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. 强推一款开源集成开发环境——Geany

    本人是一个标标准准的程序员,集成开发环境在电脑上大概看一下有:Code Blocks(C/C++),VS(C#,C/C++),eclipse(Java),Hbuild和web storm(前端),py ...

  2. Overlapping rectangles判断两个矩形是否重叠的问题 C++

    Given two rectangles, find if the given two rectangles overlap or not. A rectangle is denoted by pro ...

  3. Thymeleaf引擎支持Multi Prefix

    最近团队的一个项目在重构,希望引入Thymeleaf减少页面端的代码复杂性.在重构过程中,发现html文件需要保存在多个不同的目录中,但Thymeleaf缺省的实现不支持这种方式. 1        ...

  4. js功能代码大全

    1.日期格式化 //化为2017-08-14 function formatDate (date) { var y = date.getFullYear(); var m = date.getMont ...

  5. lesson - 14 linux系统日常管理3

    1. Linux系统服务管理工具ntsysv 类似图形界面管理工具,如果没有该命令使用 yum install -y ntsysv 安装常用服务:crond, iptables, network, s ...

  6. dd 命令详解

    作用: dd 是一个Unix和类Unix系统中的命令, 主要功能为转换和赋值文件.在Unix和类Unix系统上, 硬件的设备驱动(如硬盘) 和特殊设备文件(如/dev/zero, /dev/rando ...

  7. 5.前端基于react,后端基于.net core2.0的开发之路(5) 配置node层,session设置、获取,请求拦截

    1.总结一下 今年,2月份从深圳来到广州,工作到现在,回头看,完成的项目4-5个,公司基本没有懂技术的领导,所以在技术选型上,我们非常的自由,所以内心一直都不满足现状,加上一起工作的小伙伴给力(哈哈哈 ...

  8. 学会C sharp计算机编程语言 轻松开发财务、统计软件

    就像人们用同一种语言才可以顺畅交流一样,语言是计算机编程的根本,是IT世界交流的工具.运用这些计算机语言,人们可以创造出一个美妙的世界.你点击某个网页或是安装一个应用程序软件,这简简单单动作的背后,就 ...

  9. bootstrap 导航栏鼠标悬停显示下拉菜单

    在jsp中加入一下代码: .navbar .nav > li:hover .dropdown-menu { display: block;} 全部代码如下所示: <%@ page lang ...

  10. SSH KEY 批量分发

    代码 #!/bin/sh . /etc/init.d/functions ];then echo "sh $0 arg0" exit fi for ip in 172.23.216 ...