随笔分类 - 博弈
摘要:这道题之前做过的,但是晚上拿出来熟悉一下!但是runtime error!,很奇怪,查!坚决不看之前的代码。后来突然一个念头:会不胡hash数组没有初始化!加了个hash[110]={0};A了,忘记的是定义为全局性质的数组才会被编译器自动初始化为0;非全局的不会自动初始化!哎哎!!教训。/*poj 2960 result:ACtime:188MS*/#include"iostream"#include"algorithm"using namespace std;int s[110],k;int sg[10010];int getSg(int n){ i
阅读全文
摘要:john 必胜:1,所有均为1且SG值为0;2,有些堆大于1且SG值不为0。#include"iostream"using namespace std;int main(){ int k; cin>>k; while(k--) { int flag=1,n,i,s[50],ans=0; cin>>n; for(i=0;i<n;i++) { cin>>s[i]; if(s[i]!=1) flag=0; ans^=s[i]; } if(flag) { if(!ans) cout<<"John"<&l
阅读全文
摘要:Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 to 9. Stan always starts with p = 1, does his multiplication, then Ollie multiplies the number, then Stan and so on. Before a game starts, they draw an integer 1 < n < 4294967295 and the winner i
阅读全文
摘要:如果n/m>1的话就Stan wins否则就球gcd,看经过多少次可以出现m==0的情况。注意的是在求gcd的过程中会出现n/m>1的情况,#include"iostream"using namespace std;int gcd(int n,int m){ int i=0; while(1) { if(n/m>1) break; i++; n-=m; if(n<m) {int tmp=m;m=n;n=tmp;} if(m==0) break; } return i;}int main(){ int n,m; while(cin>>n&g
阅读全文
摘要:简单的NIM游戏过程,就不分析了。#include"iostream"using namespace std;int main(){ int n; while(cin>>n) { int i,k,ans=0; for(i=0;i<n;i++) { cin>>k; ans^=k; } if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0;}
阅读全文
摘要:Alice and Bob decide to play a new stone game.At the beginning of the game they pick n(1<=n<=10) piles of stones in a line. Alice and Bob move the stones in turn.At each step of the game,the player choose a pile,remove at least one stones,then freely move stones from this pile to any other pil
阅读全文
摘要:N堆取石子,取完最后者输。有个叫SJ定理。#include"iostream"using namespace std;int main(){ int t; cin>>t; while(t--) { int s[50],n; cin>>n; int i,flag=0,ans=0; for(i=0;i<n;i++) { cin>>s[i]; ans^=s[i]; if(s[i]>1) flag=1; } if(!flag) { if(n%2==0) cout<<"John"<<endl;
阅读全文
摘要:/*典型的SG函数的应用。求出SG值之后一连串的异或就好了*/#include"iostream"#include"algorithm"#include"string.h"using namespace std;int s[101],sg[10001],k;int getsg(int m){ int hash[101]={0}; int i; for(i=0;i<k;i++){ if(m-s[i]<0) break; if(sg[m-s[i]]==-1) sg[m-s[i]]=getsg(m-s[i]); hash[sg[
阅读全文
摘要:给出N只老鼠,两种杀法:1,一次杀一只;2,奇数的话就杀(n-1)/2只,偶数的话就杀n/2只。Alice和Bob轮流进行,Alice kill first。谁杀完最后一只老鼠者胜。第一次见这样的博弈,其实是要用模拟的思想再加上博弈的思想。#include"iostream"using namespace std;int main(){ int t; cin>>t; while(t--) { int n; cin>>n; if(n==1) { cout<<"Alice"<<endl; continue; }
阅读全文
摘要:2176在简单的NIM游戏上输出取法策略AC代码:#include"iostream" using namespace std; int main() { int m; while(cin>>m,m) { int ans=0,i,s[200001]; for(i=0;i<m;i++) { cin>>s[i]; ans^=s[i]; } if(ans==0) { cout<<"No"<<endl; continue; } cout<<"Yes"<<endl;
阅读全文
摘要:Tom和Jerry正在玩一种Northcott游戏,可是Tom老是输,因此他怀疑这个游戏是不是有某种必胜策略,郁闷的Tom现在向你求救了,你能帮帮他么? 游戏规则是这样的: 如图所示,游戏在一个n行m列(1 ≤ n ≤ 1000且2 ≤ m ≤ 100)的棋盘上进行,每行有一个黑子(黑方)和一个白子(白方)。执黑的一方先行,每次玩家可以移动己方的任何一枚棋子到同一行的任何一个空格上,当然这过程中不许越过该行的敌方棋子。双方轮流移动,直到某一方无法行动为止,移动最后一步的玩家获胜。Tom总是先下(黑方)。图1是某个初始局面,图二是Tom移动一个棋子后的局面(第一行的黑子左移两步)。 图1Inpu
阅读全文
摘要:1、 总共n张牌; 2、 双方轮流抓牌; 3、 每人每次抓牌的个数只能是2的幂次(即:1,2,4,8,16…) 4、 抓完牌,胜负结果也出来了:最后抓完牌的人为胜者;AC代码#include"iostream"using namespace std;int main(){int n;while(cin>>n){if(n%3==0)cout<<"Cici"<<endl;else cout<<"Kiki"<<endl;}return 0;}
阅读全文
浙公网安备 33010602011771号