Codeforces Round #697 (Div. 3) F. Unusual Matrix (思维,数学)


- 题意:给你一个矩阵\(a\)和\(b\),你可以对\(a\)的任意一行或任意一列的所有元素xor\(1\)任意次,问最终是否能够得到\(b\).
- 题解:由\(a\ xor\ b=c\),可得:\(a\ xor \ c=b\),根据线性代数的知识我们只需要判断\(c\)是否能由零矩阵通过上述变换得来即可.因为\(a\ xor\ c\)可以看成\(a\ xor \ 0(进行上述变换得到c)\).也就说明\(a\)可以通过上述变换得到\(b\),而\(c\)的判断,我们只需确定一行或者一列\(0\)后,b变换其他列或行判断即可.
- 代码:
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
#define rep(a,b,c) for(int a=b;a<=c;++a)
#define per(a,b,c) for(int a=b;a>=c;--a)
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
int _;
char a[1010][1010];
char b[1010][1010];
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>_;
while(_--){
int n;
cin>>n;
rep(i,1,n){
rep(j,1,n){
cin>>a[i][j];
}
}
rep(i,1,n){
rep(j,1,n){
cin>>b[i][j];
a[i][j]^=b[i][j];
}
}
rep(i,1,n){
if(a[i][1]==1){
rep(j,1,n) a[i][j]^=1;
}
}
rep(j,1,n){
if(a[1][j]==1){
rep(i,1,n) a[i][j]^=1;
}
}
bool flag=true;
rep(i,1,n){
rep(j,1,n){
if(a[i][j]==1){
flag=false;
break;
}
}
if(!flag) break;
}
if(flag) cout<<"YES\n";
else cout<<"NO\n";
}
return 0;
}
Codeforces Round #697 (Div. 3) F. Unusual Matrix (思维,数学)的更多相关文章
- Codeforces Round #531 (Div. 3) F. Elongated Matrix(状压DP)
F. Elongated Matrix 题目链接:https://codeforces.com/contest/1102/problem/F 题意: 给出一个n*m的矩阵,现在可以随意交换任意的两行, ...
- Codeforces Round #697 (Div. 3) G. Strange Beauty (DP,数学)
题意:给你一组数,问你最少删去多少数,使得剩下的数,每个数都能整除数组中其它某个数或被数组中其它某个数整除. 题解:我们直接枚举所有因子,\(dp[i]\)表示\(i\)在数组中所含的最大因子数(当我 ...
- Codeforces Round #485 (Div. 2) F. AND Graph
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...
- Codeforces Round #486 (Div. 3) F. Rain and Umbrellas
Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- Codeforces Round #501 (Div. 3) F. Bracket Substring
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...
- 二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix
题目传送门 /* 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 */ #include <cstdio> #include < ...
- Codeforces Round #499 (Div. 1) F. Tree
Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)
Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...
- Codeforces Round #622 (Div. 2) B. Different Rules(数学)
Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...
随机推荐
- 010_MySQL
目录 初识MySQL 为什么学习数据库 什么是数据库 数据库分类 MySQL简介 Windows安装MySQL 安装建议 软件下载 安装步骤 安装SQLyog 下载安装 连接数据库 简单操作 命令行连 ...
- 【Oracle】row_number() over(partition by )函数用法
row_number() OVER (PARTITION BY COL1 ORDER BY COL2) 表示根据COL1分组,在分组内部根据 COL2排序,而此函数计算的值就表示每组内部排序后的顺序编 ...
- postgresql中权限介绍
postgresql权限分为实例的权限,数据库的权限,模式的权限,对象的权限,表空间的权限 实例的权限:由pg_hba.conf文件控制,控制那些用户那些IP以哪种方式连接数据库 数据库的权限:是否允 ...
- python zxing包解析二维码报UnicodeDecodeError错误解决办法
一般错误的原因是这个库不支持中文的解码(二维码内容包含中文). 修改如下: 进入zxing.__init__.py代码中,类BarCode下,parse方法中: 找到下面这两行原代码如下: 1 raw ...
- Linux学习安装
Linux学习安装 服务器指的是网络中能对其他机器提供某些服务的计算机系统,相对普通PC, 服务器指的是高性能计算机,稳定性.安全性要求更高 linux安装学习 1.虚拟机 一台硬件的机器 安装vmw ...
- 如何封装Promise对象?
最近看到了一个有趣的Promise的方法,这里记录下来 <script> class MyPromise { constructor(executor) { // 初始化state赋值为p ...
- Scrapy——將數據保存到MySQL數據庫
Scrapy--將數據保存到MySQL數據庫 1. 在MySQL中創建數據庫表job_inf: 1 Create table job_inf( 2 id int(11) not null auto_i ...
- Vue基础之用插值表达式在视图区显示数据
Vue基础之用插值表达式在视图区显示数据 第一步:当然就是你要引入Vue.js这个脚本文件啦! <script src="https://cdn.jsdelivr.net/npm/vu ...
- Before you launch a goroutine, know when it will stop The Zen of Go
The Zen of Go https://the-zen-of-go.netlify.app/ Ten engineering values for writing simple, readable ...
- 7. A typical stream socket session
http://publibfp.dhe.ibm.com/epubs/pdf/f1a2d400.pdf Read and write data on socket s, using the send() ...