摘要: /* 典型的巴什博奕。*/#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 阅读(145) 评论(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 阅读(156) 评论(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 阅读(111) 评论(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 阅读(162) 评论(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 阅读(106) 评论(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 阅读(128) 评论(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 阅读(122) 评论(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 阅读(302) 评论(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 阅读(200) 评论(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 阅读(180) 评论(0) 推荐(0) 编辑