Sicily 1923. Is It Nim?

来源:互联网 发布:网络老虎机熊猫机器 编辑:程序博客网 时间:2024/05/17 08:28

1923. Is It Nim?

Constraints

Time Limit: 2 secs, Memory Limit: 32 MB

Description

  Alice and Bob play a new game again! There are N piles of stones. Each pile of stones may have different number of stones. They take turns to play, and Alice always play at the first turn.
  At each turn, the player of this turn must choose at least one and at most K piles of stones and take at least one stone away from each of them. Who take the last stone of the game will win.
  They both play optimally. But they want the game more interesting. So before the game start, Alice decide the number of stones in each pile, then Bob decide the number K.
  Now Alice has decided it, and Bob want to be the winner. How many integers can be chosen by Bob as K will lead to his winning of the game?

Input

  In the first line, there is one integer T(1<=T<=60).
  Then T test cases follow. In the first line of each test cases, there is one integer N(1<=N<=1000), the number of piles in the game. In the second line of each test case, there are N integers, a1, a2 ... an, the number of stones in each piles.(1<=ai<=10^9)

Output

  For each test case, output one line with only one integer, the number of integers that Bob can choose as K will lead to his winning of the game.

Sample Input

231 2 341 2 3 4

Sample Output

1

0

// Problem#: 1923// Submission#: 3279535// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include <stdio.h>#include <string.h>int main(){    int n,m,t,i,j,s[34];    scanf("%d",&n);    while(n--){        memset(s,0,sizeof(s));        scanf("%d",&m);  for(i=0;i<m;i++){   scanf("%d",&t);   j=0;         while(t!=0){    //化为二进制并将各位加到适当位置去             s[j]+=t%2;             t/=2;             j++;         }   }   t=m;  for(i=2;i<=m+1;i++)    //判断不同的i(即k)是否会导致Bob必胜  for(j=0;j<34;j++){   if(s[j]%i!=0){    t--;    break;   }  }        printf("%d\n",t);    }    return 0;}                                 


0 0
原创粉丝点击