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

来源:互联网 发布:php 打开文件过程 编辑:程序博客网 时间:2024/06/06 02:47

这个黄金分割数是重点。。。

#include <iostream>#include <cmath>#include <stdio.h>using namespace std;const double q = (1 + sqrt(5.0)) / 2.0;   // 黄金分割数int Wythoff(int a, int b){    if (a > b)  swap(a, b);    int k = b - a;    if (a == (int)(k * q))  return 0;               // 奇异局面, 先手必败    return 1;}int main (){    int a, b;    while (scanf("%d%d", &a, &b) != EOF)    {       printf("%d\n", Wythoff(a, b));    }}


0 0