UVA 10081 Tight numbers(POJ 2537)】的更多相关文章

直接看代码就OK.思路比较简单.就是注意概率要在转移过程中算出来.不能算成成立的方案书除以总方案数(POJ的这道题可以这么干.数据很水么.另外POJ要用%.5f,%.5lf 会WA.) #include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <stack> #inclu…
Time limit: 3.000 seconds Given is an alphabet {0, 1, ... , k}, 0 <= k <= 9 . We say that a word of length n over this alphabet is tightif any two neighbour digits in the word do not differ by more than 1. Input is a sequence of lines, each line con…
UVa 10006 - Carmichael Numbers An important topic nowadays in computer science is cryptography. Some people even think that cryptography is the only important field in computer science, and that life would not matter at all without cryptography. Alvar…
题目链接:uva 12050 - Palindrome Numbers 题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然后就得到是长度为多少的第几个的回文串了,有个细节注意的是, n计算完后要-1! 下面给出AC代码: #include <bits/stdc++.h> typedef long long ll; using namespace std; ; ll num[maxn]; int n,ans[maxn]…
UVA.136 Ugly Numbers (优先队列) 题意分析 如果一个数字是2,3,5的倍数,那么他就叫做丑数,规定1也是丑数,现在求解第1500个丑数是多少. 既然某数字2,3,5倍均是丑数,且1为丑数,那么不妨从1开始算起.算完之后2,3,5均为丑数,然后再从2算起,4,5,10均为丑数--直到算到第1500个即可.那么有如下的问题: 如何从算出来的丑数中取出最小的? 如何保证没有计算重复的丑数? 对于第一个问题,可以采用优先队列的方法,即有序的队列,且为升序,每次只需要取出队首元素即可…
UVA - 13022 Sheldon Numbers 二进制形式满足ABA,ABAB数的个数(A为一定长度的1,B为一定长度的0). 其实就是寻找在二进制中满足所有的1串具有相同的长度,所有的0串也具有相同的长度,并且在给定范围内的个数. 位运算.通过分析不难发现,所有解不会很大,因此我们可以暴力,用两个for分别枚举0串和1串的长度,然后交替放入一个值内(注意先放1),同时更新答案. 将值存入set,发现所有满足条件的个数为4809(4810). ps:因为这里的2^63大于long lon…
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ... shows the first 11 ugly numbers. By convention, 1 is included.Write a program to find and print the 1500'th ugly number. Input There…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1066 http://poj.org/problem?id=2549 题目大意: 给定一个整数几何S,找出一个最大的d,使得a+b+c=d,其中a,b,c,d是S中不同的元素. S的个数最大为1000. 思路: 直接暴力枚举a,b,c,d必挂. 上面的式子移向得:a+b=d-c.我们先预处理所…
 强伪素数 题目大意:利用费马定理找出强伪素数(就是本身是合数,但是满足费马定理的那些Carmichael Numbers) 很简单的一题,连费马小定理都不用要,不过就是要用暴力判断素数的方法先确定是不是素数,然后还有一个很重要的问题,那就是a和p是不互质的,不要用a^(p-1)=1(mod p)这个判据,比如4^6=4(mod 6),但是4^5=4(mod 6) #include <iostream> #include <functional> #include <algo…
A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the name “anna” is a palindrome. Numbers can also be palindromes (e.g. 151 or 753357). Additionallynumbers can of course be ordered in size. The first few…
  Carmichael Numbers  An important topic nowadays in computer science is cryptography. Some people even think that cryptography is the only important field in computer science, and that life would not matter at all without cryptography. Alvaro is one…
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2456 题意 输入两个整数a和b,输出从a到b(包含a和b)的平方数的个数.直到输入0 0时程序结束 分析: 如果一个数n是平方数,(double)sqrt(n)-(int)sqrt(n)<1e-6. 下面给出AC代码: #include <bits/stdc++.h&…
题意:给定一个N,求一个大于N的最小的Smith Numbers,Smith Numbers是一个合数,且分解质因数之后上质因子每一位上的数字之和 等于 其本身每一位数字之和(别的博客偷的题意) 思路:主要是分治:分解成质因子使用递归即可. #include<cstdio> #include<cmath> // 检测素数 bool is_prime(int n) { ; i*i <= n;++i) ){ ; } ; } //数位 int sumfun(int n) { ; ;…
 Pseudo-Random Numbers  Computers normally cannot generate really random numbers, but frequently are used to generate sequences of pseudo-random numbers. These are generated by some algorithm, but appear for all practical purposes to be really random…
