洛谷 P2252 取石子游戏
题目分析
经典的威佐夫博弈
假设两堆石子为 \((x, y) \ (x < y)\)
当且仅当 $(y - x) \times \frac{\sqrt 5 + 1} {3} = x $ 时先手必败。
code
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
#define N 100010
#define M 1010
using namespace std;
double a, b;
int main() {
while (cin >> a >> b) {
if (a > b) swap(a, b);
int x = (b - a) * ((sqrt(5.0) + 1.0) / 2.0);
if (x == a) puts("0");
else puts("1");
}
}