luogu P2252 [SHOI2002]取石子游戏|【模板】威佐夫博弈

根据威佐夫博弈的结论,若当前是 (N) 态,则必须满足 (a=(b-a) imes frac{sqrt5 +1}2)(a,b) 为两堆石子的个数)。

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

int a,b;

void init()
{
	scanf("%d %d",&a,&b);
}

void work()
{
	if(a>b) swap(a,b);
	puts(((int)((sqrt(5)+1)/2*(b-a)))==a?"0":"1");
}

int main()
{
	init();
	work();
	return 0;
}

原文地址:https://www.cnblogs.com/With-penguin/p/13501186.html