Codeforces Round #277 (Div. 2) B.OR in Matrix 模拟
Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner:
where
is equal to 1 if some ai = 1, otherwise it is equal to 0.
Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:
.
(Bij is OR of all elements in row i and column j of matrix A)
Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large.
The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively.
The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1).
In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print mrows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one.
2 2
1 0
0 0
NO
//
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define meminf(a) memset(a,127,sizeof(a)); inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){
if(ch=='-')f=-;ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';ch=getchar();
}return x*f;
}
//****************************************
#define maxn 1000+5
#define mod 1000000007 int c[maxn][maxn],b[maxn][maxn],a[maxn][maxn];
int main(){ int n=read();
int m=read();
memset(b,-,sizeof(b));
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
scanf("%d",&a[i][j]);
}
}
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(a[i][j]==){
for(int k=;k<=m;k++){
b[i][k]=;
}
for(int k=;k<=n;k++){
b[k][j]=;
}
}
}
}
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(b[i][j]==-)b[i][j]=;
}
}
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
int aa=;
for(int k=;k<=m;k++){
aa|=b[i][k];
}
for(int k=;k<=n;k++){
aa|=b[k][j];
}
c[i][j]=aa;
}
}bool flag=;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(c[i][j]!=a[i][j])flag=;
}
}
if(!flag){
cout<<"YES"<<endl;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
cout<<b[i][j]<<" ";
}
cout<<endl;
}
}
else cout<<"NO"<<endl;
return ;
}
代码
Codeforces Round #277 (Div. 2) B.OR in Matrix 模拟的更多相关文章
- Codeforces Round #277 (Div. 2) B. OR in Matrix 贪心
B. OR in Matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/probl ...
- Codeforces Round #277 (Div. 2) A B C 水 模拟 贪心
A. Calculating Function time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces Round #277 (Div. 2) 题解
Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...
- 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation
题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...
- 【codeforces】Codeforces Round #277 (Div. 2) 解读
门户:Codeforces Round #277 (Div. 2) 486A. Calculating Function 裸公式= = #include <cstdio> #include ...
- Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
- Codeforces Round #277 (Div. 2) E. LIS of Sequence DP
E. LIS of Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/pr ...
- Codeforces Round #277 (Div. 2) D. Valid Sets 暴力
D. Valid Sets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/problem ...
- Codeforces Round #277 (Div. 2) A. Calculating Function 水题
A. Calculating Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/4 ...
随机推荐
- 软件架构自学笔记-- 转载“虎牙在全球 DNS 秒级生效上的实践”
虎牙在全球 DNS 秒级生效上的实践 这次分享的是全球 DNS 秒级生效在虎牙的实践,以及由此产生的一些思考,整体上,分为以下 5 各部分: 背景介绍: 方案设计和对比: 高可用: 具体实践和落地: ...
- python--9、并发之多进程应用
multiprocessing模块 想要充分地使用多核CPU的资源(os.cpu_count()查看),在python中大部分情况需要使用多进程.Python提供了multiprocessing. ...
- RTL Compiler之synthesis flow
1 generic RTL Compiler work flow 2 invoking RTL compiler RTL Compiler is invoked from the operating ...
- Java_Web三大框架之Hibernate+jsp+selvect+HQL注册用户
Hibernate比SQL语句简单多了,代码冗余少,切方便简洁明了.下面用Hibernate+jsp+selvect+HQL来实现注册用户. 第一步:编写用户实体类和Users2.hbm.xml映射. ...
- 使用super实现类的继承
查看一个类继承了哪些类可以用__bases__方法查看 class People: def __init__(self,name,age,sex): self.name=name self.ag ...
- CAD保存DWG文件,设置保存的文件版本号和密码
主要用到函数说明: MxDrawXCustomFunction::Mx_SaveDwgEx 保存DWG文件,可以设置保存的文件版本号和密码,详细说明如下: 参数 说明 IN CString sFile ...
- 在Excel表格中打字为何会被覆盖掉
修改证件图片背景:https://www.cnblogs.com/liyanbin/p/9466746.html Insert键是插入和改写(覆盖)的开关如果当前处于改写(覆盖)模式,再按一下Inse ...
- 3.3.4 lambda 表达式
lambda表达式常用来声明匿名函数,即没有函数名字的临时使用的小函数,例如第2章中列表对象的sort()方法以及内置函数sorted()中key参数.lambda表达式只可以包含一个表达式,不允许包 ...
- 00107_TCP通信
1.TCP通信的概述 (1)TCP通信同UDP通信一样,都能实现两台计算机之间的通信,通信的两端都需要创建socket对象: (2)区别在于: ①UDP中只有发送端和接收端,不区分客户端与服务器端,计 ...
- CodeForcesGym 100735B Retrospective Sequence
Retrospective Sequence Time Limit: Unknown ms Memory Limit: 65536KB This problem will be judged on C ...