专栏文章
[ARC208A] Bitwise OR Game 题解
AT_arc208_a题解参与者 2已保存评论 1
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @minl1icy
- 此快照首次捕获于
- 2025/12/02 04:09 3 个月前
- 此快照最后确认于
- 2025/12/02 04:09 3 个月前
我们回想起学过的 Nim 游戏。
一般的 Nim 游戏就是先手不断让一个数 变成另一个数 ,使得接下来的 个数的异或和为 ,而后手一定要选数使得异或和不为 ,这样先手必然会取光,后手输。
我们把它带入这道题做一下。我们发现,每一位必然需要留下一个 。那么我们把这些 扣掉,就又变成了普通的 Nim 游戏。所以,如果按位或和等于异或和,先手必败;否则,先手必胜。证明可以感性参考一般 Nim 游戏的证明。
代码很短。好像这一场 ARC 前三题都很短?
CPP#include<bits/stdc++.h>
#define int long long
using namespace std;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
const int N=1000010;
int n;
int a[N];
void solve(){
cin>>n;
int x=0,y=0;
for(int i=1;i<=n;i++){
cin>>a[i];
x|=a[i];
y^=a[i];
}
if((x^y)==0)cout<<"Bob\n";//x^y==0 就是 x==y
else cout<<"Alice\n";
return;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int Tc=1;
cin>>Tc;
while(Tc--)solve();
return 0;
}
/*
*/
相关推荐
评论
共 1 条评论,欢迎与作者交流。
正在加载评论...