题目大意:有两堆石子,两人轮流取,每次可以取一堆中的任意个,或两堆中取相同多个。谁先取光所有堆谁赢。问先手能否获胜。
分析:威佐夫博弈,如果是奇异态则先手输,否则先手赢。直接套用公式判断是否为奇异态,设第一堆有a个,第二堆有b个,二者的差为c个。
奇异态近似符合公式b/a=a/c。即近似符合黄金分割。严格符合公式a=floor(c/黄金分割数)。黄金分割数=(sqrt(5)-1)/2。
# include<cstdio> # include<iostream> # include<cmath> # include<cstring> # include<algorithm> using namespace std; int main(void) { int a,b; int t; int k; while( scanf("%d%d",&a,&b) == 2 ) { if ( a > b ) { t = a; a = b; b = t; } k = b - a; t = (floor)(k*(1.0+sqrt(5.0))/2.0); if ( t == a ) cout<<"0"<<endl; else cout<<"1"<<endl; } return 0; }