栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

cf1628 C. Grid Xor

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

cf1628 C. Grid Xor

Note: The XOR-sum of set {s1,s2,…,sm} is defined as s1⊕s2⊕…⊕sm, where ⊕ denotes the bitwise XOR operation.
After almost winning IOI, Victor bought himself an n×n grid containing integers in each cell. n is an even integer. The integer in the cell in the i-th row and j-th column is ai,j.
Sadly, Mihai stole the grid from Victor and told him he would return it with only one condition: Victor has to tell Mihai the XOR-sum of all the integers in the whole grid.
Victor doesn’t remember all the elements of the grid, but he remembers some information about it: For each cell, Victor remembers the XOR-sum of all its neighboring cells.
Two cells are considered neighbors if they share an edge — in other words, for some integers 1≤i,j,k,l≤n, the cell in the i-th row and j-th column is a neighbor of the cell in the k-th row and l-th column if |i−k|=1 and j=l, or if i=k and |j−l|=1.
To get his grid back, Victor is asking you for your help. Can you use the information Victor remembers to find the XOR-sum of the whole grid?
It can be proven that the answer is unique.

把取每个格子的贡献看做给它四面八方的格子染色(0,1染色,0染成1,1染成0),目标是把所有格子染成1。
从第二行开始,按顺序遍历。
对于每一个方格(i,j),如果它的上一个方格没有被染色,那么只能通过计算这个方格的贡献来对其染色。

#include
using namespace std;

#define maxn ((int)1e3)

int a[maxn+5][maxn+5],g[maxn+5][maxn+5];

int main() {
	
	int T;
	cin>>T;
	while(T--) {
		int n;
		cin>>n;
		for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>a[i][j];
		for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) g[i][j]=0;
		
		int ans=0;
		
		for(int i=2;i<=n;i++) {
			for(int j=1;j<=n;j++) {
				if(g[i-1][j]==0) {
					g[i-1][j]^=1,g[i+1][j]^=1,g[i][j-1]^=1,g[i][j+1]^=1;
					ans=ans^a[i][j];
				}
			}
		}
		
		cout<
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/715234.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号