05 2013 档案

摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=4522建两个图,分别用dijstra。#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<string>#include<algorithm>#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;const int 阅读全文
posted @ 2013-05-28 15:56 Roly Yu 阅读(148) 评论(0) 推荐(0)
摘要:/* http://codeforces.com/problemset/problem/149/E KMP结合动态规划的思想,正向匹配一边,l[]数组保存的是对于匹配串的每一个位置在模式串能匹配的最左边,也就是首次匹配的位置 逆序再匹配一次,逆向信息保存r[]数组。 再枚举l[i]+r[len-i]*/#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<algorithm>#pragma comment(linker, " 阅读全文
posted @ 2013-05-21 21:30 Roly Yu 阅读(179) 评论(0) 推荐(0)
摘要:#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <algorithm>#include <math.h>#include <vector>#include <map>#include <queue>#include <stack>#include <stdlib.h>using namespace std;const int maxn = 10000 阅读全文
posted @ 2013-05-17 11:52 Roly Yu 阅读(151) 评论(0) 推荐(0)
摘要:这道题是对SG函数的考查#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <algorithm>#include <math.h>#include <vector>#include <map>#include <queue>#include <stack>#include <stdlib.h>using namespace std;const int 阅读全文
posted @ 2013-05-17 10:42 Roly Yu 阅读(150) 评论(0) 推荐(0)
摘要:题目:http://acm.fzu.edu.cn/problem.php?pid=1534巴什博奕和尼姆博弈的综合。这里分为最后拿胜利,最后拿失败,分别是nim 和 anti-nim。SG(n) = n%3#include <iostream>#include <string.h>#include <stdio.h>#include <algorithm>using namespace std;const int maxn = 10005;int p[maxn];int main(){ int n; while(~scanf("%d&q 阅读全文
posted @ 2013-05-16 14:27 Roly Yu 阅读(176) 评论(0) 推荐(0)
摘要:/* 典型的巴什博奕。*/#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <math.h>#include <stdlib.h>#include <queue>#include <vector>using namespace std;int main() { int t; scanf("%d",&t); while(t--){ int n,m; sca 阅读全文
posted @ 2013-05-15 15:26 Roly Yu 阅读(148) 评论(0) 推荐(0)
摘要:尼姆博弈,并且SG(n) = n#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <math.h>#include <stdlib.h>#include <queue>#include <vector>using namespace std;int main (){ int n,m; while(scanf("%d",&n)&&n){ i 阅读全文
posted @ 2013-05-15 15:16 Roly Yu 阅读(161) 评论(0) 推荐(0)
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=1517题意:2 个人玩游戏,从 1 开始,轮流对数进行累乘,直到超过一个指定的值。[2,9] Stan wins.[10,18] Ollie wins.[19,162]Stan wins.[162,324]Ollie wins.......#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <math.h>#include &l 阅读全文
posted @ 2013-05-15 14:44 Roly Yu 阅读(118) 评论(0) 推荐(0)
摘要:/* 每一堆的数值与ans相异或,所得的结果就是这一堆可以取的数量。 但是,如要这一堆数量没有这么多,就不可以这么取 异或运算本身就是互逆运算 */#include <iostream>using namespace std;int value[101];int main (){ int n,sum,count,i; while (cin>>n && n){ sum=0; for (i=0;i<n;i++){ cin>>value[i]; sum^=value[i]; } count... 阅读全文
posted @ 2013-05-15 14:00 Roly Yu 阅读(167) 评论(0) 推荐(0)
摘要:任给N堆石子,两人轮流从任一堆中任取(每次只能取自一堆),规定每方每次最多取K颗,取最后一颗石子的一方获胜.问先取的人如何获胜?巴什博奕和尼姆博弈的综合。令Bi=Mi mod(Li+1)定义T‘=B1 xor B2 xor ... xor Bn如果T‘=0 那么没有获胜可能,先取者必败如果T’>0 那么必然存在取的方法,使得T‘=0,先取者有获胜的方法假设对方取了在Mi中取了r<=Li个如果Mi中剩下的石子多于Li 那么就在Mi中取走Li+1-r个则Bi不变 T‘还是0如果Mi<=K 那么我们需要重新计算Bi和T‘ 。#include <iostream>#inc 阅读全文
posted @ 2013-05-15 13:36 Roly Yu 阅读(109) 评论(0) 推荐(0)
摘要:巴什博奕的变形。只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取p个,最多取q个。最后取光者得输。显然,如果n=r*(p+q)+s , 即s = n%(p+q). # n%(p+q) == 0 先手一定赢,假设先手第一次拿q个,接着每次不管后手拿多少个,假设后手拿k个,先手都可以拿p+q-k 个,所以最后一定剩下p个给后手,所以先手必胜。 # n%(p+q) != 0 1.(1< s <= p)那么由于一次最多只能取q个,所以,无论先手拿走多少个,假设拿了k个, 后手都能够一 次拿走p+q-k个物品,最后剩下s个给先手,所以先手必输。 2.(p < ... 阅读全文
posted @ 2013-05-15 13:15 Roly Yu 阅读(133) 评论(0) 推荐(0)
摘要:典型的巴什博奕。#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <set>using namespace std;int main() { int m,n; while(~scanf("%d%d",&m,&n)){ if(m<=n){ printf("%d",m); for(int i = m+1;i <= n;i++) printf(" 阅读全文
posted @ 2013-05-15 12:08 Roly Yu 阅读(125) 评论(0) 推荐(0)
摘要:利用PN分析求解此题。递推下去会发现3和3的倍数都是P点。#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <set>using namespace std;int main() { int n; while(~scanf("%d",&n)){ if(n%3) printf("Kiki\n"); else printf("Cici\n"); } re 阅读全文
posted @ 2013-05-15 11:16 Roly Yu 阅读(306) 评论(0) 推荐(0)
摘要:#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <set>using namespace std;int main() { int a,b; while(scanf("%d%d",&a,&b)&&(a+b)){ if(a<b) swap(a, b); int flag = 1; while(1){ if(a == b || a >= 2*b) brea 阅读全文
posted @ 2013-05-15 11:09 Roly Yu 阅读(204) 评论(0) 推荐(0)
摘要:/* 尼姆博奕(Nimm Game):有三堆各若干个物品,两个人轮流从某一堆取任意多的物品,规定每次至少取一个,多者不限,最后取光者得胜。 这种情况最有意思,它与二进制有密切关系,我们用(a,b,c)表示某种局势,首先(0,0,0)显然是奇异局势,无论谁面对奇异局势,都必然失败。第二 种奇异局势是(0,n,n),只要与对手拿走一样多的物品,最后都将导致(0,0,0)。仔细分析一下,(1,2,3)也是奇异局势,无论对手如何拿,接下来都可 以变为(0,n,n)的情形。 计算机算法里面有一种叫做按位模2加,也叫做异或的运算,我们用符号(+)表示这种运算。这种运算和一般加法不同的一点... 阅读全文
posted @ 2013-05-14 21:08 Roly Yu 阅读(196) 评论(0) 推荐(0)
摘要:题目:http://acm.hit.edu.cn/hoj/problem/view?id=1402整数划分问题Submitted: 886,Accepted: 374整数划分是一个经典的问题。希望这道题会对你的组合数学的解题能力有所帮助。Input每组输入是两个整数n和k。(1 <= n <= 50, 1 <= k <= n)Output对于每组输入,请输出六行。第一行: 将n划分成若干正整数之和的划分数。第二行: 将n划分成k个正整数之和的划分数。第三行: 将n划分成最大数不超过k的划分数。第四行: 将n划分成若干奇正整数之和的划分数。第五行: 将n划分成若干不同整数 阅读全文
posted @ 2013-05-14 20:08 Roly Yu 阅读(223) 评论(0) 推荐(0)
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=3374最小表示法:http://tobyaa.blog.163.com/blog/static/30248591201261604349913/#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;const int maxn = 1000005;char str[maxn];int next[maxn];void ge 阅读全文
posted @ 2013-05-14 18:36 Roly Yu 阅读(228) 评论(0) 推荐(0)
摘要:/* 对于小数据用这dfs,大数据就用递推的思想。*/#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <algorithm>#include <math.h>#include <queue>#include <map>#include <stack>#include <vector>using namespace std ;const int maxn = 20 阅读全文
posted @ 2013-05-14 15:13 Roly Yu 阅读(189) 评论(0) 推荐(0)
摘要:题目:http://codeforces.com/contest/304/problem/B#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <algorithm>#include <math.h>#include <fstream>#include <vector>#include <map>#include <queue>#include <stack& 阅读全文
posted @ 2013-05-14 09:11 Roly Yu 阅读(190) 评论(0) 推荐(0)
摘要:题目:http://acm.fzu.edu.cn/problem.php?pid=1926#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <algorithm>#include <stdlib.h>#include <math.h>#include <vector>#include <map>using namespace std;const int maxn = 1005 阅读全文
posted @ 2013-05-11 22:05 Roly Yu 阅读(196) 评论(0) 推荐(0)
摘要:#include <iostream>#include <algorithm>#include <stdio.h>#include <string>#include <string.h>#include <stdlib.h>#include <math.h>#include <vector>#include <map>#include <queue>#include <stack>#include <set>using namespace std ;c 阅读全文
posted @ 2013-05-10 13:30 Roly Yu 阅读(178) 评论(0) 推荐(0)
摘要:http://acm.neu.edu.cn/hustoj/problem.php?id=1262#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <algorithm>#include <math.h>#include <fstream>#include <vector>#include <map>#include <queue>#include <stac 阅读全文
posted @ 2013-05-09 10:59 Roly Yu 阅读(197) 评论(0) 推荐(0)
摘要:#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <algorithm>#include <math.h>#include <fstream>#include <vector>#include <map>#include <queue>#include <stack>#include <math.h>#include <stdlib. 阅读全文
posted @ 2013-05-07 21:47 Roly Yu 阅读(203) 评论(0) 推荐(0)
摘要:#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <algorithm>#include <math.h>#include <fstream>#include <vector>#include <map>#include <queue>#include <stack>#include <math.h>#include <stdlib. 阅读全文
posted @ 2013-05-07 15:16 Roly Yu 阅读(185) 评论(0) 推荐(0)
摘要:#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <algorithm>#include <math.h>#include <fstream>#include <vector>#include <map>#include <queue>#include <stack>#include <math.h>#include <stdlib. 阅读全文
posted @ 2013-05-07 09:21 Roly Yu 阅读(157) 评论(0) 推荐(0)
摘要:题目:http://www.acmore.net/problem.php?cid=1013&pid=5#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <algorithm>#include <math.h>#include <fstream>#include <vector>#include <map>#include <queue>#include & 阅读全文
posted @ 2013-05-06 22:04 Roly Yu 阅读(293) 评论(0) 推荐(0)
摘要:http://www.codeforces.com/problemset/problem/182/D利用到KMP的周期性。现寻找最小周期,再进行扩充。#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <algorithm>#include <math.h>#include <fstream>#include <vector>#include <map>#include < 阅读全文
posted @ 2013-05-04 13:14 Roly Yu 阅读(191) 评论(0) 推荐(0)
摘要:这道题拿过来感觉很蒙 , 因为以前做的都是点更新询问区间 , 或是区间更新询问点 , 这道题是在[a,b]区间内隔k个数更新一次((i - a) % k == 0即i%k==a%k),对于树状数组来说按照一维的方式定义, 后面在加上两维 c[i][k][i%k] (a<=i<=b), 相当于在一维c[i]每个节点加入了一些信息,来记录每次更新,询问时候再加上原数组即可得到结果。#include <iostream>#include <stdio.h>#include <string>#include <string.h>#includ 阅读全文
posted @ 2013-05-03 21:18 Roly Yu 阅读(174) 评论(0) 推荐(0)
摘要:剪枝很重要,可走的格数小于时间则减去,然后就是奇偶性剪枝可以把map看成这样: 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 从为 0 的格子走一步,必然走向为 1 的格子 从为 1 的格子走一步,必然走向为 0 的格子 即: 0 ->1或1->0 必然是奇数步 0->0 走1->1 必然是偶数步 所以当遇到从 0 走向 0 但是要求时间是奇数的,或者, 从 1 走向 0 但是要求时间是偶数的 都可以直接判断不可达!#include <iostream>#include <std 阅读全文
posted @ 2013-05-03 16:50 Roly Yu 阅读(164) 评论(0) 推荐(0)
摘要:http://www.acmore.net/problem.php?id=1467根据朴素的欧几里德原理有 gcd(a,b)=gcd(b,a mod b);则:ax1+by1=bx2+(a mod b)y2;即:ax1+by1=bx2+(a-[a/b]*b)y2=ay2+bx2-(a/b)*by2;根据恒等定理得:x1=y2; y1=x2-[a/b]*y2;本题直接利用这个结论。#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include < 阅读全文
posted @ 2013-05-02 20:19 Roly Yu 阅读(208) 评论(0) 推荐(0)
摘要:二分+树状数组动态的寻找比a大k的数#include <stdio.h>#include <iostream>#include <string>#include <string.h>#include <algorithm>#include <stdlib.h>#include <math.h>#include <vector>#include <map>using namespace std;const int maxn = 100005;int c[maxn];int lowbit(i 阅读全文
posted @ 2013-05-02 13:20 Roly Yu 阅读(192) 评论(0) 推荐(0)
摘要:http://www.acmore.net/problem.php?id=1504利用优先队列,转化成O(m)的复杂度。#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <algorithm>#include <math.h>#include <fstream>#include <vector>#include <map>#include <queue>#incl 阅读全文
posted @ 2013-05-01 15:47 Roly Yu 阅读(263) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2185题意:给你一个字符矩阵,求出它的最小覆盖子矩阵,即使得这个子矩阵的无限复制扩张之后的矩阵,能包含原来的矩阵。即二维的最小覆盖子串。思路:KMP很好的一道题。首先易证:最小覆盖子矩阵一定靠左上角。那么,我们考虑求出每一行的最小重复串长度,所有行的最小重复串的长度的lcm就是最小重复子矩阵的宽。然后我们对列也做相同的操作。于是我们就可以求得最小重复子矩阵的大小了。(这里要注意一点:当所得的宽大于原来的宽时,就让等于原来的宽,长也如此)。算法实现:算法的核心在于高效的求出每一行和每一列的最小重复串,这个可以最原串做一次KMP中的get_ne 阅读全文
posted @ 2013-05-01 15:34 Roly Yu 阅读(198) 评论(0) 推荐(0)