CodeForces 486B
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.
Input
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).
Output
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 m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one.
Sample Input
2 2
1 0
0 0
NO
2 3
1 1 1
1 1 1
YES
1 1 1
1 1 1
2 3
0 1 0
1 1 1
YES
0 0 0
0 1 0
第一次看题目把a,b两个数组看反了,我觉得这道题还是挺好写的,反这写就好了,只要判断a数组当行列上有1的时候对应的b数组是否为1,首先要把a数组复制出来
b数组中为0是,a数组对应的行列都要为0;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int a[][];
int m,n;
void fun(int x,int y)
{
for(int i=;i<=m;i++)
a[i][y]=;
for(int j=;j<=n;j++)
a[x][j]=;
}
int main()
{
int x[],y[];
int b[][];
int i,j;
cin>>m>>n;
for(i=;i<=m;i++)
{
for(j=;j<=n;j++)
a[i][j]=;
}
memset(x,,sizeof(x));
memset(y,,sizeof(y));
for(i=;i<=m;i++)
{
for(j=;j<=n;j++)
{
cin>>b[i][j];
if(b[i][j]==)
fun(i,j);
}
}
/*for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}*/
for(i=;i<=m;i++)
{
for(j=;j<=n;j++)
{
if(a[i][j]==)
{
x[i]=;
y[j]=;
}
}
}
/*cout<<x[1]<<" "<<x[2]<<endl;
cout<<y[1]<<" "<<y[2]<<endl;*/
int flag=;
for(i=;i<=m;i++)
{
for(j=;j<=n;j++)
{
if(x[i]==||y[j]==)
{
if(b[i][j]==)
flag=;
else
{
cout<<"NO"<<endl;
return ;
}
}
else
{
if(b[i][j]==)
{
cout<<"NO"<<endl;
return ;
}
else
flag=;
}
}
}
if(flag==)
cout<<"YES"<<endl;
for(i=;i<=m;i++)
{
for(j=;j<n;j++)
cout<<a[i][j]<<" ";
cout<<a[i][n]<<endl;
}
return ;
}
CodeForces 486B的更多相关文章
- codeforces 486B.OR in Matrix 解题报告
题目链接:http://codeforces.com/problemset/problem/486/B 题目意思:给出一个m行n列的矩阵B(每个元素只由0/1组成),问是否可以利用矩阵B,通过一定的运 ...
- Codeforces 486B - OR in Matrix
矩阵的 OR ,也是醉了. 题目意思很简单,就是问你有没有这么一个矩阵,可以变化,得到输入的矩阵. 要求是这个矩阵每行都可以上下任意移动,每列都可以左右任意移动. 解题方法: 1.也是导致我WA 的原 ...
- 【codeforces】Codeforces Round #277 (Div. 2) 解读
门户:Codeforces Round #277 (Div. 2) 486A. Calculating Function 裸公式= = #include <cstdio> #include ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- dotnetnuke 中使用ado.net entityframework 如果在程序中动态调用系统的连接字符串信息
1,打开如下图的Model1.Context.cs文件 2,找到 Base:(ConnString.conn)是我改的.默认生成的是"name=实体连接字符串" Connstrin ...
- Oracle数据库基础知识总结(一)
数据库名.实例名.数据库域名.全局数据库名.服务名,这是几个令很多初学者容易混淆的概念.相信很多初学者都与我一样被标题上这些个概念搞得一头雾水. 我们现在就来把它们弄个明白. 一.数据库名 什么是数据 ...
- Polymorphism (computer science)
In programming languages and type theory, polymorphism (from Greek πολύς, polys, "many, much&qu ...
- trait 和abstract的区别在哪里
无法在一个class上extend多个abstract class,但是你可以use多个trait abstract class是在类型系统上做文章,trait片段是mixin 类型约束 代码复用 c ...
- phpStudy 升级 MySQL版本
1:停止phpStudy ,Mysql 服务;删除Mysql 文件夹 替换为新版本的Mysql 2:复制一份 my-default.ini,改名 my.ini ,打开,在最后面加上: basedir= ...
- ORACLE 查询不走索引的原因分析,解决办法通过强制索引或动态执行SQL语句提高查询速度
(一)索引失效的原因分析: <>或者单独的>,<,(有时会用到,有时不会) 有时间范围查询:oracle 时间条件值范围越大就不走索引 like "%_" ...
- Python 集合 day3
集合(set)是一个无序的不重复元素序列. 可以使用大括号 { } 或者 set() 函数创建集合,集合用{},里面是一个一个元素,不同于key-value形式的字典: 注意:创建一个空集合必须用 s ...
- eas快捷键
ctrl+shift+c 获取分录行的id ctrl+alt+[ 获取任意界面操作的信息
- 【数据结构】4.1图的创建及DFS深度遍历(不完善)
声明:本代码仅供参考,根本就不是正确代码(至少在我看来,有很多BUG和不完美的地方) 图的存储方式选择为邻接表,并且headNode只是来存储一个链表的Node首地址额 总之这个代码写的很垃圾呀很垃圾 ...
- 重新学习html和css
当初学习前端的时候,属于快速入门那种,没有好好深入学习html和css.如今,在空闲时间重新拿起基础书学习,都会写到一些新的知识. 1.css实现圆角.渐变功能.使用border-radius以及li ...