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<N<=100).which represents having N heap stones.follow line have N integers A1,A2,A3,…An(1<=Ai<=2048), each represents the number of stones of the i_th heap .input end with 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<stdio.h>
#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<n; i++)
        {
            scanf("%d",&date);
            ans^=sg[date];
        }
        if(ans)  printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}
博弈论

 

posted @ 2013-09-07 21:41  1002liu  阅读(276)  评论(0编辑  收藏  举报