洛谷 P2252 取石子游戏

洛谷 P2252
HDU 1527

题目分析

经典的威佐夫博弈

假设两堆石子为 \((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");
	}
}
posted @ 2020-09-07 08:43  Kersen  阅读(146)  评论(0编辑  收藏  举报