B. OR in Matrix
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output

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 mrows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one.

Sample test(s)
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 题意是一个矩阵B的b[i][j]是所有A矩阵的a[i][k]和a[k][j]或起来的值,给一个B矩阵,问是否存在这样的A矩阵,并输出方案
因为是或……所以在B中出现的0必须在A中一横一竖都为0
所以先把B中0的情况搞完,然后判一下现在的B矩阵中1的位置对应的A的一行一列是否存在至少一个1
15分钟……有些慢了,你看卓神6分钟A掉
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
int mat[110][110];
int a[110][110];
int n,m;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void ex()
{
printf("NO");
exit(0);
}
int main()
{
n=read();m=read();
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
mat[i][j]=1;
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
a[i][j]=read();
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
{
int x=a[i][j];
if (!x)
{
for (int k=1;k<=n;k++)
mat[k][j]=0;
for (int k=1;k<=m;k++)
mat[i][k]=0;
}
}
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
if(a[i][j])
{
bool mrk=0;
for (int k=1;k<=n;k++)if (mat[k][j])mrk=1;
for (int k=1;k<=m;k++)if (mat[i][k])mrk=1;
if (!mrk)ex();
}
printf("YES\n");
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
printf("%d ",mat[i][j]);
printf("\n");
}
}

  

cf486B OR in Matrix的更多相关文章

  1. CF486B OR in Matrix(构造+思维)

    CF486B 一道有趣的思维题 由于or的性质可知只要a[i][j]为1那么b中第i行,第j列将都变成1 相反的,如果b[i][j]是0那么a中第i行,第j列都必须是0 根据第二个性质我们可以构造出a ...

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

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

  3. 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 ...

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

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

  5. Android笔记——Matrix

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

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

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

  7. [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 ...

  8. [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 ...

  9. [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 ...

随机推荐

  1. 2015第22周六Java反射、泛型、容器简介

    Java的反射非常强大,传递class, 可以动态的生成该类.取得这个类的所有信息,包括里面的属性.方法以及构造函数等,甚至可以取得其父类或父接口里面的内容. obj.getClass().getDe ...

  2. VS2012 中使用Emacs布局

    微软的反开源行为导致它不断的衰落,问题是还不反省. 下面这篇文章介绍了如何安装emacs布局的插件: http://marxistprogrammer.blog.163.com/blog/static ...

  3. 【转】YUV格式&像素

    一幅彩色图像的基本要素是什么? 说白了,一幅图像包括的基本东西就是二进制数据,其容量大小实质即为二进制数据的多少.一幅1920x1080像素的YUV422的图像,大小是1920X1080X2=4147 ...

  4. PHP设计模式笔记三:三种基本设计模式(工厂模式、单例模式、注册树模式) -- Rango韩老师 http://www.imooc.com/learn/236

    一.工厂设计模式 index.php $db = IMooc\Factory::createDatabase(); 使用工厂类的静态方法直接创建一个dababase对象,当类名发生修改时,在工厂里修改 ...

  5. Could not load the Tomcat server configuration at /Servers/Tomcat v7.0 Server at localhost-config.

    [问题] Eclipse[Ubuntu14.04]中启动Tomcat Server[7.0.55]的时候出现错误例如以下: [解决方法] 1.将下边的Servers中的server[Tomcat v7 ...

  6. swift2.0 UIImagePickerController 拍照 相册 录像

    系统 ios9.1 语言swift2.0 在app 里最常用的功能就是多媒体选择,首先我们storyboard 创建一个button 用于触发选择事件 @IBAction func selectIma ...

  7. fopen(),fclose() 打开/关闭文件

    打开/关闭/刷新流 1. fopen() 打开流 功能: 1)fopen()打开由 path指定的一个文件. 2)fdopen()获取一个先有的文件描述符,并使一个标准的I/O流与该描述相结合.此函数 ...

  8. oracle 双机热备,oracle dataguard 和oracle rac的区别和联系(转)

    Data Guard 是Oracle的远程复制技术,它有物理和逻辑之分,但是总的来说,它需要在异地有一套独立的系统,这是两套硬件配置可以不同的系统,但是这两套系统的软件结构保持一致,包括软件的版本,目 ...

  9. Linux下的压缩和解压

    1. gzip, bzip2 能否直接压缩目录呢?不可以 2. 请快速写出,使用gzip和bzip2压缩和解压一个文件的命令.压缩:gzip 1.txt bzip2 1.txt解压:gzip -d 1 ...

  10. [MVC4-基礎] 連動DropDownList - 使用jQuery、JSON

    剛開始學MVC4,以下是一些基礎的學習筆記! 先展示一下結果: 1.選擇申請部門 2.選好後申請部門鎖住防止USER修改並載入該部門所擁有的設備類型 一.資料庫 dept mf_fx 二.View ( ...