OR in Matrix

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

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
/*
题意:定义一个异或,a1^a2...^an如果有一个ai=1那么值为1,否则为零,给出你一个矩阵B,是由矩阵A得来的,Bij等于A的i行元素
异或j列元素。给出你矩阵B问你是否有这样的矩阵A 初步思路:将矩阵初始化为1,然后先按照矩阵B中有零的元素,将对应A矩阵中的元素设置成零,然后在反过来验证B矩阵
*/
#include <bits/stdc++.h>
using namespace std;
int n,m;
int a[][];
int b[][];
int main(){
// freopen("in.txt","r",stdin);
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
scanf("%d",&b[i][j]);
a[i][j]=;
}
}
//按照B矩阵进行置0
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(b[i][j]==){
for(int k=;k<=m;k++)
a[i][k]=;
for(int k=;k<=n;k++)
a[k][j]=;
}
}
}
//验证然后按照1的位置验证B矩阵
bool f=false;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(b[i][j]==){
bool flag=false;
for(int k=;k<=n;k++){
if(a[i][k]==){
flag=true;
break;
}
}
if(flag==false)
for(int k=;k<=m;k++){
if(a[k][j]==){
flag=true;
break;
}
}
if(flag==false){
f=true;
break;
}
}
}
}
if(f){
puts("NO");
}else{
puts("YES");
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
printf(j==?"%d":" %d",a[i][j]);
}
printf("\n");
}
}
return ;
}

OR in Matrix的更多相关文章

  1. angular2系列教程(十一)路由嵌套、路由生命周期、matrix URL notation

    今天我们要讲的是ng2的路由的第二部分,包括路由嵌套.路由生命周期等知识点. 例子 例子仍然是上节课的例子:

  2. Pramp mock interview (4th practice): Matrix Spiral Print

    March 16, 2016 Problem statement:Given a 2D array (matrix) named M, print all items of M in a spiral ...

  3. Atitit Data Matrix dm码的原理与特点

    Atitit Data Matrix dm码的原理与特点 Datamatrix原名Datacode,由美国国际资料公司(International Data Matrix, 简称ID Matrix)于 ...

  4. Android笔记——Matrix

    转自:http://www.cnblogs.com/qiengo/archive/2012/06/30/2570874.html#translate Matrix的数学原理 在Android中,如果你 ...

  5. 通过Matrix进行二维图形仿射变换

    Affine Transformation是一种二维坐标到二维坐标之间的线性变换,保持二维图形的"平直性"和"平行性".仿射变换可以通过一系列的原子变换的复合来 ...

  6. [LeetCode] Kth Smallest Element in a Sorted Matrix 有序矩阵中第K小的元素

    Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth ...

  7. [LeetCode] Longest Increasing Path in a Matrix 矩阵中的最长递增路径

    Given an integer matrix, find the length of the longest increasing path. From each cell, you can eit ...

  8. [LeetCode] Search a 2D Matrix II 搜索一个二维矩阵之二

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  9. [LeetCode] Search a 2D Matrix 搜索一个二维矩阵

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  10. [LeetCode] Set Matrix Zeroes 矩阵赋零

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click ...

随机推荐

  1. vim与sublime,程序员的屠龙刀和倚天剑

    对程序员来说,写代码是再熟悉不过的事情了,windows系统自带有记事本软件,能写写小规模的代码,可是代码量大了,它的局限性就暴露得很明显了:没有语法高亮,没有自动提示,不支持项目管理,界面难看-- ...

  2. java中集合的增删改操作及遍历总结

      集合的增删改操作及遍历总结

  3. 我的第一个python web开发框架(4)——数据库结构设计与创建

    小白做好前端html设计后,马上开始进入数据库结构设计步骤. 在开始之前,小白回忆了一下老大在公司里培训时讲过的数据库设计解说: 对于初学者来说,很多拿到原型时不知道怎么设计数据表结构,这是很正常的事 ...

  4. 【框架学习与探究之消息队列--EasyNetQ(1)】

    前言 本文欢迎转载,实属原创,本文原始链接地址:http://www.cnblogs.com/DjlNet/p/7603554.html 废话 既然都是废话了,所以大家就可以跳过了,这里是博主有事没事 ...

  5. elasticsearch单例模式连接

    import java.net.InetAddress;import org.elasticsearch.client.transport.TransportClient;import org.ela ...

  6. Java 多态、内部类、异常、包

    一.多态 1. 概述 理解:多态可以理解为事物存在的多种体(表)现形态. 例如: 动物中的猫和狗. 猫这个对象对应的是猫类型,例如:猫 x = new 猫(); 同时猫也是动物中的一种,也可以把猫称为 ...

  7. nodejs项目管理之supervisor||pm2||forever

    supervisor 是开发环境用. forever 管理多个站点,每个站访问量不大,不需要监控. pm2 网站访问量比较大,需要完整的监控界面. supervisor 特点: 代码修改,实时重启 安 ...

  8. mb_substr函数

    定义和用法 mb_substr() 截取字符串中指定长度字符 注:常用于中文截取,可以避免截取时候出现乱码,即截取半个字符的情况. 类似函数 substr(),iconv_substr() 语法 mb ...

  9. zabbix自动截图留档_python版

    1 背景     每个DB Server都有zabbix监控,除了异常情况的报警信息外,也会在日检.周检.月检等工作中用到zabbix的监控数据,对zabbix监控数据会做两种处理:1 数据分析(环比 ...

  10. 【NOIP模拟】LCS及方案数(DP)

    Description 对于一个序列