poj1067

题意:有两堆石子,两人轮流取,每次可以取一堆中的任意个,或两堆中取相同多个。谁先取光所有堆谁赢。问先手能否获胜。

分析:威佐夫博弈,如果是奇异态则先手输,否则先手赢。直接套用公式判断是否为奇异态,设第一堆有a个,第二堆有b个,二者的差为c个。

奇异态近似符合公式b/a=a/c。即近似符合黄金分割。严格符合公式a=floor(c/黄金分割数)。黄金分割数=(sqrt(5)-1)/2。

#include <cstdio>
#include <cmath>
#include <utility>
using namespace std;

int main()
{
    int a, b;
    while (~scanf("%d%d", &a, &b))
    {
        if (a > b)
            swap(a, b);
        int difference = b - a;
        double multiplier = (1 + sqrt(5)) / 2;
        int answer = 1;
        if (a == floor(difference * multiplier))
            answer = 0;
        printf("%d\n", answer);
    }
    return 0;
}
View Code

 

posted @ 2013-07-04 16:00  金海峰  阅读(781)  评论(0编辑  收藏  举报