Codeforces Round #277 (Div. 2) B. OR in Matrix 贪心
B. OR in Matrix
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/486/problem/B
Description
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 贪心的更多相关文章
- Codeforces Round #277 (Div. 2)---C. Palindrome Transformation (贪心)
Palindrome Transformation time limit per test 1 second memory limit per test 256 megabytes input sta ...
- 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 ...
- Codeforces Round #277 (Div. 2) 题解
Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...
- 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation
题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...
- 【codeforces】Codeforces Round #277 (Div. 2) 解读
门户:Codeforces Round #277 (Div. 2) 486A. Calculating Function 裸公式= = #include <cstdio> #include ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #277 (Div. 2) A. Calculating Function 水题
A. Calculating Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/4 ...
随机推荐
- 计算时间间隔的js
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- Delphi Unable to invoke Code Completion due to errors in source code
这时因为在.pas文件中存在delphi无法识别的编码,也就是说.pas文件中的字符并非是纯粹的可由文本文件编辑器所能识别的编码.所以,delphi就不可能有效地解释这些编码.因而就出现了自动代码提示 ...
- Please ensure that adb is correctly located at……问题解决方案
启动android模拟器时.有时会报The connection to adb is down, and a severe error has occured.的错误.在网友说在任务管理器上把所有ad ...
- 构造函数后面的base()
先执行父类的对应的构造函数,再执行当前的构造函数. 关于子类对象的构造函数和父类构造函数的执行顺序 以下内容转自:http://blog.csdn.net/todototry/article/deta ...
- POJ 1068 Parencodings
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24932 Accepted: 14695 De ...
- http://jingyan.baidu.com/article/4dc40848e7b69bc8d946f127.html
http://jingyan.baidu.com/article/4dc40848e7b69bc8d946f127.html
- LightOJ 1427 -Repository(ac自动机)
题意: 求每个模式串在母串中出现的次数 #include <map> #include <set> #include <list> #include <cma ...
- bzoj3884: 上帝与集合的正确用法 欧拉降幂公式
欧拉降幂公式:http://blog.csdn.net/acdreamers/article/details/8236942 糖教题解处:http://blog.csdn.net/skywalkert ...
- UVALive 5029
用字典树来查询,关键是怎么处理输入的8个数字代表的字符,把每个数分别除以0.95和1.05得到8的区间,按左区间从小到大排序,那么和第一个区间有交集的必然代表二进制0,与它没交集的之后都是1,因为题目 ...
- 如何将自定义RPM包加入YUM
1 前言 在很多时候进行编译了自己的RPM包,在搭建YUM的时候,希望将自定义的RPM加入到YUM源中,从而出现了下列方法. 2. 将RPM包加入YUM源 2.1 查看目前repodata位置 YUM ...