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. JS中基本的一些兼容问题 可能解释的不会太清楚

    做兼容注意: 一如果两个都是属性,用逻辑||做兼容 二如果有一个是方法 用三目运算符做兼容 三多个属性或方法封装函数做兼容 一:谷歌浏览器和火狐浏览器鼠标滚动条兼容 1.document.docume ...

  2. ②jquery复习

    # jQuery 复习--by 传智前端与移动开发学院 ## 1. jQuery是什么?(了解)+ www.github.com+ jQuery 其实就是一堆的js函数,是普通的js,只不过应用广泛, ...

  3. PyTorch教程之Tensors

    Tensors类似于numpy的ndarrays,但是可以在GPU上使用来加速计算. 一.Tensors的构建 from __future__ import print_function import ...

  4. 如何解决Python.h:No such file or directory

    安装python2.7对应的dev sudo apt-get install python-dev 安装python3.6对应的dev sudo apt-get install python3-dev

  5. Nginx学习——Nginx简单介绍和Linux环境下的安装

    一:Nginx的简介 百科百科:Nginx Nginx 是一个俄罗斯的哥们开发的,并将其进行了开源. Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器, ...

  6. java集合系列——Set之HashSet和TreeSet介绍(十)

    一.Set的简介 Set是一个不包含重复元素的 collection.更确切地讲,set 不包含满足 e1.equals(e2) 的元素.对 e1 和 e2,并且最多包含一个为 null 的元素. S ...

  7. class DELPHICLASS TObject

    class DELPHICLASS TObject    1.自己猜想:delphi,是windows平台的快速应用程序开发工具Rapid Application Development 简称RAD. ...

  8. VB.net DateTimePicker 初始化为空,选择后显示日期

    目的:当某记录的日期数据为空的时候,DateTimePicker 不以默认当前时间显示. 优点:避免不规则的时间格式输入:符合平时遇到的时间输入习惯 缺点:设置要代码,没有textbox控件那么方便设 ...

  9. Linux上mysql的安装与配置

    前言 在我们使用Linux的过程中,可能会使用到数据库.那么,数据库的安装与配置就是我们需要掌握的了~所以呢,这篇博客小编就来给大家唠唠数据库的安装与配置. 说到编译安装,小编脑海里浮现的第一个方法就 ...

  10. springboot使用zookeeper(curator)实现注册发现与负载均衡

    最简单的实现服务高可用的方法就是集群化,也就是分布式部署,但是分布式部署会带来一些问题.比如: 1.各个实例之间的协同(锁) 2.负载均衡 3.热删除 这里通过一个简单的实例来说明如何解决注册发现和负 ...