Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones Nim游戏

E. Game of Stones

链接:

http://codeforces.com/contest/768/problem/E

题解:

状态数为 n(n+1)/2 <=x 的最大x,之后就进行异或和即可。

代码 :

 1 #include <map>
 2 #include <set>
 3 #include <cmath>
 4 #include <queue>
 5 #include <stack>
 6 #include <cstdio>
 7 #include <string>
 8 #include <vector>
 9 #include <cstring>
10 #include <iostream>
11 #include <algorithm>
12 #include <functional>
13 using namespace std;
14 #define rep(i,a,n) for (int i=a;i<=n;i++)
15 #define per(i,a,n) for (int i=n;i>=a;i--)
16 #define pb push_back
17 #define mp make_pair
18 #define all(x) (x).begin(),(x).end()
19 #define fi first
20 #define se second
21 #define SZ(x) ((int)(x).size())
22 typedef vector<int> VI;
23 typedef long long ll;
24 typedef pair<int, int> PII;
25 const ll mod = 1000000007;
26 // head
27 
28 int n, a[66];
29 int main()
30 {
31     int st = 0, an = 0;
32     a[0] = 0;
33     rep(i, 1, 10) rep(j, 1, i + 1) a[++st] = i;
34     scanf("%d", &n);
35     while (n--){
36         scanf("%d", &st);
37         an ^= a[st];
38     }
39     if (an == 0) printf("YES
");
40     else printf("NO
");
41     return 0;
42 }
原文地址:https://www.cnblogs.com/baocong/p/6428000.html