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
m rows 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

wa了几发才过、
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdlib>
using namespace std; int a[110][110], b[110][110]; int main() {
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
int m, n;
cin >> m>> n;
for (int i = 0; i<m; i++) {
for (int j = 0; j<n; j++) {
cin >> a[i][j];
b[i][j] = 1;
}
}
if (m == n && m == 1) {
cout << "YES" << endl;
cout << a[0][0] << endl;
return 0;
}
int flag1 = 0, flag2 = 0, flag3 = 0, flag4 = 1;
for (int i = 0; i<m; i++) {
for (int j = 0; j<n; j++) {
if (a[i][j] == 1) {
flag4 = 0;
flag1 = 0, flag2 = 0;
for (int k = 0; k<n; k++) {
if (a[i][k] != 1)
flag1 ++ ;
}
for (int k = 0; k<m; k++) {
if (a[k][j] != 1)
flag2 ++ ;
}
if (flag1 == 0 && flag2 == 0)
flag3 ++ ;
else if (flag1>0 && flag2>0) {
cout << "NO"<< endl;
return 0;
}
}
}
}
if (flag4 == 1) {
cout << "YES" << endl;
for (int i = 0; i<m; i++) {
for (int j = 0; j<n-1; j++) {
cout << a[i][j] << " ";
}
cout << a[i][n-1] << endl;
}
cout << endl;
return 0;
}
if (flag3 > 0) {
cout << "YES"<< endl;
for (int i = 0; i<m; i++) {
for (int j = 0; j<n; j++) {
if (a[i][j] == 0) {
for (int k = 0; k<n; k++)
b[i][k] = 0;
for (int k = 0; k<m; k++)
b[k][j] = 0;
}
}
}
for (int i = 0; i<m; i++) {
for (int j = 0; j<n-1; j++) {
cout << b[i][j] << " ";
}
cout << b[i][n-1] << endl;
}
cout << endl;
}
else {
cout << "NO" << endl;
} return 0;
}

B. 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. [置顶] Xamarin android如何调用百度地图入门示例(一)

    在Xamarin android如何调用百度地图呢? 首先我们要区分清楚,百度地图这是一个广泛的概念,很多刚刚接触这个名词"百度地图api",的确是泛泛而谈,我们来看一下百度地图的 ...

  2. ArcGIS API for JavaScript 4.2学习笔记[17] 官方第七章Searching(空间查询)概览与解释

    空间分析和空间查询是WebGIS有别于其他Web平台的特点.到这一章,就开始步入空间分析的内容了. [Search widget] 介绍空间查询的核心小部件"Search". [S ...

  3. .net 连接SqlServer数据库及基本增删改查

    一.写在前面 因为这学期选修的 .net 课程就要上机考试了,所以总结下.net 操作 SqlServer 数据的方法.(因为本人方向是 Java,所以对.net 的了解不多,但以下所写代码均是经过测 ...

  4. Docker(十一):Docker实战部署HTTPS的Tomcat站点

    1.选择基础镜像  docker pull tomcat:7.0-jre8 2.生成HTTPS证书 keytool -genkey -alias tomcat -keyalg RSA -keystor ...

  5. 从底层角度看ASP.NET-A low-level Look at the ASP.NET...

    从更低的角度 这篇文章在一个底层的角度来关注一个web请求怎样到达asp.net框架,从web服务器,通过ISAPI.看看这些后面发生了什么,让我们停止对asp.net的黑箱猜想.ASP.NET是一个 ...

  6. python 小脚本升级-- 钉钉群聊天机器人

    一则小脚本(工作中用) 在这篇文章中写的监控的脚本,发送监控的时候 是利用的邮箱,其实在实际,邮箱查收有着不方便性,于是乎升级, 我们工作中,经常用钉钉,那么如果要是能用到钉钉多好,这样我们的监控成功 ...

  7. unity创建和加载AssetBundle

    先说一下为什么要使用AssetBundle吧,以前做东西一直忽略这个问题,现在认为这个步骤很重要,代码是次要的,决策和为什么这样搞才是关键. 一句话概括吧,AssetBundle实现了资源与服务分离, ...

  8. 滚动条大于120px时,判断pc端的情况下,导航条固定定位

      //滚动条大于120px时,判断pc端的情况下,导航条固定定位 $(window).scroll(function(){ var viewWidth=$(document).width() var ...

  9. C语言中static关键字的用法

    C记得还是大一时学的,现在觉得好久没用了,又捧起来看看.今天刚看到有关static关键字,仔细地看了一遍<C和指针>这本书中的解释,现在觉得清楚多了. 首先,我们将static关键字,修饰 ...

  10. 安装spark单机环境

    (假定已经装好的hadoop,不管你装没装好,反正我是装好了) 1 下载spark安装包 http://spark.apache.org/downloads.html 下载spark-1.6.1-bi ...