07 2013 档案

摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1705题解: 1 首先看到题目想起那个两个盒子之间把求放来放去,每次大的那边减去和小的那边一样数目的球,问能不能让所有球在一个盒子中去。 有点类似,但是这个题总数在减 少,而且这里存在最佳情况。 2 分析这个题要逆向思考,首先我们选择分某一边后,剩下那一边就完全没有用了,举案例这个例子。6*5 -> (6*3+6*2)-> (6*1+6*2)->(6*1+6*1) 每次分别吃掉6*2,6*1, 最后把相等的6*1吃掉,可以看到这里6并没有用, 定下 阅读全文
posted @ 2013-07-31 17:57 814jingqi 阅读(166) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2711题解:1记录num[i][j][k] 表示从第一个字符开始,长度为i+j+k的,A的个数为i,B的个数为j,C的个数为k的字符串的个数。 则如果i>=j>=k 则可以根据最后一个字符是A, B还是C,分三类计数,假设是最后一位是A,由于题目的要求是前缀 ,所以前面的放法数恰好是num[i-1][j-1][k]另外两种情况同理,加的时候注意下标小于零就不要了 2一开始把所有的元素赋值为0,这样在三重for 中,根本没有将不满足ijk 不等关系的量 阅读全文
posted @ 2013-07-31 16:52 814jingqi 阅读(286) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2709题解: 1 组合数的计算,用DP,速度又快又简洁。 2 首先用一个map统计出现了那些字母,以及对应的次数,然后n-总次数得到还有多少个字母可以分配,按照题意,只能是已经出现的字母。 想到Robbers那一题,感觉分给已经出现次数最多的比较好,或者像那题一样尽量按照比例分配,但是最后试了一下案例,探索发现案例的结果是在28,:11:11: 5:5的时候取到。 和按比例分很接近,但是49按比例... 阅读全文
posted @ 2013-07-31 00:04 814jingqi 阅读(221) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26271#overview解题报告:http://blog.watashi.ws/764/andrew-stankevich-4-solution/ 阅读全文
posted @ 2013-07-30 23:31 814jingqi 阅读(78) 评论(0) 推荐(0) 编辑
摘要:比赛地址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26275#overview题解报告:http://blog.watashi.ws/584/andrew-stankevich-10-solution/whu版本 阅读全文
posted @ 2013-07-30 22:45 814jingqi 阅读(92) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2704题解: 1 看见括号匹配自然想到用栈去匹配,但是这里想记录最大长度,想法就是每次匹配以后还要知道匹配的括号在原来的序列中的下标,这样把括号存在结构体里最好了。 2 得到了匹配的序列以后,求最大的连续的“1”序列, 记得在最后面加上一个0,否则可能漏掉最后一段连续的“1”。 3输出子序列时,由于有可能完全没有匹配的,于是还设置一个bool non,如果没有一个“1”就直接输出空串。#include #include #include ... 阅读全文
posted @ 2013-07-30 22:39 814jingqi 阅读(258) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2612题解: 1 只用找到星号的位置,然后比较两端 2使用algorithm中的反转比较方便,不用管第二段开始的位置 3 容易忽略的地方,至少b要和a去掉星号后一样长啊,否则 a*a 和a这种情况也匹配了 4要求多多的输入输出,不说了代码:#include #include #include #include using namespace std; int match(string a,string b) // a i... 阅读全文
posted @ 2013-07-29 01:25 814jingqi 阅读(148) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=698题解: 额,水题一个,一点思维量都没有,就是逻辑判断理顺就好了。 耍赖使用了goto#include #include using namespace std; int isvowel(char ch) { if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u') return 1; else return 0; } int isconsonan 阅读全文
posted @ 2013-07-28 21:35 814jingqi 阅读(152) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26273#overview题解报告:http://blog.watashi.ws/2330/stankevich07/ 阅读全文
posted @ 2013-07-28 20:53 814jingqi 阅读(59) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26274#overview题解报告:http://blog.watashi.ws/1213/andrew-stankevich-6-solution/ 阅读全文
posted @ 2013-07-28 20:51 814jingqi 阅读(73) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2678题解 : 1本题的答案就是gcd(m,n) 2解释是这样的,棋盘上的点是 (i,j) 0<=i<=m-1; 0<=j<=n-1; 从(a,b)走k步到达的点就是 ((a+k)%m, (b+k)%n) 现在的问题就是,至少需要多少个整数对 (a,b) 构成一个 点集,使得 对任意的i,j ,0<=i<=m-1; 0<=j<=n-1;在这个点集中一定存在一个 (a0,b0) ,和一个整数k 。 成立着 ... 阅读全文
posted @ 2013-07-27 13:53 814jingqi 阅读(186) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1315题解 : 1 一个很简单的题 没有什么算法在里面,完全考输入输出,基本功 。 2 很奇怪 每个案例后面总是输出一个空行,和一般的要求不一样 3 每次在调用cin.getline() 时 先用调用一次,吃掉前面cin没有管的回车换行符 4 判断某一个关键词在不在这个借口中时,将这个关键词一步步的移动,逐一去匹配,还要注意的是,即便匹配成功,这个关键词前面和后面不可以有字母,所以还要对匹配成功的地址进行特判。#include #... 阅读全文
posted @ 2013-07-27 02:31 814jingqi 阅读(114) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2136经典DP,划分为这样的子问题: 记录 length【k】为,以ak为最后一个元素的最长上升子序的长度,那么求这个值时,只需要取出这个数之前的比它小的数,看它的length是多少,取出有最大的length那个。m记录的是之前子问题的length,初始化为0。这样实现的结果就是,有length【0】就可以求出length【1】,接着可以求出length【2】......。这样暴力是 O(2^n)的问题(所有的子集都拿出来考察)就变成O(n^2)了最后的结果是所 阅读全文
posted @ 2013-07-26 01:11 814jingqi 阅读(152) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4602解题思路: 1设对n的分解中k出现的次数是 g(n,k) ,首先发现k从n往下举例的时候,前几项都是一样的(待证明) 然后只需要知道对n的划分中,一共有多少个数。 考虑将n分成k个数,有C(n-1,k-1)种分发,于是总个数就是sigma k*C(n-1,k-1) ; 2 利用kC(n,k)=n C(n-1,k-1) 很容易求和 ,找到了a(n)=sigma...- S(n-1) ;再列举一项相减就可以了。 最后得到a(n)=(2^(n-3) ) * ... 阅读全文
posted @ 2013-07-25 23:25 814jingqi 阅读(147) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4602解题思路: 1设对n的分解中k出现的次数是 g(n,k) ,首先发现k从n往下举例的时候,前几项都是一样的(待证明) 然后只需要知道对n的划分中,一共有多少个数。 考虑将n分成k个数,有C(n-1,k-1)种分发,于是总个数就是sigma k*C(n-1,k-1) ; 2 利用kC(n,k)=n C(n-1,k-1) 很容易求和 ,找到了a(n)=sigma...- S(n-1) ;再列举一项相减就可以了。 最后得到a(n)=(2^(n-3) ) * ... 阅读全文
posted @ 2013-07-25 23:25 814jingqi 阅读(140) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4608题目分析: 大整数,可以考虑java BigInteger(好像tle?) 这个题的思路是逐步调整,构造一个例子,得到一个比较小的范围,然后暴力就可以了。 我们首先把这个整数加到末尾是0,进位完成以后,取出除了最后一位,每一位求和,看mod10 余数多少,不管是多少,直接用10-这个数(如果得到10改成0),加到最后一位肯定不会进位,构造完成。这样会发现我们要找的数和原来的数之间的差距不会超过18,然后一一暴力就可以。注意要点:1如果这个数不行,还有恢复数组原来的状态 (r... 阅读全文
posted @ 2013-07-25 02:54 814jingqi 阅读(197) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1316题目思想:首先 设新矩阵为c【n】【n】, 则 c【i】【j】=sigma aT【i】【k】*a【k】【j】=sigma a【k】【i】*a【k】【j】; 现在题目要求 sigama sigma c【i】【j】,三重求和,角标之间没有限制,于是可以将k拿到最外层,这样对内层求和时,k不变,可以看做关联矩阵某一行任意两个数相乘,显然只用考虑两个数都是1的情形, 这样对某个1 ,1*(1+1+...+1)括号中的数恰好是 顶点k的度数,而恰好有这么多个算式,于是固 阅读全文
posted @ 2013-07-25 02:18 814jingqi 阅读(135) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1316题目思想:首先 设新矩阵为c【n】【n】, 则 c【i】【j】=sigma aT【i】【k】*a【k】【j】=sigma a【k】【i】*a【k】【j】; 现在题目要求 sigama sigma c【i】【j】,三重求和,角标之间没有限制,于是可以将k拿到最外层,这样对内层求和时,k不变,可以看做关联矩阵某一行任意两个数相乘,显然只用考虑两个数都是1的情形, 这样对某个1 ,1*(1+1+...+1)括号中的数恰好是 顶点k的度数,而恰好有这么多个算式,于是固 阅读全文
posted @ 2013-07-25 02:18 814jingqi 阅读(153) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1313这题的理论就是当且仅当(a,m)=1 时 a*k+b (1 #include using namespace std; void jminus(int a [],int n,int b) { a[n-1]-=b; for(int i=n-1;i>0;i--) { if(a[i]>size; for(int l=0;l>p; int n=strlen(p); int a[n]; for(int i=0;i<n;i++) ... 阅读全文
posted @ 2013-07-25 01:58 814jingqi 阅读(202) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1313这题的理论就是当且仅当(a,m)=1 时 a*k+b (1 #include using namespace std; void jminus(int a [],int n,int b) { a[n-1]-=b; for(int i=n-1;i>0;i--) { if(a[i]>size; for(int l=0;l>p; int n=strlen(p); int a[n]; for(int i=0;i<n;i++) ... 阅读全文
posted @ 2013-07-25 01:58 814jingqi 阅读(170) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/listproblem.php?vol=37(4600-4610)题解报告 阅读全文
posted @ 2013-07-24 22:17 814jingqi 阅读(86) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1592要点:1 结果就是所有数的和(如果小于0,就返回0) 2将所有的数排在圆周上(从a1到an顺时针存放),这样所谓的j,就是向顺时针扫描 不管扫描到哪里扫过的和必须都是正数。 在1和-1数目相等的时候刚好是0个j满足,然后增加一个1时可以用反证法证明恰好存在一个j,用数学归纳法可以证明: 设和为n时,j的个数为f(n),f(n)=n#include using namespace std; int main() { int size; ... 阅读全文
posted @ 2013-07-23 00:42 814jingqi 阅读(122) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1592要点:1 结果就是所有数的和(如果小于0,就返回0) 2将所有的数排在圆周上(从a1到an顺时针存放),这样所谓的j,就是向顺时针扫描 不管扫描到哪里扫过的和必须都是正数。 在1和-1数目相等的时候刚好是0个j满足,然后增加一个1时可以用反证法证明恰好存在一个j,用数学归纳法可以证明: 设和为n时,j的个数为f(n),f(n)=n#include using namespace std; int main() { int size; ... 阅读全文
posted @ 2013-07-23 00:42 814jingqi 阅读(135) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://poj.org/problem?id=3233思想: 1模仿快速模幂法 ; 给矩阵写一个快幂 2 但是k太大 直接求和还是会tle 这个很像等比数列求和 但是可以递归用二分求,理论基础如下 : 求和二分:A+A^2+A...+A^(2k+1)= A+A^2+...+A^k+A^(k+1)+A^(k+1)*(A+A^2+...+A^k). 3 矩阵用结构体存储很好用呀 之前用int **存好像容易超内存 或者时间效率不高 4递归函数设计时,把调用递归的放在前面,这样实现自动回溯,而且不会爆栈 5 用g++... 阅读全文
posted @ 2013-07-22 22:20 814jingqi 阅读(155) 评论(0) 推荐(0) 编辑
摘要:比赛地址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26270题解:http://blog.watashi.ws/705/andrew-stankevich-5-solution/最近状态水的1b啊。。 阅读全文
posted @ 2013-07-22 21:08 814jingqi 阅读(86) 评论(0) 推荐(0) 编辑
摘要:1 a,m和不一定互素的时候,欧拉定理的应用 a^phi(m)%m=a^(k*phi(m) ) %m (证明用到中国剩余定理)2 发现A 满足的同余式以后 ,由于phi(m) #include #include using namespace std; struct robber { int money; int id; double inf; }; int cmp(robber x,robber y) { if(x.inf>size; for(int l=0;l>n>>m>>y; int *p=new int [n]; for(int i=0;i>. 阅读全文
posted @ 2013-07-22 03:08 814jingqi 阅读(171) 评论(0) 推荐(0) 编辑
摘要:1 a,m和不一定互素的时候,欧拉定理的应用 a^phi(m)%m=a^(k*phi(m) ) %m (证明用到中国剩余定理)2 发现A 满足的同余式以后 ,由于phi(m) #include #include using namespace std; struct robber { int money; int id; double inf; }; int cmp(robber x,robber y) { if(x.inf>size; for(int l=0;l>n>>m>>y; int *p=new int [n]; for(int i=0;i>. 阅读全文
posted @ 2013-07-22 03:08 814jingqi 阅读(179) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2343题目分析:1题目大意就是按照预先定好的标准分钱,一个很大的提示就是 y不整除m ,自然想到先用代余除法,把能按照这个方式分的钱分完再说,但是余下的钱仍然可能过比n大不好分应该是先每个人得到 [ x[i]*k/m ] 这么多钱 ,由高斯函数的性质知余下的钱不会多于n, 最后挑出对整体的 "方案不均匀系数"(即最后要求最小的那个数)影响最小的left个人(还剩left 块钱)2 注意要点 将每个人放在struct 中,包含id 信息,这样在 阅读全文
posted @ 2013-07-22 03:00 814jingqi 阅读(179) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2343题目分析:1题目大意就是按照预先定好的标准分钱,一个很大的提示就是 y不整除m ,自然想到先用代余除法,把能按照这个方式分的钱分完再说,但是余下的钱仍然可能过比n大不好分应该是先每个人得到 [ x[i]*k/m ] 这么多钱 ,由高斯函数的性质知余下的钱不会多于n, 最后挑出对整体的 "方案不均匀系数"(即最后要求最小的那个数)影响最小的left个人(还剩left 块钱)2 注意要点 将每个人放在struct 中,包含id 信息,这样在 阅读全文
posted @ 2013-07-22 03:00 814jingqi 阅读(178) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1394注意要点:1根本不需要真正构建出树的结构 否则反而超内存由于最后的结果等于 w【i】*l【i】求和 换成加法 w【i】应该加层数那么多次,而这样的构建方式使根结点的权值恰好等于所有叶子节点权值之和(包括中间状态)所以在每次创建新结点时,把新结点的权值加到最后的结果中去,那么每个权值被加的次数等于它出于多少颗树中,恰好等于它的高度2即使是weight 也应该用long long保存 因为p【i】已经可达10^9 #include #include using n 阅读全文
posted @ 2013-07-22 02:46 814jingqi 阅读(171) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1394注意要点:1根本不需要真正构建出树的结构 否则反而超内存由于最后的结果等于 w【i】*l【i】求和 换成加法 w【i】应该加层数那么多次,而这样的构建方式使根结点的权值恰好等于所有叶子节点权值之和(包括中间状态)所以在每次创建新结点时,把新结点的权值加到最后的结果中去,那么每个权值被加的次数等于它出于多少颗树中,恰好等于它的高度2即使是weight 也应该用long long保存 因为p【i】已经可达10^9 #include #include using n 阅读全文
posted @ 2013-07-22 02:46 814jingqi 阅读(350) 评论(0) 推荐(0) 编辑
摘要:#include using namespace std; int quick_mod(int a,int b,int m) { a=a%m; int ans=1; while(b) { if(b&1) { ans=(ans*a)%m; } b>>=1; a=(a*a)%m; } return ans; } int main() { int size; cin>>size; int m; int h; int a,b; while(cin>>m) ... 阅读全文
posted @ 2013-07-21 19:40 814jingqi 阅读(122) 评论(0) 推荐(0) 编辑
摘要:比赛地址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26269#overview题解报告:http://blog.watashi.ws/816/andrew-stankevich-2-solution/ 阅读全文
posted @ 2013-07-20 19:50 814jingqi 阅读(69) 评论(0) 推荐(0) 编辑
摘要:比赛地址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26268解题报告:http://bbs.whu.edu.cn/wForum/disparticle.php?boardName=ACM_ICPC&ID=1105535381 阅读全文
posted @ 2013-07-19 22:22 814jingqi 阅读(111) 评论(0) 推荐(0) 编辑
摘要:比赛地址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=25749解题报告: http://blog.watashi.ws/640/andrew-stankevich-8-solution/ 阅读全文
posted @ 2013-07-19 22:14 814jingqi 阅读(72) 评论(0) 推荐(0) 编辑
摘要:比赛地址 :http://acm.hust.edu.cn/vjudge/contest/view.action?cid=25748 阅读全文
posted @ 2013-07-19 22:11 814jingqi 阅读(91) 评论(0) 推荐(0) 编辑
摘要:题目地址 :http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1420思路:一开始看这个题觉得题意简单但不同的月份有不同的天数,有点不知怎么方便的解决。 然后想到打表的方法,把每一天的信息作为一个结构体,一一存在向量里面,向量的角标是自增的,刚好就是里2000-01-01的天数。注意 :1 闰年的判断2输出格式 1-1要写成 01-013 超内存问题 要把三个属性值设置成 short int ,直接int会超内存4 星期问题,2000-01-01是周六 所以第n天就是 周(n+6)%7代码:#include #include 阅读全文
posted @ 2013-07-12 22:26 814jingqi 阅读(287) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1788说明: 题目很水 提到一个定理,求多个数的最小公倍数转化为求两个数的最小公倍数方法。 然后就是 a=b(mod m1) a=b(mod m2) 等价于a=b(mod [m1,m2] )#include using namespace std; typedef long long inta; int gcd(int a,int b) { if(b==0) return a; else return gcd(b,a%b); } int main() { int k,a; ... 阅读全文
posted @ 2013-07-10 04:46 814jingqi 阅读(114) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://poj.org/problem?id=1006中国剩余定理的应用#include using namespace std; typedef long long inta; void extend_gcd(inta a,inta b,inta &x,inta &y) { if(b==0) { x=1; y=0; } else { extend_gcd(b,a%b,x,y); int temp=x; x=y; y=temp-a/b*y; } } int main() ... 阅读全文
posted @ 2013-07-10 04:18 814jingqi 阅读(103) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3579要点; 题目要求正整数,一旦r1=0;应该输出最小公倍数#include #include using namespace std; typedef long long inta; void extend_gcd(inta a,inta b,inta &x,inta &y,inta &gcd) { if(b==0) { x=1; y=0; gcd=a; } else { extend_gcd(b,a... 阅读全文
posted @ 2013-07-10 02:33 814jingqi 阅读(103) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1573注意要点:1 最后的次数直接用除法 取高斯加1即可 若用加法累加会超时2 很容易漏掉的一点是题目要求正整数个数, 不是非负整数 ,如果最后r1==0 而且结果不是0 ,就要在结果上减一#include #include using namespace std; typedef long long inta; void extend_gcd(inta a,inta b,inta &x,inta &y,inta &gcd) { if(b==0) { x=1; ... 阅读全文
posted @ 2013-07-10 01:23 814jingqi 阅读(117) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://poj.org/problem?id=2115#include #include using namespace std; typedef long long inta; void extend_gcd(inta a,inta b,inta &x,inta &y,inta &gcd) { if(b==0) { x=1; y=0; gcd=a; } else { extend_gcd(b,a%b,x,y,gcd); inta temp=x; x=y; ... 阅读全文
posted @ 2013-07-10 00:13 814jingqi 阅读(135) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://poj.org/problem?id=2891#include #include using namespace std; typedef long long inta; void extend_gcd(inta a,inta b,inta &x,inta &y,inta &gcd) { if(b==0) { x=1; y=0; gcd=a; } else { extend_gcd(b,a%b,x,y,gcd); inta temp=x; x=y; ... 阅读全文
posted @ 2013-07-09 23:29 814jingqi 阅读(164) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1021说明 :题目很水但是有一个重要结论,只要是递推数列,一定是模周期数列 (可以用抽屉原理证明)#include using namespace std; int main() { int n; while(cin>>n) { if(n%8==2||n%8==6) cout<<"yes"<<endl; else cout<<"no"<<endl; } } 阅读全文
posted @ 2013-07-09 17:13 814jingqi 阅读(112) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://poj.org/problem?id=2769要点 :1 如果在确定了模数后再在循体里面用双重for循环检测是否存在 同余的一定会超时 需要寻找O(n)复杂度的方法 2一开始想使用map 检测是否重复,结果还是超时 最后还是用类似于筛法的方法,关键点是初始化时只能(也只需要)初始化到k,否则仍会tle#include #include #include using namespace std; int main() { bool find[100000]; int size; cin>>size; int n; while(cin>>n... 阅读全文
posted @ 2013-07-09 17:00 814jingqi 阅读(153) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.nefu.edu.cn/test/problemshow.php?problem_id=120#include #include #include using namespace std; typedef long long inta; inta multi(inta a,inta b, inta m) { inta rel=0; while(b>0) { if(b&1) { rel=(rel+a)%m; } b>>=1; a=(a0) {n>>=1; ... 阅读全文
posted @ 2013-07-09 15:19 814jingqi 阅读(244) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.nefu.edu.cn/test/problemshow.php?problem_id=120#include #include #include using namespace std; typedef long long inta; inta multi(inta a,inta b, inta m) { inta rel=0; while(b>0) { if(b&1) { rel=(rel+a)%m; } b>>=1; a=(a0) {n>>=1; ... 阅读全文
posted @ 2013-07-09 15:19 814jingqi 阅读(162) 评论(0) 推荐(0) 编辑
摘要:#include #include using namespace std; int main() { int k; cin>>k; int n; while(cin>>n) { int exponent=0; for(int i=1;pow(5.0,i) #include using namespace std; int main() { int k; cin>>k; int n; double p; while(cin>>n>>p) { int exponent=0; for(int i=1;... 阅读全文
posted @ 2013-07-09 03:58 814jingqi 阅读(223) 评论(0) 推荐(0) 编辑
摘要:#include #include #define M 16777220 using namespace std; bool composite[16777220]; int main() { int len=sqrt(M); for(int i=2;i>n) { int count=0; for(int i=2;i<=n/2;i++) if(composite[n-i]==0&&composite[i]==0) count++; cout<<count<<endl; } } // 打素数表 只需要 O(n^1.5)的算法 阅读全文
posted @ 2013-07-08 20:21 814jingqi 阅读(192) 评论(0) 推荐(0) 编辑
摘要:#include #include #define M 16777220 using namespace std; bool composite[16777220]; int main() { int len=sqrt(M); for(int i=2;i>n) { int count=0; for(int i=2;i<=n/2;i++) if(composite[n-i]==0&&composite[i]==0) count++; cout<<count<<endl; } } // 打素数表 只需要 O(nlogn)的算法 题目地... 阅读全文
posted @ 2013-07-08 20:21 814jingqi 阅读(125) 评论(0) 推荐(0) 编辑
摘要:#include #include using namespace std; int main() { int n; while(cin>>n) { int result; result=n-log10(n*log(10)); cout<<result+1<<endl; } } 利用素数定理 pi(x) 近似于 x/ln(x); 阅读全文
posted @ 2013-07-08 19:14 814jingqi 阅读(176) 评论(0) 推荐(0) 编辑
摘要:#include using namespace std; typedef long long inta; int extend_gcd(inta a,inta b,inta &x,inta &y,inta &gcd) { if(b==0) { x=1; y=0; gcd=a; } else { extend_gcd(b,a%b,x,y,gcd); int temp=x; x=y; y=temp-a/b*y; } } int gcd(int a,int b) { ... 阅读全文
posted @ 2013-07-08 18:12 814jingqi 阅读(187) 评论(0) 推荐(0) 编辑
摘要:#include using namespace std; typedef long long inta; int extend_gcd(inta a,inta b,inta &x,inta &y,inta &gcd) { if(b==0) { x=1; y=0; gcd=a; } else { extend_gcd(b,a%b,x,y,gcd); int temp=x; x=y; y=temp-a/b*y; } } int gcd(int a,int b) { ... 阅读全文
posted @ 2013-07-08 18:03 814jingqi 阅读(195) 评论(0) 推荐(0) 编辑
摘要:#Team UniversitySolvedTimeABCDEFGHIJK1St. Petersburg National Research University of IT, Mechanics and Optics98911-430-11-772-171-1312-271-141-571-1571-1152-2072Shanghai Jiao Tong University89341-8513-921-451-43-46G1-1131-2071-562-1903The University of Tokyo810601-783-1912-1651-270-12-211-43-1401-22 阅读全文
posted @ 2013-07-03 21:13 814jingqi 阅读(156) 评论(0) 推荐(0) 编辑
摘要:#include using namespace std; int main() { int a,b; while(cin>>a>>b) { int tag=0; if(a==0&&b==0) break; for(int i=0;i<=9;i++) for(int j=0;j<=9;j++) { int final=a*100; final+=i*10+j; if(final%b==0) { ... 阅读全文
posted @ 2013-07-03 14:41 814jingqi 阅读(114) 评论(0) 推荐(0) 编辑
摘要:#include using namespace std; int gcd(int a,int b) { if(a>n>>m) { result=n; result/=gcd(m,n); result*=m; cout<<result<<endl; } } // 最大公约数 最小公倍数求法 注意可能 m和n互素 乘积超过int范围 阅读全文
posted @ 2013-07-03 01:38 814jingqi 阅读(115) 评论(0) 推荐(0) 编辑
摘要:#include using namespace std; int main() { int n; while(cin>>n) { if(n%12==0) cout 6|n 阅读全文
posted @ 2013-07-03 01:26 814jingqi 阅读(129) 评论(0) 推荐(0) 编辑