1619 - Feel Good Time limit: 3.000 seconds   Bill is developing a new mathematical theory for human emotions. His recent investigations are dedi- cated to studying how good or bad days in uent people's memories about some period of life. A new idea B…
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ... shows the first 11 ugly numbers. By convention, 1 is included. Write a program to find and print the 1500’th ugly number. Input Ther…
Smith Numbers Background While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh University , noticed that the telephone number of his brother-in-law H. Smith had the following peculiar property: The sum of the digits o…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2456 题目大意: 给出两个数a,b(a<=b<=100000),求在a和b之间有多少个完全平方数(包括a和b) 思路: 打表啊打表. #include<cstdio> #include<cstring> #include<cmath> cons…
A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example, the name “anna” is a palindrome. Numbers can also be palindromes (e.g. 151 or 753357). Additionally numbers can of course be ordered in size. The first…
People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, others like using Windows, and some like difficult mathematical games. Latest marketing research shows, that this market…
While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh University,noticed that the telephone number of his brother-in-law H. Smith had the following peculiar property: The sum of the digits of that number was equal to…
数学太渣了,这道题反复参考了大神的博客,算是看懂了吧.博客原文  http://blog.csdn.net/crazysillynerd/article/details/43339157 算是个数学题吧,虽然在AOAPC上面给放到象征水题的第三章里面了. 这个题基本就是帮着你复习了一遍浮点数的存储方式了.浮点数在计算机里是分三部分表示的,最前面一位表示符号,后面一部分是尾数,最后一部分是阶码,表示方法类似于科学记数法,不过是二进制的,尾数是M阶码是E的话那么表示起来就是M × 2^E了.然后对于…
 素数之和 题目大意:一些整数可以表示成一个连续素数之和,给定一个整数要你找出可以表示这一个整数的连续整数序列的个数 方法:打表,然后用游标卡尺法即可 #include <iostream> #include <functional> #include <algorithm> #define MAX_N 10010 using namespace std; static int primes_set[MAX_N], flag[MAX_N], p_sum; void in…
阶乘总和 题目大意:要你算一堆阶乘对m的模... 大水题,对指数二分就可以了... #include <iostream> #include <functional> #include <algorithm> using namespace std; typedef long long LL_INT; LL_INT cal(const LL_INT, const LL_INT, const LL_INT); int main(void) { int case_sum,…
题目链接 #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <ctime> #include <cstdlib> #include <iostream> using namespace std; #define LL long long #define MOD 1000000007 ]; int judge(in…
题目:统计区间中的平方数个数. 分析: ... #include <stdio.h> #include <string.h> ]; int main() { int i, a, b, t; memset(on,,sizeof(on)); ;i<=;i++) on[i*i] = ; while(~scanf("%d%d", &a, &b)) { t=; &&b==) break; for(i=a;i<=b;i++) {…
题目大意:给出i,输出第i个镜像数,不能有前导0. 题解:从外层开始模拟 #include <stdio.h> int p(int x) { int sum, i; ;i<=x;i++) sum *= ; return sum; } int main() { ], c; while(~scanf("%d", &n)) { ) break; i=; *p((i-)/)) { n -= *p((i-)/); i++; } c = (i+)/; t=; while(…
题意:给出丑数的定义,不能被除2,3,5以外的素数整除的的数称为丑数. 和杭电的那一题丑数一样--这里学的紫书上的用优先队列来做. 用已知的丑数去生成新的丑数,利用优先队列的能够每次取出当前最小的丑数再去生成新的丑数==== 大概这儿的优先队列就充当了dp转移方程里面的那个min的意思@_@ #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include&l…
题意:给定Z, I, M,  L,根据随机数产生式k=(Z*L+I)%M.但是L表示的是上一个产生的数,比如根据产生式产生了序列{2,5,4,3}那么5是由L=2算来的,4由L=5算来的..第1个所产生的数所需的L由系统给定.那么肯定会产生一个环,到某个位置就会开始产生重复的序列,比如12345345345....求循环中有多少个数(循环节)?(如例是3,分别是345) 思路:因为z i m 都是不变的,当L一定,那么产生的数肯定是一定的,所以只要L有重复出现,那就会从那里开始循环.标记一下所产…
题目大意:只有素因子2,3,5的数叫做丑数.输出第1500个丑数即可. 这个...好吧,直接输出就是了.自己写一个小程序先计算一下,这就是黑盒测试的好处啊,“我们的目标是解决问题,而不是为了写程序而写程序,同时应该保持简单(Kepp It Simple and Stupid, KISS)”,摘自<算法竞赛入门经典>. #include <cstdio> int main() { ; // the number of ugly number int i; ; ; i++) { int…