# bzoj3105 [cqoi2013]新Nim游戏

6
5 5 6 6 5 5

21

## HINT

k<=100

 1 //It is made by wfj_2048~
2 #include <algorithm>
3 #include <iostream>
4 #include <complex>
5 #include <cstring>
6 #include <cstdlib>
7 #include <cstdio>
8 #include <vector>
9 #include <cmath>
10 #include <queue>
11 #include <stack>
12 #include <map>
13 #include <set>
14 #define inf (1<<30)
15 #define il inline
16 #define RG register
17 #define ll long long
18 #define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
19
20 using namespace std;
21
22 ll a[110],p[70],n,ans;
23
24 il int gi(){
25     RG int x=0,q=1; RG char ch=getchar(); while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
26     if (ch=='-') q=-1,ch=getchar(); while (ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar(); return q*x;
27 }
28
29 il int cmp(const ll &a,const ll &b){ return a>b; }
30
31 il int insert(RG ll x){
32     for (RG int i=62;i>=0;--i)
33     if (x>>i&1){
34         if (!p[i]){ p[i]=x; break; }
35         x^=p[i];
36     }
37     return x;
38 }
39
40 il void work(){
41     n=gi(); for (RG int i=1;i<=n;++i) a[i]=gi();
42     sort(a+1,a+n+1,cmp);
43     for (RG int i=1;i<=n;++i)
44     if (!insert(a[i])) ans+=a[i];
45     printf("%lld\n",ans); return;
46 }
47
48 int main(){
49     File("nim");
50     work();
51     return 0;
52 }

posted @ 2017-03-15 14:59  wfj_2048  阅读(131)  评论(0编辑  收藏  举报