Codeforces Round #277 (Div. 2) B.OR in Matrix 模拟
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.
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).
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 mrows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one.
2 2
1 0
0 0
NO
//
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define meminf(a) memset(a,127,sizeof(a)); inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){
if(ch=='-')f=-;ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';ch=getchar();
}return x*f;
}
//****************************************
#define maxn 1000+5
#define mod 1000000007 int c[maxn][maxn],b[maxn][maxn],a[maxn][maxn];
int main(){ int n=read();
int m=read();
memset(b,-,sizeof(b));
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]==){
for(int k=;k<=m;k++){
b[i][k]=;
}
for(int k=;k<=n;k++){
b[k][j]=;
}
}
}
}
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(b[i][j]==-)b[i][j]=;
}
}
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
int aa=;
for(int k=;k<=m;k++){
aa|=b[i][k];
}
for(int k=;k<=n;k++){
aa|=b[k][j];
}
c[i][j]=aa;
}
}bool flag=;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(c[i][j]!=a[i][j])flag=;
}
}
if(!flag){
cout<<"YES"<<endl;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
cout<<b[i][j]<<" ";
}
cout<<endl;
}
}
else cout<<"NO"<<endl;
return ;
}
代码
Codeforces Round #277 (Div. 2) B.OR in Matrix 模拟的更多相关文章
- 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/probl ...
- Codeforces Round #277 (Div. 2) A B C 水 模拟 贪心
A. Calculating Function time limit per test 1 second memory limit per test 256 megabytes input stand ...
- 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 #367 (Div. 2) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
- 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 ...
随机推荐
- SVN系列学习(二)-小乌龟的安装与配置
1.TortoiseSVN的介绍 TortoiseSVN是Subversion版本控制系统的一个免费开源客户端,可以超越时间的管理文件和目录. 2.TortoiseSVN的安装 下载地址:http:/ ...
- Android RecyclerView利用Glide加载大量图片into(Target)导致OOM异常
学过android的人应该都知道Glide是一个无比强大的图片加载库,它内部已经提供了很好的缓存机制供我们选择,我们只需一个参数调用即可(DiskCacheStrategy()),而不必像Univer ...
- android ormlite 清空表
delete from TableName; //清空数据 update sqlite_sequence SET seq = where name ='TableName';//自增长ID为0 Sam ...
- Android开发笔记(5)——方法调用(基础)
转载请注明——博客园igoslly:http://www.cnblogs.com/igoslly/p/6833544.html 在实际方法调用中,程序按顺序逐句执行,直到“}”结束. 为避免程序大 ...
- Java Web框架前景浅析
基于三(多)层架构模式,典型WEB系统的总体架构如下图所示: 在上述分层架构中,整个应用被划分为两大部分: 客户端:基于浏览器提供信息展现.用户交互等功能.所采用的技术主要有:HTML/HTML5.J ...
- GridView动态计算高度
// 动态加载GridView 高度 public static void setListViewHeightBasedOnChildren(MyGridView myGridView) { List ...
- CentOS7将firewall切换为iptables防火墙
- (转)Struts2快速入门
http://blog.csdn.net/yerenyuan_pku/article/details/66187307 Struts2框架的概述 Struts2是一种基于MVC模式的轻量级Web框架, ...
- 数字化婚姻配对尝试问题(C++实现)
问题描述:一.标题: 数字化婚姻配对尝试 二.题目: 建立一个模型,来模拟推导社会男女择偶过程. 为了模型简化,一个人的特性指标有三个,这里假设为财富.样貌.品格,每个指标均可取值1-100之间任意数 ...
- 程序员不可不知的Linux性能工具
前言 在实际开发中,有时候会收到一些服务的监控报警,比如CPU飙高,内存飙高等,这个时候,我们会登录到服务器上进行排查.本篇博客将涵盖这方面的知识:Linux性能工具. 一次线上问题排查模拟 背景:服 ...