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

Input
2 2
1 0
0 0
Output
NO
Input
2 3
1 1 1
1 1 1
Output
YES
1 1 1
1 1 1
Input
2 3
0 1 0
1 1 1
Output
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的更多相关文章

  1. codeforces 486B.OR in Matrix 解题报告

    题目链接:http://codeforces.com/problemset/problem/486/B 题目意思:给出一个m行n列的矩阵B(每个元素只由0/1组成),问是否可以利用矩阵B,通过一定的运 ...

  2. Codeforces 486B - OR in Matrix

    矩阵的 OR ,也是醉了. 题目意思很简单,就是问你有没有这么一个矩阵,可以变化,得到输入的矩阵. 要求是这个矩阵每行都可以上下任意移动,每列都可以左右任意移动. 解题方法: 1.也是导致我WA 的原 ...

  3. 【codeforces】Codeforces Round #277 (Div. 2) 解读

    门户:Codeforces Round #277 (Div. 2) 486A. Calculating Function 裸公式= = #include <cstdio> #include ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. Struts2 在拦截器中向Action传参

    struts.xml配置文件: <package name="system-default" extends="struts-default" abstr ...

  2. 在命令提示符窗口下(cmd)使用指令操作并编译java代码,运行java编译代码

    使用cmd操作java代码,编译.java文件,运行.class文件. 操作步骤: 1:创建一个文件夹: 例如:在e盘根目录(\)下面创建一个名为Hello的文件夹: 使用md指令:如图 在e盘中会生 ...

  3. 彻底去除Google AdMob广告

    应用中包含广告是能够理解的,但经常造成用户误点,或者广告切换时造成下载流量,就有点让人不舒服了. 以下就以Google AdMob广告为例,看怎样彻底去除他. 先分析一下Google AdMob的工作 ...

  4. Java:Java 队列的遍历

    Java队列到底有没有可以遍历的功能呢?暂且试一下吧 参考链接:stl容器遍历测试 1.LinkedList实现简单遍历 for(Iter =LocTimesSerials.size()-1; iSe ...

  5. 《计算机图形学基础(OpenGL版)》勘误表

    第1版第1次印刷: 所在页码 所在行 原内容 更正为 41 16 k=Δx/Δy k=Δy/Δx 46 6 s-t=2Δy/Δx(xi+1)+2b+2yi-1 s-t=2Δy/Δx(xi+1)+2b- ...

  6. SQL 分组

  7. Java+selenium+Firefox/ IE/ Chrome主流浏览器自动化环境搭建

    一.java+selenium+firefox 1.环境准备:JDK1.8 2.安装firefox浏览器v59 3.下载驱动:https://github.com/mozilla/geckodrive ...

  8. console.log、toString方法与js判断变量类型

    Java调用system.print.out()是会调用toString方法打印js里的console.log也是控制台打印,很多时候,我们以为也是调用toString方法,其实并不是.我们在chro ...

  9. 去掉二级页面 tabs 菜单, 修改返回按钮

    imports: [ /*引入的模块 依赖的模块*/ BrowserModule, ComponentsModule, IonicModule.forRoot(MyApp,{ tabsHideOnSu ...

  10. vue,基础整理,夯实基础,为进阶打基础

    把基础部分,再次系统的了解一遍,整理成文档.