威佐夫博弈:有两堆各若干个物品,两个人轮流从任意一堆中取出至少一个或者同时从两堆中取出同样多的物品,规定每次至少取一个,至多不限,最后取光者胜利。
结论:首先黄金比例:r=1.618 = (sqrt(5.0) + 1) / 2,则给定两组石头堆(n,m),假设n>m,则当(n-m)*r==m时,先手输。否则后手输
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
//freopen("t.txt","r",stdin);
int n,m,a,b,t;
double r=(sqrt(5.0)+1)/2,c;
while(scanf("%d%d",&n,&m)!=EOF)
{
a=max(n,m);
b=min(n,m);
c=(double)(a-b);
t=(int)(r*c);
if(t==b) printf("0\n");//先手输
else printf("1\n");
}
return 0;
}