关于入门资料,推荐看<这里>,取火柴的那10个定理必须理解。
五篇国家集训队论文:
张一飞: 《由感性认识到理性认识——透析一类搏弈游戏的解答过程 》
王晓珂:《 解析一类组合游戏》
方展鹏:《浅谈如何解决不平等博弈问题》
贾志豪:《组合游戏略述——浅谈SG游戏的若干拓展及变形》
曹钦翔:《从“k倍动态减法游戏”出发 探究一类组合游戏问题》
下面是题目总结:
1.HDU 1404 预处理,推出所有情况的胜负情况。
1 //STATUS:C++_AC_468MS_4140KB 2 #include <functional> 3 #include <algorithm> 4 #include <iostream> 5 //#include <ext/rope> 6 #include <fstream> 7 #include <sstream> 8 #include <iomanip> 9 #include <numeric> 10 #include <cstring> 11 #include <cassert> 12 #include <cstdio> 13 #include <string> 14 #include <vector> 15 #include <bitset> 16 #include <queue> 17 #include <stack> 18 #include <cmath> 19 #include <ctime> 20 #include <list> 21 #include <set> 22 #include <map> 23 using namespace std; 24 //using namespace __gnu_cxx; 25 //define 26 #define pii pair<int,int> 27 #define mem(a,b) memset(a,b,sizeof(a)) 28 #define lson l,mid,rt<<1 29 #define rson mid+1,r,rt<<1|1 30 #define PI acos(-1.0) 31 //typedef 32 typedef long long LL; 33 typedef unsigned long long ULL; 34 //const 35 const int N=1000010; 36 const int INF=0x3f3f3f3f; 37 const int MOD=100000,STA=8000010; 38 const LL LNF=1LL<<60; 39 const double EPS=1e-8; 40 const double OO=1e15; 41 const int dx[4]={-1,0,1,0}; 42 const int dy[4]={0,1,0,-1}; 43 const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 44 //Daily Use ... 45 inline int sign(double x){return (x>EPS)-(x<-EPS);} 46 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} 47 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} 48 template<class T> inline T lcm(T a,T b,T d){return a/d*b;} 49 template<class T> inline T Min(T a,T b){return a<b?a:b;} 50 template<class T> inline T Max(T a,T b){return a>b?a:b;} 51 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} 52 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} 53 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} 54 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} 55 //End 56 57 int sta[N],ten[10]; 58 int n; 59 60 int dfs(int u,int w) 61 { 62 if(!w || u/ten[w-1]==0)return 1; 63 if(sta[u]!=-1)return sta[u]; 64 int i,j,t,v; 65 for(i=w-1;i>=0;i--){ 66 t=u/ten[i]%10; 67 if(t==0){ 68 v=u/ten[i+1]; 69 if(dfs(v,w-i-1)==0)return sta[u]=1; 70 } 71 v=u-ten[i]; 72 for(;t;t--,v-=ten[i]) 73 if(dfs(v,w)==0)return sta[u]=1; 74 } 75 return sta[u]=0; 76 } 77 78 int getw(int a) 79 { 80 if(a/10==0)return 1; 81 if(a/100==0)return 2; 82 if(a/1000==0)return 3; 83 if(a/10000==0)return 4; 84 if(a/100000==0)return 5; 85 return 6; 86 } 87 88 int main() 89 { 90 // freopen("in.txt","r",stdin); 91 int i,j,len; 92 char s[10]; 93 for(i=ten[0]=1;i<8;i++)ten[i]=ten[i-1]*10; 94 mem(sta,-1);sta[0]=1; 95 for(i=1;i<1000000;i++){ 96 if(sta[i]==-1)dfs(i,getw(i)); 97 } 98 while(~scanf("%s",s)) 99 { 100 len=strlen(s); 101 for(i=n=0;i<len;i++)n+=(s[len-i-1]-'0')*ten[i]; 102 103 printf("%s ",(s[0]=='0' || sta[n])?"Yes":"No"); 104 } 105 return 0; 106 }
2.HDU 1907 尼姆博奕,最后取玩的位loser,必败态为:T2,S0;必胜态为:S2,S1,T0;
1 //STATUS:C++_AC_0MS_228KB 2 #include <functional> 3 #include <algorithm> 4 #include <iostream> 5 //#include <ext/rope> 6 #include <fstream> 7 #include <sstream> 8 #include <iomanip> 9 #include <numeric> 10 #include <cstring> 11 #include <cassert> 12 #include <cstdio> 13 #include <string> 14 #include <vector> 15 #include <bitset> 16 #include <queue> 17 #include <stack> 18 #include <cmath> 19 #include <ctime> 20 #include <list> 21 #include <set> 22 #include <map> 23 using namespace std; 24 //using namespace __gnu_cxx; 25 //define 26 #define pii pair<int,int> 27 #define mem(a,b) memset(a,b,sizeof(a)) 28 #define lson l,mid,rt<<1 29 #define rson mid+1,r,rt<<1|1 30 #define PI acos(-1.0) 31 //typedef 32 typedef long long LL; 33 typedef unsigned long long ULL; 34 //const 35 const int N=110; 36 const int INF=0x3f3f3f3f; 37 const int MOD=100000,STA=8000010; 38 const LL LNF=1LL<<60; 39 const double EPS=1e-8; 40 const double OO=1e15; 41 const int dx[4]={-1,0,1,0}; 42 const int dy[4]={0,1,0,-1}; 43 const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 44 //Daily Use ... 45 inline int sign(double x){return (x>EPS)-(x<-EPS);} 46 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} 47 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} 48 template<class T> inline T lcm(T a,T b,T d){return a/d*b;} 49 template<class T> inline T Min(T a,T b){return a<b?a:b;} 50 template<class T> inline T Max(T a,T b){return a>b?a:b;} 51 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} 52 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} 53 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} 54 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} 55 //End 56 57 int T,n; 58 59 int main() 60 { 61 // freopen("in.txt","r",stdin); 62 int i,j,sg,a,cou; 63 scanf("%d",&T); 64 while(T--) 65 { 66 scanf("%d",&n); 67 sg=cou=0; 68 while(n--){ 69 scanf("%d",&a); 70 sg^=a; 71 if(a>1)cou++; 72 } 73 if((!cou&&sg) || (cou>=2&&!sg)) 74 printf("Brother "); 75 else printf("John "); 76 } 77 return 0; 78 }
3.HDU 2509 和上一题一样。
1 //STATUS:C++_AC_0MS_228KB 2 #include <functional> 3 #include <algorithm> 4 #include <iostream> 5 //#include <ext/rope> 6 #include <fstream> 7 #include <sstream> 8 #include <iomanip> 9 #include <numeric> 10 #include <cstring> 11 #include <cassert> 12 #include <cstdio> 13 #include <string> 14 #include <vector> 15 #include <bitset> 16 #include <queue> 17 #include <stack> 18 #include <cmath> 19 #include <ctime> 20 #include <list> 21 #include <set> 22 #include <map> 23 using namespace std; 24 //using namespace __gnu_cxx; 25 //define 26 #define pii pair<int,int> 27 #define mem(a,b) memset(a,b,sizeof(a)) 28 #define lson l,mid,rt<<1 29 #define rson mid+1,r,rt<<1|1 30 #define PI acos(-1.0) 31 //typedef 32 typedef long long LL; 33 typedef unsigned long long ULL; 34 //const 35 const int N=110; 36 const int INF=0x3f3f3f3f; 37 const int MOD=100000,STA=8000010; 38 const LL LNF=1LL<<60; 39 const double EPS=1e-8; 40 const double OO=1e15; 41 const int dx[4]={-1,0,1,0}; 42 const int dy[4]={0,1,0,-1}; 43 const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 44 //Daily Use ... 45 inline int sign(double x){return (x>EPS)-(x<-EPS);} 46 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} 47 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} 48 template<class T> inline T lcm(T a,T b,T d){return a/d*b;} 49 template<class T> inline T Min(T a,T b){return a<b?a:b;} 50 template<class T> inline T Max(T a,T b){return a>b?a:b;} 51 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} 52 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} 53 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} 54 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} 55 //End 56 57 int n; 58 59 int main() 60 { 61 // freopen("in.txt","r",stdin); 62 int i,j,sg,a,cou; 63 while(~scanf("%d",&n)) 64 { 65 sg=cou=0; 66 while(n--){ 67 scanf("%d",&a); 68 sg^=a; 69 if(a>1)cou++; 70 } 71 if((!cou&&sg) || (cou>=2&&!sg)) 72 printf("No "); 73 else printf("Yes "); 74 } 75 return 0; 76 }
4.
1 //STATUS:C++_AC_32MS_264KB 2 #include <functional> 3 #include <algorithm> 4 #include <iostream> 5 //#include <ext/rope> 6 #include <fstream> 7 #include <sstream> 8 #include <iomanip> 9 #include <numeric> 10 #include <cstring> 11 #include <cassert> 12 #include <cstdio> 13 #include <string> 14 #include <vector> 15 #include <bitset> 16 #include <queue> 17 #include <stack> 18 #include <cmath> 19 #include <ctime> 20 #include <list> 21 #include <set> 22 #include <map> 23 using namespace std; 24 //using namespace __gnu_cxx; 25 //define 26 #define pii pair<int,int> 27 #define mem(a,b) memset(a,b,sizeof(a)) 28 #define lson l,mid,rt<<1 29 #define rson mid+1,r,rt<<1|1 30 #define PI acos(-1.0) 31 //typedef 32 typedef long long LL; 33 typedef unsigned long long ULL; 34 //const 35 const int N=100000010; 36 const int INF=0x3f3f3f3f; 37 const int MOD=5000,STA=100010; 38 const LL LNF=1LL<<60; 39 const double EPS=1e-8; 40 const double OO=1e15; 41 const int dx[4]={-1,0,1,0}; 42 const int dy[4]={0,1,0,-1}; 43 const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 44 //Daily Use ... 45 inline int sign(double x){return (x>EPS)-(x<-EPS);} 46 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} 47 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} 48 template<class T> inline T lcm(T a,T b,T d){return a/d*b;} 49 template<class T> inline T Min(T a,T b){return a<b?a:b;} 50 template<class T> inline T Max(T a,T b){return a>b?a:b;} 51 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} 52 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} 53 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} 54 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} 55 //End 56 57 struct Hash 58 { 59 int i,size,next[STA]; 60 int f[MOD],sg[STA]; 61 LL sta[STA]; 62 void init(){ 63 size=0; 64 mem(f,-1); 65 } 66 int find(LL a){ 67 int s=a%MOD; 68 for(i=f[s];i!=-1;i=next[i]){ 69 if(sta[i]==a){ 70 return sg[i]; 71 } 72 } 73 sta[size]=a;sg[size]=0; 74 next[size]=f[s]; 75 f[s]=size++; 76 return -1; 77 } 78 void update(LL a){ 79 int s=a%MOD; 80 for(i=f[s];i!=-1 && sta[i]!=a;i=next[i]); 81 sg[i]=1; 82 } 83 }hs; 84 85 LL n; 86 87 int dfs(LL u) 88 { 89 if(u>=n)return 0; 90 int i,t,sg,ret=0; 91 if((t=hs.find(u))!=-1)return t; 92 for(i=2;i<=9;i++){ 93 sg=dfs(u*i); 94 if(!sg)ret=1,hs.update(u); 95 } 96 return ret; 97 } 98 99 int main() 100 { 101 // freopen("in.txt","r",stdin); 102 int i,j; 103 while(~scanf("%I64d",&n)) 104 { 105 hs.init(); 106 printf("%s wins. ",dfs((LL)1)?"Stan":"Ollie"); 107 } 108 return 0; 109 }
5.
1 //STATUS:C++_AC_0MS_228KB 2 #include <functional> 3 #include <algorithm> 4 #include <iostream> 5 //#include <ext/rope> 6 #include <fstream> 7 #include <sstream> 8 #include <iomanip> 9 #include <numeric> 10 #include <cstring> 11 #include <cassert> 12 #include <cstdio> 13 #include <string> 14 #include <vector> 15 #include <bitset> 16 #include <queue> 17 #include <stack> 18 #include <cmath> 19 #include <ctime> 20 #include <list> 21 #include <set> 22 #include <map> 23 using namespace std; 24 //using namespace __gnu_cxx; 25 //define 26 #define pii pair<int,int> 27 #define mem(a,b) memset(a,b,sizeof(a)) 28 #define lson l,mid,rt<<1 29 #define rson mid+1,r,rt<<1|1 30 #define PI acos(-1.0) 31 //typedef 32 typedef long long LL; 33 typedef unsigned long long ULL; 34 //const 35 const int N=100000010; 36 const int INF=0x3f3f3f3f; 37 const int MOD=5000,STA=100010; 38 const LL LNF=1LL<<60; 39 const double EPS=1e-8; 40 const double OO=1e15; 41 const int dx[4]={-1,0,1,0}; 42 const int dy[4]={0,1,0,-1}; 43 const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 44 //Daily Use ... 45 inline int sign(double x){return (x>EPS)-(x<-EPS);} 46 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} 47 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} 48 template<class T> inline T lcm(T a,T b,T d){return a/d*b;} 49 template<class T> inline T Min(T a,T b){return a<b?a:b;} 50 template<class T> inline T Max(T a,T b){return a>b?a:b;} 51 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} 52 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} 53 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} 54 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} 55 //End 56 57 int main() 58 { 59 // freopen("in.txt","r",stdin); 60 int n,a,sg; 61 while(~scanf("%d",&n) && n) 62 { 63 sg=0; 64 while(n--){ 65 scanf("%d",&a); 66 sg^=a; 67 } 68 69 printf("%s Win! ",sg?"Rabbit":"Grass"); 70 } 71 return 0; 72 }
1 //STATUS:C++_AC_0MS_228KB 2 #include <functional> 3 #include <algorithm> 4 #include <iostream> 5 //#include <ext/rope> 6 #include <fstream> 7 #include <sstream> 8 #include <iomanip> 9 #include <numeric> 10 #include <cstring> 11 #include <cassert> 12 #include <cstdio> 13 #include <string> 14 #include <vector> 15 #include <bitset> 16 #include <queue> 17 #include <stack> 18 #include <cmath> 19 #include <ctime> 20 #include <list> 21 #include <set> 22 #include <map> 23 using namespace std; 24 //using namespace __gnu_cxx; 25 //define 26 #define pii pair<int,int> 27 #define mem(a,b) memset(a,b,sizeof(a)) 28 #define lson l,mid,rt<<1 29 #define rson mid+1,r,rt<<1|1 30 #define PI acos(-1.0) 31 //typedef 32 typedef long long LL; 33 typedef unsigned long long ULL; 34 //const 35 const int N=100000010; 36 const int INF=0x3f3f3f3f; 37 const int MOD=5000,STA=100010; 38 const LL LNF=1LL<<60; 39 const double EPS=1e-8; 40 const double OO=1e15; 41 const int dx[4]={-1,0,1,0}; 42 const int dy[4]={0,1,0,-1}; 43 const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 44 //Daily Use ... 45 inline int sign(double x){return (x>EPS)-(x<-EPS);} 46 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} 47 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} 48 template<class T> inline T lcm(T a,T b,T d){return a/d*b;} 49 template<class T> inline T Min(T a,T b){return a<b?a:b;} 50 template<class T> inline T Max(T a,T b){return a>b?a:b;} 51 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} 52 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} 53 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} 54 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} 55 //End 56 57 int T,n,m; 58 59 int main() 60 { 61 // freopen("in.txt","r",stdin); 62 scanf("%d",&T); 63 while(T--) 64 { 65 scanf("%d%d",&n,&m); 66 printf("%s ",n%(m+1)?"Grass":"Rabbit"); 67 } 68 return 0; 69 }
7.
1 //STATUS:C++_AC_15MS_228KB 2 #include <functional> 3 #include <algorithm> 4 #include <iostream> 5 //#include <ext/rope> 6 #include <fstream> 7 #include <sstream> 8 #include <iomanip> 9 #include <numeric> 10 #include <cstring> 11 #include <cassert> 12 #include <cstdio> 13 #include <string> 14 #include <vector> 15 #include <bitset> 16 #include <queue> 17 #include <stack> 18 #include <cmath> 19 #include <ctime> 20 #include <list> 21 #include <set> 22 #include <map> 23 using namespace std; 24 //using namespace __gnu_cxx; 25 //define 26 #define pii pair<int,int> 27 #define mem(a,b) memset(a,b,sizeof(a)) 28 #define lson l,mid,rt<<1 29 #define rson mid+1,r,rt<<1|1 30 #define PI acos(-1.0) 31 //typedef 32 typedef long long LL; 33 typedef unsigned long long ULL; 34 //const 35 const int N=100000010; 36 const int INF=0x3f3f3f3f; 37 const int MOD=5000,STA=100010; 38 const LL LNF=1LL<<60; 39 const double EPS=1e-8; 40 const double OO=1e15; 41 const int dx[4]={-1,0,1,0}; 42 const int dy[4]={0,1,0,-1}; 43 const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 44 //Daily Use ... 45 inline int sign(double x){return (x>EPS)-(x<-EPS);} 46 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} 47 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} 48 template<class T> inline T lcm(T a,T b,T d){return a/d*b;} 49 template<class T> inline T Min(T a,T b){return a<b?a:b;} 50 template<class T> inline T Max(T a,T b){return a>b?a:b;} 51 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} 52 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} 53 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} 54 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} 55 //End 56 57 int T,n,m; 58 59 int main() 60 { 61 // freopen("in.txt","r",stdin); 62 int a,sg; 63 scanf("%d",&T); 64 while(T--) 65 { 66 scanf("%d",&n); 67 sg=0; 68 while(n--){ 69 scanf("%d%d",&a,&m); 70 sg^=a%(m+1); 71 } 72 printf("%s ",sg?"No":"Yes"); 73 } 74 return 0; 75 }
8.
1 //STATUS:C++_AC_62MS_228KB 2 #include <functional> 3 #include <algorithm> 4 #include <iostream> 5 //#include <ext/rope> 6 #include <fstream> 7 #include <sstream> 8 #include <iomanip> 9 #include <numeric> 10 #include <cstring> 11 #include <cassert> 12 #include <cstdio> 13 #include <string> 14 #include <vector> 15 #include <bitset> 16 #include <queue> 17 #include <stack> 18 #include <cmath> 19 #include <ctime> 20 #include <list> 21 #include <set> 22 #include <map> 23 using namespace std; 24 //using namespace __gnu_cxx; 25 //define 26 #define pii pair<int,int> 27 #define mem(a,b) memset(a,b,sizeof(a)) 28 #define lson l,mid,rt<<1 29 #define rson mid+1,r,rt<<1|1 30 #define PI acos(-1.0) 31 //typedef 32 typedef long long LL; 33 typedef unsigned long long ULL; 34 //const 35 const int N=100000010; 36 const int INF=0x3f3f3f3f; 37 const int MOD=5000,STA=100010; 38 const LL LNF=1LL<<60; 39 const double EPS=1e-8; 40 const double OO=1e15; 41 const int dx[4]={-1,0,1,0}; 42 const int dy[4]={0,1,0,-1}; 43 const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 44 //Daily Use ... 45 inline int sign(double x){return (x>EPS)-(x<-EPS);} 46 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} 47 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} 48 template<class T> inline T lcm(T a,T b,T d){return a/d*b;} 49 template<class T> inline T Min(T a,T b){return a<b?a:b;} 50 template<class T> inline T Max(T a,T b){return a>b?a:b;} 51 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} 52 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} 53 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} 54 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} 55 //End 56 57 int T,n; 58 59 int main() 60 { 61 // freopen("in.txt","r",stdin); 62 int x,y,a,p,q,sg; 63 while(~scanf("%d%d%d",&a,&p,&q)) 64 { 65 sg=0; 66 x=1,y=p; 67 while(a<x || a>y){ 68 x=y+1; 69 if(sg)y+=p; 70 else y+=q; 71 sg^=1; 72 } 73 printf("%s ",sg?"WIN":"LOST"); 74 } 75 return 0; 76 }
9.
1 //STATUS:C++_AC_0MS_228KB 2 #include <functional> 3 #include <algorithm> 4 #include <iostream> 5 //#include <ext/rope> 6 #include <fstream> 7 #include <sstream> 8 #include <iomanip> 9 #include <numeric> 10 #include <cstring> 11 #include <cassert> 12 #include <cstdio> 13 #include <string> 14 #include <vector> 15 #include <bitset> 16 #include <queue> 17 #include <stack> 18 #include <cmath> 19 #include <ctime> 20 #include <list> 21 #include <set> 22 #include <map> 23 using namespace std; 24 //using namespace __gnu_cxx; 25 //define 26 #define pii pair<int,int> 27 #define mem(a,b) memset(a,b,sizeof(a)) 28 #define lson l,mid,rt<<1 29 #define rson mid+1,r,rt<<1|1 30 #define PI acos(-1.0) 31 //typedef 32 typedef long long LL; 33 typedef unsigned long long ULL; 34 //const 35 const int N=110; 36 const int INF=0x3f3f3f3f; 37 const int MOD=5000,STA=100010; 38 const LL LNF=1LL<<60; 39 const double EPS=1e-8; 40 const double OO=1e15; 41 const int dx[4]={-1,0,1,0}; 42 const int dy[4]={0,1,0,-1}; 43 const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 44 //Daily Use ... 45 inline int sign(double x){return (x>EPS)-(x<-EPS);} 46 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} 47 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} 48 template<class T> inline T lcm(T a,T b,T d){return a/d*b;} 49 template<class T> inline T Min(T a,T b){return a<b?a:b;} 50 template<class T> inline T Max(T a,T b){return a>b?a:b;} 51 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} 52 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} 53 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} 54 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} 55 //End 56 57 int f[N]; 58 int n; 59 60 int main() 61 { 62 // freopen("in.txt","r",stdin); 63 int i,ok; 64 f[0]=f[1]=1; 65 for(i=2;i<46;i++)f[i]=f[i-1]+f[i-2]; 66 while(~scanf("%d",&n) && n) 67 { 68 ok=1; 69 for(i=0;i<46;i++)if(f[i]==n){ok=0;break;} 70 printf("%s win ",ok?"First":"Second"); 71 } 72 return 0; 73 }
10.
1 //STATUS:C++_AC_0MS_232KB 2 #include <functional> 3 #include <algorithm> 4 #include <iostream> 5 //#include <ext/rope> 6 #include <fstream> 7 #include <sstream> 8 #include <iomanip> 9 #include <numeric> 10 #include <cstring> 11 #include <cassert> 12 #include <cstdio> 13 #include <string> 14 #include <vector> 15 #include <bitset> 16 #include <queue> 17 #include <stack> 18 #include <cmath> 19 #include <ctime> 20 #include <list> 21 #include <set> 22 #include <map> 23 using namespace std; 24 //using namespace __gnu_cxx; 25 //define 26 #define pii pair<int,int> 27 #define mem(a,b) memset(a,b,sizeof(a)) 28 #define lson l,mid,rt<<1 29 #define rson mid+1,r,rt<<1|1 30 #define PI acos(-1.0) 31 //typedef 32 typedef long long LL; 33 typedef unsigned long long ULL; 34 //const 35 const int N=100000010; 36 const int INF=0x3f3f3f3f; 37 const int MOD=5000,STA=100010; 38 const LL LNF=1LL<<60; 39 const double EPS=1e-8; 40 const double OO=1e15; 41 const int dx[4]={-1,0,1,0}; 42 const int dy[4]={0,1,0,-1}; 43 const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 44 //Daily Use ... 45 inline int sign(double x){return (x>EPS)-(x<-EPS);} 46 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} 47 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} 48 template<class T> inline T lcm(T a,T b,T d){return a/d*b;} 49 template<class T> inline T Min(T a,T b){return a<b?a:b;} 50 template<class T> inline T Max(T a,T b){return a>b?a:b;} 51 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} 52 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} 53 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} 54 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} 55 //End 56 57 int n,m; 58 59 int main() 60 { 61 // freopen("in.txt","r",stdin); 62 int i,j,sg,lx,ly,x,y; 63 while(~scanf("%d%d",&m,&n)) 64 { 65 sg=1; 66 lx=m;ly=m+n; 67 x=Max(m-n,0);y=Max(0,m-1); 68 while(0<x){ 69 lx=x,ly=y; 70 if(sg)x=y=x-1; 71 else { 72 y=x-1;x-=n; 73 } 74 sg^=1; 75 } 76 77 if(sg){ 78 printf("%d",lx); 79 for(i=lx+1;i<=ly && i<=n;i++) 80 printf(" %d",i); 81 } 82 else printf("none"); 83 putchar(' '); 84 } 85 return 0; 86 }
11.
1 //STATUS:C++_AC_0MS_232KB 2 #include <functional> 3 #include <algorithm> 4 #include <iostream> 5 //#include <ext/rope> 6 #include <fstream> 7 #include <sstream> 8 #include <iomanip> 9 #include <numeric> 10 #include <cstring> 11 #include <cassert> 12 #include <cstdio> 13 #include <string> 14 #include <vector> 15 #include <bitset> 16 #include <queue> 17 #include <stack> 18 #include <cmath> 19 #include <ctime> 20 #include <list> 21 #include <set> 22 #include <map> 23 using namespace std; 24 //using namespace __gnu_cxx; 25 //define 26 #define pii pair<int,int> 27 #define mem(a,b) memset(a,b,sizeof(a)) 28 #define lson l,mid,rt<<1 29 #define rson mid+1,r,rt<<1|1 30 #define PI acos(-1.0) 31 //typedef 32 typedef long long LL; 33 typedef unsigned long long ULL; 34 //const 35 const int N=1000010; 36 const int INF=0x3f3f3f3f; 37 const int MOD=5000,STA=100010; 38 const LL LNF=1LL<<60; 39 const double EPS=1e-8; 40 const double OO=1e15; 41 const int dx[4]={-1,0,1,0}; 42 const int dy[4]={0,1,0,-1}; 43 const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 44 //Daily Use ... 45 inline int sign(double x){return (x>EPS)-(x<-EPS);} 46 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} 47 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} 48 template<class T> inline T lcm(T a,T b,T d){return a/d*b;} 49 template<class T> inline T Min(T a,T b){return a<b?a:b;} 50 template<class T> inline T Max(T a,T b){return a>b?a:b;} 51 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} 52 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} 53 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} 54 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} 55 //End 56 57 int num[N]; 58 int n; 59 60 int main() 61 { 62 // freopen("in.txt","r",stdin); 63 int i,j,sg,w,ans; 64 while(~scanf("%d",&n) && n) 65 { 66 sg=0; 67 for(i=0;i<n;i++){ 68 scanf("%d",&num[i]); 69 sg^=num[i]; 70 } 71 if(sg){ 72 for(i=0;i<31;i++) 73 if(sg&(1<<i))w=(1<<i); 74 for(i=ans=0;i<n;i++){ 75 if(num[i]&w)ans++; 76 } 77 } 78 79 printf("%d ",sg?ans:0); 80 } 81 return 0; 82 }
12.
1 //STATUS:C++_AC_0MS_228KB 2 #include <functional> 3 #include <algorithm> 4 #include <iostream> 5 //#include <ext/rope> 6 #include <fstream> 7 #include <sstream> 8 #include <iomanip> 9 #include <numeric> 10 #include <cstring> 11 #include <cassert> 12 #include <cstdio> 13 #include <string> 14 #include <vector> 15 #include <bitset> 16 #include <queue> 17 #include <stack> 18 #include <cmath> 19 #include <ctime> 20 #include <list> 21 #include <set> 22 #include <map> 23 using namespace std; 24 //using namespace __gnu_cxx; 25 //define 26 #define pii pair<int,int> 27 #define mem(a,b) memset(a,b,sizeof(a)) 28 #define lson l,mid,rt<<1 29 #define rson mid+1,r,rt<<1|1 30 #define PI acos(-1.0) 31 //typedef 32 typedef long long LL; 33 typedef unsigned long long ULL; 34 //const 35 const int N=20; 36 const int INF=0x3f3f3f3f; 37 const int MOD=5000,STA=100010; 38 const LL LNF=1LL<<60; 39 const double EPS=1e-8; 40 const double OO=1e15; 41 const int dx[4]={-1,0,1,0}; 42 const int dy[4]={0,1,0,-1}; 43 const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 44 //Daily Use ... 45 inline int sign(double x){return (x>EPS)-(x<-EPS);} 46 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} 47 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} 48 template<class T> inline T lcm(T a,T b,T d){return a/d*b;} 49 template<class T> inline T Min(T a,T b){return a<b?a:b;} 50 template<class T> inline T Max(T a,T b){return a>b?a:b;} 51 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} 52 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} 53 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} 54 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} 55 //End 56 57 int num[N],g[5]; 58 int T,n=15; 59 60 int main() 61 { 62 // freopen("in.txt","r",stdin); 63 int i,j,cou[2],w,ca=1; 64 scanf("%d",&T); 65 while(T--) 66 { 67 for(i=1;i<=n;i++) 68 scanf("%d",&num[i]); 69 g[1]=num[15]; 70 g[2]=num[5]+num[6]-num[3]-num[4]; 71 g[3]=num[11]+num[12]+num[13]+num[14]; 72 g[4]=num[7]+num[8]-num[9]-num[10]; 73 // printf("%d %d %d %d ",g[1],g[2],g[3],g[4]); 74 cou[0]=num[1]*2;cou[1]=num[2]*2; 75 w=0; 76 if(g[1]&1){cou[w]++;w^=1;} 77 if(g[2]){ 78 if(g[2]>0)cou[0]+=g[2]/2; 79 else cou[1]+=(-g[2])/2; 80 if(g[2]&1){ 81 if((!w && g[2]>0) || (w && g[2]<0))cou[w]++; 82 w^=1; 83 } 84 } 85 if(g[3]&1)w^=1; 86 if(g[4]){ 87 if(g[4]>0)cou[0]+=g[4]/2; 88 else cou[1]+=(-g[4])/2; 89 if(g[4]&1){ 90 if((w && g[4]>0) || (!w && g[4]<0))cou[!w]++; 91 w^=1; 92 } 93 } 94 95 printf("Case #%d: %s ",ca++,((cou[0]>cou[1]) || (cou[0]==cou[1] && w))?"Alice":"Bob"); 96 } 97 return 0; 98 }
13.
1 //STATUS:C++_AC_0MS_228KB 2 #include <functional> 3 #include <algorithm> 4 #include <iostream> 5 //#include <ext/rope> 6 #include <fstream> 7 #include <sstream> 8 #include <iomanip> 9 #include <numeric> 10 #include <cstring> 11 #include <cassert> 12 #include <cstdio> 13 #include <string> 14 #include <vector> 15 #include <bitset> 16 #include <queue> 17 #include <stack> 18 #include <cmath> 19 #include <ctime> 20 #include <list> 21 #include <set> 22 #include <map> 23 using namespace std; 24 //using namespace __gnu_cxx; 25 //define 26 #define pii pair<int,int> 27 #define mem(a,b) memset(a,b,sizeof(a)) 28 #define lson l,mid,rt<<1 29 #define rson mid+1,r,rt<<1|1 30 #define PI acos(-1.0) 31 //typedef 32 typedef long long LL; 33 typedef unsigned long long ULL; 34 //const 35 const int N=20; 36 const int INF=0x3f3f3f3f; 37 const int MOD=5000,STA=100010; 38 const LL LNF=1LL<<60; 39 const double EPS=1e-8; 40 const double OO=1e15; 41 const int dx[4]={-1,0,1,0}; 42 const int dy[4]={0,1,0,-1}; 43 const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 44 //Daily Use ... 45 inline int sign(double x){return (x>EPS)-(x<-EPS);} 46 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} 47 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} 48 template<class T> inline T lcm(T a,T b,T d){return a/d*b;} 49 template<class T> inline T Min(T a,T b){return a<b?a:b;} 50 template<class T> inline T Max(T a,T b){return a>b?a:b;} 51 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} 52 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} 53 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} 54 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} 55 //End 56 57 int n; 58 59 int main() 60 { 61 // freopen("in.txt","r",stdin); 62 while(~scanf("%d",&n)) 63 { 64 printf("%s ",n%3?"Kiki":"Cici"); 65 } 66 return 0; 67 }
14.
1 //STATUS:C++_AC_15MS_228KB 2 #include <functional> 3 #include <algorithm> 4 #include <iostream> 5 //#include <ext/rope> 6 #include <fstream> 7 #include <sstream> 8 #include <iomanip> 9 #include <numeric> 10 #include <cstring> 11 #include <cassert> 12 #include <cstdio> 13 #include <string> 14 #include <vector> 15 #include <bitset> 16 #include <queue> 17 #include <stack> 18 #include <cmath> 19 #include <ctime> 20 #include <list> 21 #include <set> 22 #include <map> 23 using namespace std; 24 //using namespace __gnu_cxx; 25 //define 26 #define pii pair<int,int> 27 #define mem(a,b) memset(a,b,sizeof(a)) 28 #define lson l,mid,rt<<1 29 #define rson mid+1,r,rt<<1|1 30 #define PI acos(-1.0) 31 //typedef 32 typedef long long LL; 33 typedef unsigned long long ULL; 34 //const 35 const int N=20; 36 const int INF=0x3f3f3f3f; 37 const int MOD=5000,STA=100010; 38 const LL LNF=1LL<<60; 39 const double EPS=1e-8; 40 const double OO=1e15; 41 const int dx[4]={-1,0,1,0}; 42 const int dy[4]={0,1,0,-1}; 43 const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 44 //Daily Use ... 45 inline int sign(double x){return (x>EPS)-(x<-EPS);} 46 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} 47 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} 48 template<class T> inline T lcm(T a,T b,T d){return a/d*b;} 49 template<class T> inline T Min(T a,T b){return a<b?a:b;} 50 template<class T> inline T Max(T a,T b){return a>b?a:b;} 51 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} 52 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} 53 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} 54 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} 55 //End 56 57 int n; 58 59 int main() 60 { 61 // freopen("in.txt","r",stdin); 62 int a,b; 63 while(scanf("%d%d",&a,&b) && a && b) 64 { 65 printf("%s ",(a&1 && b&1)?"What a pity!":"Wonderful!"); 66 } 67 return 0; 68 }
15.
1 //STATUS:C++_AC_15MS_228KB 2 #include <functional> 3 #include <algorithm> 4 #include <iostream> 5 //#include <ext/rope> 6 #include <fstream> 7 #include <sstream> 8 #include <iomanip> 9 #include <numeric> 10 #include <cstring> 11 #include <cassert> 12 #include <cstdio> 13 #include <string> 14 #include <vector> 15 #include <bitset> 16 #include <queue> 17 #include <stack> 18 #include <cmath> 19 #include <ctime> 20 #include <list> 21 #include <set> 22 #include <map> 23 using namespace std; 24 //using namespace __gnu_cxx; 25 //define 26 #define pii pair<int,int> 27 #define mem(a,b) memset(a,b,sizeof(a)) 28 #define lson l,mid,rt<<1 29 #define rson mid+1,r,rt<<1|1 30 #define PI acos(-1.0) 31 //typedef 32 typedef long long LL; 33 typedef unsigned long long ULL; 34 //const 35 const int N=210; 36 const int INF=0x3f3f3f3f; 37 const int MOD=5000,STA=100010; 38 const LL LNF=1LL<<60; 39 const double EPS=1e-8; 40 const double OO=1e15; 41 const int dx[4]={-1,0,1,0}; 42 const int dy[4]={0,1,0,-1}; 43 const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 44 //Daily Use ... 45 inline int sign(double x){return (x>EPS)-(x<-EPS);} 46 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} 47 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} 48 template<class T> inline T lcm(T a,T b,T d){return a/d*b;} 49 template<class T> inline T Min(T a,T b){return a<b?a:b;} 50 template<class T> inline T Max(T a,T b){return a>b?a:b;} 51 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} 52 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} 53 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} 54 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} 55 //End 56 57 int main() 58 { 59 // freopen("in.txt","r",stdin); 60 int ok,a,b,w; 61 while(~scanf("%d%d",&a,&b) && (a||b)) 62 { 63 ok=w=0; 64 while(a && b){ 65 if(a>b)swap(a,b); 66 if(b/a>=2){ 67 if(!w)ok=1; 68 else ok=2; 69 break; 70 } 71 b-=b/a*a; 72 w^=1; 73 } 74 if(!ok){ 75 if(w)ok=1; 76 else ok=2; 77 } 78 79 printf("%s wins ",ok==1?"Stan":"Ollie"); 80 } 81 return 0; 82 }
16.HDU 3032 可以将一堆石子分成多堆——Multi-SG游戏,将SG函数适当变形,然后找规律。
1 //STATUS:C++_AC_0MS_228KB 2 #include <functional> 3 #include <algorithm> 4 #include <iostream> 5 //#include <ext/rope> 6 #include <fstream> 7 #include <sstream> 8 #include <iomanip> 9 #include <numeric> 10 #include <cstring> 11 #include <cassert> 12 #include <cstdio> 13 #include <string> 14 #include <vector> 15 #include <bitset> 16 #include <queue> 17 #include <stack> 18 #include <cmath> 19 #include <ctime> 20 #include <list> 21 #include <set> 22 #include <map> 23 using namespace std; 24 //using namespace __gnu_cxx; 25 //define 26 #define pii pair<int,int> 27 #define mem(a,b) memset(a,b,sizeof(a)) 28 #define lson l,mid,rt<<1 29 #define rson mid+1,r,rt<<1|1 30 #define PI acos(-1.0) 31 //typedef 32 typedef long long LL; 33 typedef unsigned long long ULL; 34 //const 35 const int N=210; 36 const int INF=0x3f3f3f3f; 37 const int MOD=5000,STA=100010; 38 const LL LNF=1LL<<60; 39 const double EPS=1e-8; 40 const double OO=1e15; 41 const int dx[4]={-1,0,1,0}; 42 const int dy[4]={0,1,0,-1}; 43 const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 44 //Daily Use ... 45 inline int sign(double x){return (x>EPS)-(x<-EPS);} 46 template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} 47 template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} 48 template<class T> inline T lcm(T a,T b,T d){return a/d*b;} 49 template<class T> inline T Min(T a,T b){return a<b?a:b;} 50 template<class T> inline T Max(T a,T b){return a>b?a:b;} 51 template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} 52 template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} 53 template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} 54 template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} 55 //End 56 57 int T,n; 58 59 int main() 60 { 61 // freopen("in.txt","r",stdin); 62 LL a,sg; 63 scanf("%d",&T); 64 while(T--) 65 { 66 scanf("%d",&n); 67 sg=0; 68 while(n--){ 69 scanf("%I64d",&a); 70 if(a%4==0)sg^=a-1; 71 else if(a%4==3)sg^=a+1; 72 else sg^=a; 73 } 74 75 printf("%s ",sg?"Alice":"Bob"); 76 } 77 return 0; 78 }