专栏文章
题解:CF2171C1 Renako Amaori and XOR Game (easy version)
CF2171C1题解参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @min1ea81
- 此快照首次捕获于
- 2025/12/01 18:59 3 个月前
- 此快照最后确认于
- 2025/12/01 18:59 3 个月前
思路:
考虑贪心,既然只有 和 ,那么有两种情况: 的总数为偶数个,异或后和为 ,若有奇数个 1 那么异或和为 。尽量让最终答案为 。那么只需要判断:轮到我操作时,若我手上的 的个数为偶数个,就看看能不能通过交换使个数增加 或减少 ,使我的和为 。
代码:
CPP#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 2e5 + 10;
int t,n,a[N],b[N];
void solve(){
cin >> n;
int cnt1 = 0,cnt2 = 0;
bool f1 = 0,f2 = 0;
for(int i = 1;i <= n;i ++){cin >> a[i];cnt1 += a[i];}
for(int i = 1;i <= n;i ++){cin >> b[i];cnt2 += b[i];}
for(int i = 1;i <= n;i ++){
if(a[i] == b[i])continue;
if(i % 2){
if(cnt1 % 2 == 0){
if(a[i] == 1 and b[i] == 0){
cnt1 --;
cnt2 ++;
}
if(a[i] == 0 and b[i] == 1){
cnt1 ++;
cnt2 --;
}
}
}else{
if(cnt2 % 2 == 0){
if(a[i] == 0 and b[i] == 1){
cnt1 --;
cnt2 ++;
}
if(a[i] == 1 and b[i] == 0){
cnt2 ++;
cnt1 --;
}
}
}
}
if((cnt1 % 2 == 0 and cnt2 % 2 == 0) or (cnt1 % 2 and cnt2 % 2))puts("Tie");
else if(cnt1 % 2 == 0)puts("Mai");
else if(cnt2 % 2 == 0)puts("Ajisai");
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> t;
while(t --){
solve();
}
return 0;
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...