跟编程之美上面的NIM(3)和NIM(2)是相同的思想
源代码如下:
#include<stdio.h>
#include<math.h>
void swap(int &a,int &b)
{int x=a;a=b;b=x;
}
int main()
{int a,b;while(scanf("%d%d",&a,&b)!=EOF){if(a>b)swap(a,b);double x=(1+sqrt(5.0))/2;double y=(3+sqrt(5.0))/2;int m=floor(x*(b-a));int n=floor(y*(b-a));if(m==a&&n==b)printf("0\n");elseprintf("1\n");}return 0;
}
#include<stdio.h>
int main()
{int M;while(scanf("%d",&M)!=EOF){int i,a[21],result;for(i=0;i<M;i++){scanf("%d",a+i);}if(M==1)printf("Yes\n");else{result=a[0]^a[1];for(i=2;i<M;i++)result=result^a[i];if(result!=0)printf("Yes\n");elseprintf("No\n");}}return 0;
}