取石子游戏 HDU - 1527
威佐夫博弈:有两堆若干个物品,两个人轮流取物品,两种方式:从某一堆取任意多物品或同时从两堆中取同样多的物品,规定每次至少取一次,多者不限,最后取完者获胜。结论:若两堆物品的初始值为(x,y),且x<y,记temp=(int)[((sqrt(5.0)+1.0)/2.0)*z ];若temp=x,则先手败,否则先手胜。
AC代码如下:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int x, y,temp;
while (cin >> x >> y)
{
if (x > y)
swap(x, y);
temp = (int)(((sqrt(5.0) + 1.0) / 2.0)* (y - x));
if (temp == x)
cout << "0" << endl;
else
cout << "1" << endl;
}
return 0;
}