poj 1067 取石子游戏

/* Name:poj 1067 取石子游戏 Author: Unimen Date: 16/04/11 16:51 Description: 威佐夫博奕 */ /* 解题报告:威佐夫博弈 分析: 比较裸的威佐夫博奕(Wythoff Game) 有黄金分割知,不安全局面(an,bn)满足: an = floor(a*n),bn = floor(b*n); 其中: a = (1+sqrt(5))/2 b = (3+sqrt(5))/2 在本题中,已知石子个数A,B,判断A,B是否能满足上述条件,即 若存在n能使得: floor(n*a)==A,floor(n*b)==B (1) 那么便必输,否则必胜 逆推上式,若存在该n,则 n = ceil(A/a),然后再判断(1)是否成立即可。 特别注意:在n的求解中必须向上取整! */ #include <iostream> #include <cmath> using namespace std; int an, bn; bool Judge() { double a = ( 1 + sqrt(5) ) / 2; double b = ( 3 + sqrt(5) ) / 2; int n = ceil( an/a ); if(floor( a * n)==an && floor( b*n )==bn) return false; return true; } int main() { while(cin>>an>>bn) { if(an>bn) { an ^= bn; bn ^= an; an ^= bn; } if(Judge()) cout<<1<<endl; else cout<<0<<endl; } return 0; }

你可能感兴趣的:(poj 1067 取石子游戏)