跳到正文

题解

题解:CF2096D Wonderful Lightbulbs

lailai0916约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟
获赞
1
题目
CF2096D

版本

  1. v1当前

原题链接

解题思路

注意到:每次操作让 xx 和 x+1x+1 两列,以及 x+yx+y 和 x+y+1x+y+1 两条斜线,各变动 22 个灯,奇偶性保持不变,而宝藏所在的列和斜线亮灯数为奇数。

在一组出现偶数次的数中找出出现奇数次的数,可用异或直接求出 ss 和 tt。

参考代码

C++
#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;
}
原文