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 ...
随机推荐
- poj1305:概念水题
了解一下毕达哥拉斯三元组概念= = 暴力求出所有的本源三元组即可 代码: #include <iostream> #include <stdio.h> #include< ...
- java servlet+jquery+json学习小例子
引入JSON的jar包: 注意,如果包不全,页面请求servlet时,jquery ajax会返回error:function 弹出error occured!!! HTML Code: <%@ ...
- VSCode
下载: 打开终端控制器 wget http://download.microsoft.com/download/0/D/5/0D57186C-834B-463A-AECB-BC55A8E466AE/V ...
- BeyondCompare两个文件中同一行字符长度不一致的文件对比,比如pi文件对比(xjl456852原创)
假设有两个文件,里面存放的数字都只有一行,但长度不一样,对比时会有问题 示例文件: 对比示例如图: 左边的pi的字符串比较长,右边的比较短. 右边的pi的值不是从开始的第一个位置对比的,这样的情况是有 ...
- <Win32_6>程序员求爱的创意程序^_^
作为程序员,我们时常被外界误认为很闷.不浪漫.没创意……等等这一类人,这让我们实在有些感伤啊,我得为程序员呐喊一声: 我们也能可以欢快.浪漫.有创意…… 朋友,你向女生表白过吗? …… 这个问题有点儿 ...
- Linux重装系统后SSH登录失败
#Linux重装系统后SHH登录服务器报错 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ WARNING: REMOTE H ...
- openssl 证书请求和自签名命令req详解
1.密钥.证书请求.证书概要说明 在证书申请签发过程中,客户端涉及到密钥.证书请求.证书这几个概念,初学者可能会搞不清楚三者的关系,网上有的根据后缀名来区分三者,更让人一头雾水.我们以申请证书的流程说 ...
- 九个Console命令,让 JS 调试更简单
一.显示信息的命令 <!DOCTYPE html> <html> <head> <title>常用console命令</title> < ...
- 在IIS集成管道中使用OWIN Middleware
在Katana中启用Windows Authorization OWIN的架构: Host 管理OWIN pipeline上运行的进程 Server 打开一个network socket,,监听请求 ...
- Android Studio tips and tricks 翻译学习
Android Studio tips and tricks 翻译 这里是原文的链接. 正文: 如果你对Android Studio和IntelliJ不熟悉,本页提供了一些建议,让你可以从最常见的任务 ...