题解:CF2096D Wonderful Lightbulbs
· One min read
原题链接
解题思路
注意到:每次操作让 和 两列,以及 和 两条斜线,各变动 个灯,奇偶性保持不变,而宝藏所在的列和斜线亮灯数为奇数。
在一组出现偶数次的数中找出出现奇数次的数,可用异或直接求出 和 。
参考代码
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
ll a=0,b=0;
while(n--)
{
ll x,y;
cin>>x>>y;
a^=x;b^=x+y;
}
cout<<a<<' '<<b-a<<'\n';
}
return 0;
}