# Sicily 1922. Winning Ways

a1⊕a2⊕a3⊕…⊕aN=0。
a1⊕a2⊕a3⊕…⊕aN一般称为Nim-sum

http://web.mit.edu/sp.268/www/nim.pdf

s=x1⊕x2⊕x3⊕…⊕xn；

t=y1⊕y2⊕y3⊕…⊕yn；

t = 0 ⊕ t
= s ⊕ s ⊕ t
= s ⊕ (x1 ⊕ x2 ⊕ … ⊕ xn) ⊕ (y1 ⊕ y2 ⊕ … ⊕ yn)
= s ⊕ (x1 ⊕ y1) ⊕ (x2 ⊕ y2) ⊕ … ⊕ (xk ⊕ yk)
= s ⊕ xk ⊕ yk

xk= 101010，

= s ⊕ xk ⊕ xk ⊕ s
= s ⊕ s ⊕ xk ⊕ xk
= 0

#include <stdio.h>

int main() {

int CaseNum;
scanf("%d\n", &CaseNum);

while (CaseNum--) {

int N, Sum = 0, Stones[50005], k = 0, XorSum = 0;
scanf("%d\n", &N);
char C[600000];
gets(C);

// Use the gets() function to read a line with lots of datas is fast than scanf()
for (int i = 0; C[i] != '\0'; i++) {
if (C[i] == ' ') {
Stones[k++] = Sum;
Sum = 0;
} else {
Sum = Sum * 10 + C[i] - '0';
}
}
Stones[k] = Sum;

for (int i = 0; i < N; i++) XorSum ^= Stones[i];
if (XorSum == 0) printf("0\n");
else {
int Ways = 0;
for (int i = 0; i < N; i++) if ((XorSum ^ Stones[i]) <= Stones[i]) Ways++;
printf("%d\n", Ways);
}

}

return 0;
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120