题解 [ARC131C] Zero XOR

传送门

发现 \(n=1, 3\) 时先手必胜,尝试证明 \(n\) 为奇数时先手必胜
若存在一个数等于当前序列的异或和,则能一击必杀
否则若对手在这一步胜利当且仅当你们先后选的数 \(a, b\) 满足 \(a\oplus b=sum\)
因为有奇数个数,所以至少存在一个数不被包含在任何这样的数对里,选择一个这样的数可以归纳到 \(n-2\) 的情况
于是 \(n\) 为奇数时先手必胜

考虑 \(n\) 为偶数时
发现若不能一击必杀,则你选了一个数后对手会面临一个 \(n\) 为奇数的先手必胜局面,则你必败

点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define N 400010
#define ll long long
//#define int long long

char buf[1<<21], *p1=buf, *p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf, 1, 1<<21, stdin)), p1==p2?EOF:*p1++)
inline int read() {
	int ans=0, f=1; char c=getchar();
	while (!isdigit(c)) {if (c=='-') f=-f; c=getchar();}
	while (isdigit(c)) {ans=(ans<<3)+(ans<<1)+(c^48); c=getchar();}
	return ans*f;
}

int n;
int a[N], sum;

signed main()
{
	n=read();
	if (n&1) {puts("Win"); return 0;}
	for (int i=1; i<=n; ++i) a[i]=read(), sum^=a[i];
	for (int i=1; i<=n; ++i) if (a[i]==sum) {puts("Win"); return 0;}
	puts("Lose");
	
	return 0;
}
posted @ 2021-12-06 10:26  Administrator-09  阅读(5)  评论(0编辑  收藏  举报