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)