B. OR in Matrix

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/486/problem/B

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

2 2
1 0
0 0

Sample Output

NO

HINT

题意

给你b矩阵,bij = ai1 | ai2 | ai3 ...... | aim | a1j | a2j ..... | anj

然后让你求a矩阵

题解:

找找规律就知道,如果bij是0,那么a矩阵中,第i行和第j行都是0

如果bij是1,那么a矩阵中,第i行或者第j行存在一个1就好了

代码

#include<stdio.h>
#include<iostream>
using namespace std;
int a[][];
int vis1[];
int vis2[];
int main()
{
int n,m;scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
scanf("%d",&a[i][j]);
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(a[i][j]==)
{
vis1[i]=;
vis2[j]=;
}
}
}
int sum1=;
for(int i=;i<=n;i++)
sum1+=vis1[i];
int sum2=;
for(int i=;i<=m;i++)
sum2+=vis2[i];
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(a[i][j]==)
{
if(sum1==n||sum2==m)
{
printf("NO\n");
return ;
}
if(vis1[i]&&vis2[j])
{
printf("NO\n");
return ;
}
}
}
}
printf("YES\n");
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(vis1[i]||vis2[j])
{
printf("0 ");
}
else
printf("1 ");
}
printf("\n");
}
}

Codeforces Round #277 (Div. 2) B. OR in Matrix 贪心的更多相关文章

  1. Codeforces Round #277 (Div. 2)---C. Palindrome Transformation (贪心)

    Palindrome Transformation time limit per test 1 second memory limit per test 256 megabytes input sta ...

  2. Codeforces Round #277 (Div. 2) B.OR in Matrix 模拟

    B. OR in Matrix   Let's define logical OR as an operation on two logical values (i. e. values that b ...

  3. Codeforces Round #277 (Div. 2) 题解

    Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...

  4. 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation

    题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...

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

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

  6. Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心

    Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  7. Codeforces Round #277 (Div. 2) E. LIS of Sequence DP

    E. LIS of Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/pr ...

  8. Codeforces Round #277 (Div. 2) D. Valid Sets 暴力

    D. Valid Sets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/problem ...

  9. Codeforces Round #277 (Div. 2) A. Calculating Function 水题

    A. Calculating Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/4 ...

随机推荐

  1. ejabberd、jabber、jabberd、xmpp辨析

    Jabber 是著名的即时通讯服务服务器,它是一个自由开源软件,能让用户自己架即时通讯服务器,可以在Internet上应用,也可以在局域网中应用.    XMPP(可扩展消息处理现场协议)是基于可扩展 ...

  2. Android之APK文件签名——keytool和jarsigner

    一.生成密钥库将位置定位在jdk的bin文件中,输入以下命名行:keytool -genkey -alias ChangeBackgroundWidget.keystore -keyalg RSA - ...

  3. git学习一

    一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己的电脑,所以 ...

  4. 【C++对象模型】函数返回C++对象的问题

    在深入C++对象模型中,对于形如 CObj obj1 = Get(obj2); 的形式,编译器会在将其改变为如下 Get(obj, CObj&  obj1); 将赋值操作符左边的变量作为函数的 ...

  5. SVM:从理论到OpenCV实践

    (转载请注明出处:http://blog.csdn.net/zhazhiqiang/ 未经允许请勿用于商业用途)   一.理论 参考网友的博客: (1)[理论]支持向量机1: Maximum Marg ...

  6. hadoop1.2.1三种模式配置

    1.本地模式 本地模式的安装 将hadoop 安装包解压后不用任何配置就是默认的本地模式 此时 core-site.xml ,hdfs-site.xml , marped.site.xml 三个配置文 ...

  7. LeetCode题解——String to Integer(atoi)

    题目: 字符串转换为数字. 解法: 这道题的意思是要考虑到,如果有前置的空字符,则跳过:如果超出数字范围,则返回最大/最小整数:如果碰到第一个不能转换的字符,则返回. 代码: class Soluti ...

  8. 在asp.net mvc中使用PartialView返回部分HTML段

    问题链接: MVC如何实现异步调用输出HTML页面 该问题是个常见的 case, 故写篇文章用于提示新人. 在asp.net mvc中返回View时使用的是ViewResult,它继承自ViewRes ...

  9. kobo boot scripts

    #!/bin/sh pkill nickel eink_enable_autoupdate rm -rf /debian/tmp/* /debian/tmp/.* 2>/dev/null mou ...

  10. Hadoop2.0新特性-持续追加【干货】

    1.NAME NODE HA 2.NAME NODE Federation 3.HDFS 快照(目录快照) 4.HDFS 缓存 5.HDFS ACL 6.异构层级存储结构 -------------- ...