HDU 1849 Rabbit and Grass

思路:Nim博弈

    将每个棋子的位置看作一堆牌的数量,这就可以使用HDU1850 Being a Good Boy in Spring Festivaly的解题思路了

   解题方法链接:http://blog.csdn.net/qinmusiyan/article/details/7949557


给出代码:


#include<stdio.h>
int main()
{
   int n,sum,i,a;
   while(scanf("%d",&n)&&n)
   {
      sum=0;
	  for(i=0;i<n;i++)
	  {
	     scanf("%d",&a);
		 sum=sum^a;
	  }
	  printf(sum==0?"Grass Win!\n":"Rabbit Win!\n");
	  
   }
   return 0;
}


你可能感兴趣的:(HDU 1849 Rabbit and Grass)