hdu 1527 取石子游戏 (威佐夫博奕)

来源:互联网 发布:大学网络宣传部简介 编辑:程序博客网 时间:2024/04/29 14:00

威佐夫博奕

相对于nim游戏的任意堆石子,每次在任意一堆至少取一个。威佐夫博奕有两堆石子,要么在两堆同时取一样的石子,要么在其中一堆取至少一个石子。
其必败态叫做奇异局势:

k1+52,k1+52+k   |  k=0,1,2...

可以求得。
下题为判定给定n,m是否为奇异局势。

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cmath>using namespace std;#define pr(x) cout << #x << ": " << x << "  " #define pl(x) cout << #x << ": " << x << endl;struct jibancanyang{    int n, m;    void fun() {        while (~scanf("%d%d", &n, &m)) {            if (n > m) swap(n, m);            bool ok = true;            int k = m - n;            int a = k * (1 + sqrt(5)) / 2;            if (a == n) {                ok = false;            }            printf("%d\n", ok);        }    }}ac;int main(){#ifdef LOCAL    freopen("in.txt", "r", stdin);    //freopen("out.txt", "w", stdout);#endif    ac.fun();    return 0;}
0 0