HDU 2176 取(m堆)石子游戏

^^^转载请注明出处,谢谢合作O(∩_∩)O~

Problem Description
m堆石子,两人轮流取.只能在1堆中取.取完者胜.先取者负输出No.先取者胜输出Yes,然后输出怎样取子.例如5堆 5,7,8,9,10先取者胜,先取者第1次取时可以从有8个的那一堆取走7个剩下1个,也可以从有9个的中那一堆取走9个剩下0个,也可以从有10个的中那一堆取走7个剩下3个.
 
Input
输入有多组.每组第1行是m,m<=200000. 后面m个非零正整数.m=0退出.
 
Output
先取者负输出No.先取者胜输出Yes,然后输出先取者第1次取子的所有方法.如果从有a个石子的堆中取若干个后剩下b个后会胜就输出a b.参看Sample Output.
 
Sample Input
2 45 45 3 3 6 9 5 5 7 8 9 10 0
 
Sample Output
No Yes 9 5 Yes 8 1 9 0 10 3
 
尼姆博弈:
关键在于计算从某一堆中取剩下多少个以后变为奇异局势:
#include <iostream>
using namespace std;
#define M 200000+10
int a[M];
int main()
{
     int m,s,x;
     while(scanf("%d",&m)!=EOF)
     {
         s=0;
         if(m==0)break;
         int i;
         for(i=0;i<m;i++)
         {
          cin>>a[i];
          s=s^a[i];
         }
         if(s==0)
         printf("No\n");
         else
         {
             printf("Yes\n");             
            for(i=0;i<m;i++)
            {
                x=a[i]^s;
                if(a[i]>x)
                printf("%d %d\n",a[i],x);
            } 
              
         }
          
     }
        
    return 0;
}
 
原文地址:https://www.cnblogs.com/hsqdboke/p/2450022.html