cf486B 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
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 题意是一个矩阵B的b[i][j]是所有A矩阵的a[i][k]和a[k][j]或起来的值,给一个B矩阵,问是否存在这样的A矩阵,并输出方案
因为是或……所以在B中出现的0必须在A中一横一竖都为0
所以先把B中0的情况搞完,然后判一下现在的B矩阵中1的位置对应的A的一行一列是否存在至少一个1
15分钟……有些慢了,你看卓神6分钟A掉
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
int mat[110][110];
int a[110][110];
int n,m;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void ex()
{
printf("NO");
exit(0);
}
int main()
{
n=read();m=read();
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
mat[i][j]=1;
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
a[i][j]=read();
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
{
int x=a[i][j];
if (!x)
{
for (int k=1;k<=n;k++)
mat[k][j]=0;
for (int k=1;k<=m;k++)
mat[i][k]=0;
}
}
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
if(a[i][j])
{
bool mrk=0;
for (int k=1;k<=n;k++)if (mat[k][j])mrk=1;
for (int k=1;k<=m;k++)if (mat[i][k])mrk=1;
if (!mrk)ex();
}
printf("YES\n");
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
printf("%d ",mat[i][j]);
printf("\n");
}
}
cf486B OR in Matrix的更多相关文章
- CF486B OR in Matrix(构造+思维)
CF486B 一道有趣的思维题 由于or的性质可知只要a[i][j]为1那么b中第i行,第j列将都变成1 相反的,如果b[i][j]是0那么a中第i行,第j列都必须是0 根据第二个性质我们可以构造出a ...
- angular2系列教程(十一)路由嵌套、路由生命周期、matrix URL notation
今天我们要讲的是ng2的路由的第二部分,包括路由嵌套.路由生命周期等知识点. 例子 例子仍然是上节课的例子:
- 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 ...
- Atitit Data Matrix dm码的原理与特点
Atitit Data Matrix dm码的原理与特点 Datamatrix原名Datacode,由美国国际资料公司(International Data Matrix, 简称ID Matrix)于 ...
- Android笔记——Matrix
转自:http://www.cnblogs.com/qiengo/archive/2012/06/30/2570874.html#translate Matrix的数学原理 在Android中,如果你 ...
- 通过Matrix进行二维图形仿射变换
Affine Transformation是一种二维坐标到二维坐标之间的线性变换,保持二维图形的"平直性"和"平行性".仿射变换可以通过一系列的原子变换的复合来 ...
- [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 ...
- [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 ...
- [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 ...
随机推荐
- myeclipse实现Servlet实例(1) 通过继承servlet接口实现
1.在myeclipse新建web project,配置Tomcat(在myeclipse的Window--preferences) 2.然后在src新建servlet文件( 此处放在com.tsin ...
- Wikioi 1080一维树状数组
半个月时间最终把那些杂七杂八的学完了,尽管学完也,也仅仅是有了个模板,自己手敲还是不太行.所以如今開始要疯狂刷题了! ! .!!! 这题裸的树状数组.曾经写那道<敌兵布阵>的时候写过,所以 ...
- Android-它们的定义Dialog
Android-它们的定义Dialog 2014年4月27日 星期天 天气晴朗 心情平静 本篇博文来分享一个也是开发中常常须要用到的功能-自己定义对话框,这里我用到了Android中的图形资源shap ...
- hdu2767 Proving Equivalences --- 强连通
给一个图,问至少加入�多少条有向边能够使图变成强连通的. 原图是有环的,缩点建图,在该DAG图上我们能够发现,要使该图变成强连通图必须连成环 而加入�最少的边连成环,就是把图上入度为0和出度为0的点连 ...
- eclipse注释模板修改
http://swiftlet.net/archives/1199 以下为模板文件 <?xml version="1.0" encoding="UTF-8" ...
- DEV SIT UAT
DEV环境:DEV顾名思义就是develop,即代码开发的环境.SIT环境:System Integration Test系统集成测试,开发人员自己测试流程是否走通.UAT环境:User Accept ...
- jquery,js常用特效名称
- c#读写cookie
读 response.SetCokie(new HttpCookie("Color",TextBox1.Text);写 request.Cookies["color&qu ...
- extjs folder is lost解决方法 和 FineUI主题切换时 iframe内的内容主题不变的解决方法
错误原因:extjs包和FineUI版本不一致 或者是 webconfig配置中 没有设置为任何人可访问 解放方法下载和FineUI版本相同的extjs包就ok了 解决方法:FineUI主题切换时 ...
- android Log.isLoggable步骤的使用
原文地址: http://www.cnblogs.com/maxinliang/p/4024442.html android Log.isLoggable方法的使用 android 动态控制logca ...