有两堆石子,数量任意,可以不同。游戏开始由两个人轮流取石子。游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子;二是可以在两堆中同时取走相同数量的石子。最后把石子全部取完者为胜者。现在给出初始的两堆石子的数目,如果轮到你先取,假设双方都采取最好的策略,问最后你是胜者还是败者。如果你胜,你第1次怎样取子?
1 2 5 72 20 0
013 53 54 710 01 2
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,i;
	int t,temp,temp1;
	while(~scanf("%d%d",&a,&b),a+b)
	{
		if(a>=b)
		swap(a,b);
		int k=b-a;
		int t=k*(1+sqrt(5))/2;
		if(t==a)
		{
			printf("0\n");
		}
		else
		{
			printf("1\n");
			if(abs(t-a)==abs(t+k-b)&&t<a)//两堆的情况
			printf("%d %d\n",t,t+k);//奇异局势就是剩下来的状态
			if(a==0)
			printf("0 0\n");//0.0也是奇异局势点
			for(i=0;i<=b;i++)//当在一堆中取得时候
			{
				temp=i*(1+sqrt(5))/2;
				temp1=temp+i;
				if(temp==a&&temp1<b)
				printf("%d %d\n",a,temp1);
				else if(temp1==a&&temp<b)
				printf("%d %d\n",temp,a);
				else if(temp1==b&&temp<a)
				printf("%d %d\n",temp,b);
			}
		}
	}
	return 0;
} 原文:http://blog.csdn.net/ice_alone/article/details/39440353