Uva1482:playing with stones (SG)

Source: Internet
Author: User

Description

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

Input

The first line of input contains an integer t(t) denoting the number of testcases. Each testcase begins with an integer n(1N) the number of piles. The next line contains n integers a1, a2, a3,..., an (1ai2 * 1018) The number of stones in each pile.

Output

For each testcase, the 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
Make a chart to find the pattern of the SG table
#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;}


Uva1482:playing with stones (SG)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.