P2252 威佐夫博弈

传送门

题目描述:给两堆物品,两人玩游戏,给出两种选择,一种是选择一个x,让两堆物品同时减去一个x个,

另一种是让某一堆物品减去x个,最终使得两堆物品都减为0的胜利。

模板题,用黄金分割率乘一下两个数的差值然后取整,如果值等于较小的那个数,则先手不能赢,反之后手赢。

模板代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 10000005;
const int inf = 0x3f3f3f3f;
int main() {
    int a, b;
    scanf("%d%d", &a, &b);
    if (a > b)swap(a, b);
    double gold = (1 + sqrt(5)) / 2;
    int res = int((b - a) * gold);
    if (res == a)printf("0");
    else printf("1");
    return 0;
}

 

posted @ 2021-04-27 19:22  cono奇犽哒  阅读(35)  评论(0编辑  收藏  举报