这题就贪心啊
根据Nim游戏的规则,作为一个先手,我们留给对方的东西,一定不可以有一个组合,使得他们的异或值为0
知道了这个就很好办了,我们想排序,接着对于每一堆,要是他可以通过之前已有的基异或出来,那么我们肯定要把它拿掉。
最后统计一下答案就好了。
然后这题肯定是没有-1的情况的,至少有一个必胜策略:
假设现在有n堆
作为先手,我们直接拿n-1堆,剩下一堆
根据规则,前两回合不能拿完,于是对手挂机
我们就赢了。。
不知道是谁设计的这么智障的游戏规则
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const LL N=105;
LL k;
LL g[N];
LL a[N];
bool ins (LL x)
{
for (LL u=62;u>=0;u--)
if (x>>u&1)
{
if (g[u]==0) {g[u]=x;return true;}
x=x^g[u];
}
return false;
}
int main()
{
memset(g,0,sizeof(g));
scanf("%lld",&k);
for (LL u=1;u<=k;u++) scanf("%lld",&a[u]);
sort(a+1,a+1+k);
LL ans=0;
for (LL u=k;u>=1;u--)
if (ins(a[u])==false)
ans=ans+a[u];
printf("%lld\n",ans);
return 0;
}