威佐夫博弈 poj 1067

 威佐夫博弈(Wythoff Game):

有两堆各若干的物品,两人轮流从其中一堆取至少一件物品,至多不限,或从两堆中同时取相同件物品,规定最后取完者胜利。

直接说结论了,若两堆物品的初始值为(x,y),且x<y,则另z=y-x;

记w=(int)[((sqrt(5)+1)/2)*z  ];

若w=x,则先手必败,否则先手必胜。

#include<bits/stdc++.h>
using namespace std;
int main()
{
        int x,y;
        while(cin>>x>>y){
            if(x>y) swap(x,y);
            int z=y-x;
            int w = (int)(((sqrt(5.0)+1)/2)*z);
            if(w==x) cout<<"0"<<endl;
            else cout<<"1"<<endl;
        }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41156122/article/details/80398332