Alice and Bob

Problem description
  Alice and Bob are very smart guys and they like to play all kinds of games in their spare time. The most amazing thing is that they always find the best strategy, and that's why they feel bored again and again. They just invented a new game, as they usually did. The rule of the new game is quite simple.
There are N heap of stones,the i_th heap has Ai stones.
the operation should follow only one rule:one operation can only operate in one heap,and the stone of taking away in a time must no less than half number of the heap.  For example :having a heap which has 5 stones,you can pick up 3,4,or 5.having a heap which has 2 stones ,you can pick up 1or2 stone.
Alice and Bob operate take turns .he who first can’t operate is loss.
As usual,alice operates first; 

Input
  There are multiple cases,each case have two lines.first line have a integer N(0
Output
  If Alice win output “YES” otherwise output “NO”.

Sample Input
2
3 4
3
1 2 4
0
Sample Output
YES
NO
Problem Source
  湖南师范大学第四届大学生计算机程序设计竞赛
#include
#include<string.h>

int b[3000],sg[3000];

int main()
{
    int i,j,n,ans,date;
    sg[0]=0;
    for(i=1; i<2050; i++)
    {//单堆石子游戏的SG函数
        memset(b,0,sizeof(b));
        for(j=0; j<=i/2; j++) b[sg[j]]=1;
        for(j=0; b[j]==1&&j<101; j++);
        sg[i]=j;
    }//多堆石子游戏,石子之间没有关系,做异或运算
    while(scanf("%d",&n),n)
    {
        ans=0;
        for(i=0; i)
        {
            scanf("%d",&date);
            ans^=sg[date];
        }
        if(ans)  printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}
博弈论

 

转载于:https://www.cnblogs.com/contestant/p/3307812.html

你可能感兴趣的:(Alice and Bob)