POJ 1067 取石子游戏 (威佐夫博弈)

来源:互联网 发布:nginx禁止代理ip访问 编辑:程序博客网 时间:2024/06/10 10:16

题目链接:http://poj.org/problem?id=1067

看解析看得也很辛苦,当时做之前是先知道了有这个博弈的,所以偷懒了。不过知其然还要知其所以然吧。

http://poj.org/showmessage?message_id=48161 写的挺详细的,看不看得懂就要靠天赋了。。。


#include<iostream>#include<cstring>#include<cmath>#include<cstdio>#include<algorithm>using namespace std;int main () {    int a, b;    double x = (1 + sqrt(5.0)) / 2;    while (~scanf("%d%d", &a, &b)) {        if(a > b) {            swap(a, b);        }        printf("%d\n", (a == (int)((b - a) * x)) ? 0: 1);    }    return 0 ;}


0 0