题目链接:http://poj.org/problem?id=2975
Nim游戏。代码如下:
1 #include <iostream> 2 #include <math.h> 3 #include <stdio.h> 4 #include <cstdio> 5 #include <algorithm> 6 #include <string.h> 7 #include <string> 8 #include <sstream> 9 #include <cstring> 10 #include <queue> 11 #include <vector> 12 #include <functional> 13 #include <cmath> 14 #include <set> 15 #define SCF(a) scanf("%d", &a) 16 #define IN(a) cin>>a 17 #define FOR(i, a, b) for(int i=a;i<b;i++) 18 #define Infinity 999999999 19 #define NInfinity -999999999 20 #define PI 3.14159265358979323846 21 #define MAXN 1000000005 22 #define RATIO (sqrt(5.0)+1.0)/2.0 23 typedef long long Int; 24 using namespace std; 25 26 int main() 27 { 28 int n; 29 while (SCF(n)) 30 { 31 if (!n) 32 break; 33 int *nums = new int[n]; 34 int cstate = 0; 35 FOR(i, 0, n) 36 { 37 SCF(nums[i]); 38 cstate = cstate^nums[i]; 39 } 40 int fans = 0; 41 FOR(i, 0, n) 42 { 43 if ((cstate ^ nums[i]) < nums[i]) 44 { 45 fans++; 46 } 47 } 48 printf("%d\n", fans); 49 50 } 51 return 0; 52 }