威佐夫博弈——hdu1527

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

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

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

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

代码如下:

#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5+6;

int main()
{
    int n,m;
    while(cin >> m >> n) {
        int x = min(n,m);
        int y = max(n,m);
        double z = (double)y - x;
        int t = (int)(z*(1+sqrt(5))/2.0);
        if(t == x) printf("0
");
        else printf("1
");
    }
    return 0;
}

——

原文地址:https://www.cnblogs.com/cunyusup/p/8483371.html