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

根据威佐夫博弈的结论,若当前是 \(N\) 态,则必须满足 \(a=(b-a)\times \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;
}

posted @ 2020-08-14 11:24  With_penguin  阅读(146)  评论(0编辑  收藏  举报