Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
这道题涉及到NIM游戏的本质,详细请见之前的关于NIM和anti-NIM两种博弈游戏的博客
#include <cstdio> #include <iostream> using namespace std; int a[105]; int main () { int m, nimSum; while(scanf("%d", &m) != EOF && m) { nimSum = 0; for(int i=0; i<m; i++) { scanf("%d", &a[i]); nimSum ^= a[i]; } if(nimSum == 0) { printf("0\n"); } else { int temp = nimSum, k, cur=0; while(temp) { if(temp&1) k=cur; temp >>= 1; cur++; } int ans=0; for(int i=0; i<m; i++) { if((a[i]>>k) & 1) { ++ans; } } printf("%d\n", ans); } } return 0; }
HDU 1850 —— Being a Good Boy in Spring Festival
原文:http://www.cnblogs.com/AcIsFun/p/5372623.html