问题链接:POJ1067 HDU1527 取石子游戏。
问题描述:参见上文。
问题分析:这是一个博弈题,参见参考链接。
程序说明:
(略)
参考链接:
AC的C++语言程序:
/* POJ1067 HDU1527 取石子游戏 */ #include <iostream> #include <cmath> using namespace std; const double q = (1 + sqrt(5.0)) / 2.0; // 黄金分割数 int Wythoff(int a, int b) { if (a > b) swap(a, b); // 0:奇异局面, 先手必败 return (a == (int)((b - a) * q)) ? 0 : 1; } int main() { int a, b; while(cin >> a >> b) cout << Wythoff(a, b) << endl; return 0; }