hdu 1527 取石子游戏(威佐夫博弈)

 威佐夫博弈(Wythoff Game):

有两堆各若干的物品,两人轮流从其中一堆取至少一件物品,至多不限,或从两堆中同时取相同件物品,规定最后取完者胜利。

直接说结论了,若两堆物品的初始值为(xy),且x<y,则另z=y-x

w=int[((sqrt5+1/2*z  ]

w=x,则先手必败,否则先手必胜。

#include<stdio.h>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){

	int n1,n2,temp;
	while(scanf("%d%d",&n1,&n2)!=EOF){
		
		if(n1>n2)swap(n1,n2);
		//floor向下取整 
		temp=floor(n2-n1)*(1+sqrt(5.0))/2.0;
		if(temp==n1)printf("0\n");
		else printf("1\n");

	}
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/l2533636371/article/details/80167085
今日推荐