CodeForces 486B
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
NO
2 3
1 1 1
1 1 1
YES
1 1 1
1 1 1
2 3
0 1 0
1 1 1
YES
0 0 0
0 1 0
第一次看题目把a,b两个数组看反了,我觉得这道题还是挺好写的,反这写就好了,只要判断a数组当行列上有1的时候对应的b数组是否为1,首先要把a数组复制出来
b数组中为0是,a数组对应的行列都要为0;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int a[][];
int m,n;
void fun(int x,int y)
{
for(int i=;i<=m;i++)
a[i][y]=;
for(int j=;j<=n;j++)
a[x][j]=;
}
int main()
{
int x[],y[];
int b[][];
int i,j;
cin>>m>>n;
for(i=;i<=m;i++)
{
for(j=;j<=n;j++)
a[i][j]=;
}
memset(x,,sizeof(x));
memset(y,,sizeof(y));
for(i=;i<=m;i++)
{
for(j=;j<=n;j++)
{
cin>>b[i][j];
if(b[i][j]==)
fun(i,j);
}
}
/*for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}*/
for(i=;i<=m;i++)
{
for(j=;j<=n;j++)
{
if(a[i][j]==)
{
x[i]=;
y[j]=;
}
}
}
/*cout<<x[1]<<" "<<x[2]<<endl;
cout<<y[1]<<" "<<y[2]<<endl;*/
int flag=;
for(i=;i<=m;i++)
{
for(j=;j<=n;j++)
{
if(x[i]==||y[j]==)
{
if(b[i][j]==)
flag=;
else
{
cout<<"NO"<<endl;
return ;
}
}
else
{
if(b[i][j]==)
{
cout<<"NO"<<endl;
return ;
}
else
flag=;
}
}
}
if(flag==)
cout<<"YES"<<endl;
for(i=;i<=m;i++)
{
for(j=;j<n;j++)
cout<<a[i][j]<<" ";
cout<<a[i][n]<<endl;
}
return ;
}
CodeForces 486B的更多相关文章
- codeforces 486B.OR in Matrix 解题报告
题目链接:http://codeforces.com/problemset/problem/486/B 题目意思:给出一个m行n列的矩阵B(每个元素只由0/1组成),问是否可以利用矩阵B,通过一定的运 ...
- Codeforces 486B - OR in Matrix
矩阵的 OR ,也是醉了. 题目意思很简单,就是问你有没有这么一个矩阵,可以变化,得到输入的矩阵. 要求是这个矩阵每行都可以上下任意移动,每列都可以左右任意移动. 解题方法: 1.也是导致我WA 的原 ...
- 【codeforces】Codeforces Round #277 (Div. 2) 解读
门户:Codeforces Round #277 (Div. 2) 486A. Calculating Function 裸公式= = #include <cstdio> #include ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- MessageDigest 加密和解密2
package com.drawthink.platform.util; import java.security.MessageDigest; import java.security.NoSuch ...
- C# 如何实现WinForm程序自重启(重新启动自己)
重启的时间间隔方法 private void Restart() { Thread thtmp = new Thread(new ParameterizedThreadStart(run)); obj ...
- python--7、面向对象
什么是面向对象 对象,即抽象的一类事物中的某个具体的个体.这个世界中存在的一切皆为对象,不存在的也能创建出来. 较之面向过程的区别: 编程的复杂度远高于面向过程,不了解面向对象而立即上手基于它设计程序 ...
- [原创]Linux(CentOS)下安装nodejs+express
网上找了很多步骤,各种问题,自己总结下吧 1.下载 wget --no-check-certificate https://nodejs.org/dist/v6.10.1/node-v6.10.1-l ...
- 【MySQL】通信协议
1.TCP/IP(Transmission Control Protocol/Internet Protocol) 该通信协议套件用于连接 Internet 上的主机.在 Linux 操作系统中,TC ...
- 能够附加图片的标签控件iOS项目源码
这个源码案例是能够附加图片的标签控件,源码JTImageLabel,JTImageLabel能够附加图片的标签Label控件,图片可以随意更换.位置也能够很好的控制.效果图: <ignore_j ...
- Assembly之instruction之JUMP
JMP Jump unconditionally Syntax JMP label Operation PC + 2 × offset −> PC Description The 10- ...
- Matlab矩阵填充--Matlab interp2
Matlab interp2 为Matlab的矩阵填充函数, 填充关系: x=1:11; y=1:13; x1=1:0.1:12; y1=1:0.1:14; [x2,y2]=meshgrid(x1,y ...
- [Intermediate Algorithm] - Everything Be True
题目 所有的东西都是真的! 完善编辑器中的every函数,如果集合(collection)中的所有对象都存在对应的属性(pre),并且属性(pre)对应的值为真.函数返回ture.反之,返回false ...
- <转>c++引用与指针的区别(着重理解)
★ 相同点: 1. 都是地址的概念: 指针指向一块内存,它的内容是所指内存的地址:引用是某块内存的别名. ★ 区别: 1. 指针是一个实体,而引用仅是个别名: 2. 引用使用时无需解引用(*),指 ...