zoukankan      html  css  js  c++  java
  • hdu 4388 Stone Game II sg函数 博弈

    Stone Game II comes. It needs two players to play this game. There are some piles of stones on the desk at the beginning. Two players move the stones in turn. At each step of the game the player should do the following operations.
      First, choose a pile of stones. (We assume that the number of stones in this pile is n)
      Second, take some stones from this pile. Assume the number of stones left in this pile is k. The player must ensure that 0 < k < n and (k XOR n) < n, otherwise he loses.
      At last, add a new pile of size (k XOR n). Now the player can add a pile of size ((2*k) XOR n) instead of (k XOR n) (However, there is only one opportunity for each player in each game).
    The first player who can't do these operations loses. Suppose two players will do their best in the game, you are asked to write a program to determine who will win the game.


    Input  The first line contains the number T of test cases (T<=150). The first line of each test cases contains an integer number n (n<=50), denoting the number of piles. The following n integers describe the number of stones in each pile at the beginning of the game.
    You can assume that all the number of stones in each pile will not exceed 100,000.
    Output  For each test case, print the case number and the answer. if the first player will win the game print "Yes"(quotes for clarity) in a single line, otherwise print "No"(quotes for clarity).
    Sample Input
    3
    2
    1 2
    3
    1 2 3
    4
    1 2 3 3
    Sample Output
    Case 1: No
    Case 2: Yes
    Case 3: No

    http://blog.csdn.net/y1196645376/article/details/52143551
     1 #pragma GCC optimize(2)
     2 #pragma G++ optimize(2)
     3 #include<iostream>
     4 #include<algorithm>
     5 #include<cmath>
     6 #include<cstdio>
     7 #include<cstring>
     8 
     9 #define N 27
    10 using namespace std;
    11 inline int read()
    12 {
    13     int x=0,f=1;char ch=getchar();
    14     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    15     while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    16     return x*f;
    17 }
    18     int getone(int num)//得到一个数二进制中1的个数  
    19     {  
    20         int cnt = 0;  
    21         while(num)  
    22         {  
    23             cnt += (num&1);  
    24             num>>=1;  
    25         }  
    26         return cnt;  
    27     }  
    28     int main()  
    29     {  
    30         int t,n,k,_case = 0;  
    31         cin >> t;  
    32         while(t--)  
    33         {  
    34             cin >> n;  
    35             printf("Case %d: ",++_case);  
    36             k = 0;  
    37             int step;  
    38             for(int i = 0 ;  i < n ; i ++)  
    39             {  
    40                  scanf("%d",&step);  
    41                  k += getone(step);  
    42             }  
    43             printf((k+n)&1? "Yes
    ":"No
    ");  
    44         }  
    45         return 0;  
    46     }  
  • 相关阅读:
    进程与线程
    HTML——部分MP4在谷歌浏览器上无法播放
    Node——用http-proxy 做反向代理服务器
    jQuery——操作复选框(checkbox) attr checked不起作用
    ionic2——开发利器之Visual Studio Code 常用插件整理
    ionic2——开发利器之Visual Studio Code 常用快捷键
    ionic2常见问题——修改应用图标及添加启动画面(官方命令行工具自动生成)
    ionic2常见问题——启动后白屏问题
    ionic2常见问题——解决下载gradle-2.14.1-all.zip太慢或失败
    ionic2常见问题——cordova使用Gradle构建下载maven太慢,使用阿里云镜像
  • 原文地址:https://www.cnblogs.com/fengzhiyuan/p/8487538.html
Copyright © 2011-2022 走看看