UVA1482:Playing With Stones(SG)

来源:互联网 发布:懒懒淘宝客助手官网 编辑:程序博客网 时间:2024/04/16 21:51

Description

Download as PDF

You and your friend are playing a game in which you and your friend take turns removing stones from piles. Initially there are N piles witha1a2a3,..., aN number of stones. On each turn, a player must remove at least one stone from one pile but no more than half of the number of stones in that pile. The player who cannot make any moves is considered lost. For example, if there are three piles with 5, 1 and 2 stones, then the player can take 1 or 2 stones from first pile, no stone from second pile, and only 1 stone from third pile. Note that the player cannot take any stones from the second pile as 1 is more than half of 1 (the size of that pile). Assume that you and your friend play optimally and you play first, determine whether you have a winning move. You are said to have a winning move if after making that move, you can eventually win no matter what your friend does.

Input

The first line of input contains an integer T(T$ \le$100) denoting the number of testcases. Each testcase begins with an integer N(1$ \le$N$ \le$100) the number of piles. The next line contains N integers a1a2a3,..., aN(1$ \le$ai$ \le$* 1018) the number of stones in each pile.

Output

For each testcase, print ``YES" (without quote) if you have a winning move, or ``NO" (without quote) if you don‟t have a winning move.

Sample Input

4 2 4 4 3 1 2 33 2 4 63 1 2 1

Sample Output

NO YES NO YES
打表找规律得出SG表
#include <iostream>#include <stdio.h>#include <string.h>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <math.h>#include <bitset>#include <algorithm>#include <climits>using namespace std;#define LS 2*i#define RS 2*i+1#define UP(i,x,y) for(i=x;i<=y;i++)#define DOWN(i,x,y) for(i=x;i>=y;i--)#define MEM(a,x) memset(a,x,sizeof(a))#define W(a) while(a)#define gcd(a,b) __gcd(a,b)#define LL long long#define N 1000005#define MOD 1000000007#define INF 0x3f3f3f3f#define EXP 1e-8LL SG(LL x){    if(x&1)        return SG(x/2);    return x/2;}int main(){    int n,t,i,j;    LL a,ans;    scanf("%d",&t);    while(t--)    {        ans = 0;        scanf("%d",&n);        for(i = 0; i<n; i++)        {            scanf("%lld",&a);            ans^=SG(a);        }        if(ans) printf("YES\n");        else printf("NO\n");    }    return 0;}


0 0
原创粉丝点击