ACM模板——简单博弈
巴什博弈:只有一堆n个物品,两个人轮流从这堆物品中取物, 规定每次至少取一个,最多取m个。最后取光者得胜。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
if(n%(m+1)) first win else second win
变种:取光者输
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
if(!(n-1)%(m+1)) second win else first win
威佐夫博弈:有两堆各若干个物品,两个人轮流从任一堆取至少一个或同时从两堆中取同样多的物品,规定每次至少取一个,多者不限,最后取光者得胜。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
double r = (sqrt(5.0)+1)/2; int d = abs(a-b)*r; if(d!=min(a,b)) first win else second win
尼姆博弈:n堆物品,两人轮流取,每次取某堆中不少于1个,最后取完者胜。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
int res = 0; _for(i,1,n+1) res = res ^ a[i]; if(res) first win else second win
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
int f[N],SG[N]; bool S[M]; void getSG(int n) { memset(SG,0,sizeof(SG)); for(int i=1;i<=n;i++) { memset(S,false,sizeof(S)); for(int j=1;f[j]<=i&&j<M;j++) { S[SG[i-f[j]]]=true; } while(S[SG[i]]) SG[i]++; } }