Codeforces 486B - OR in Matrix
矩阵的 OR ,也是醉了。
题目意思很简单,就是问你有没有这么一个矩阵,可以变化,得到输入的矩阵。
要求是这个矩阵每行都可以上下任意移动,每列都可以左右任意移动。
解题方法:
1.也是导致我WA 的原因,首先要判断是否是一个零矩阵,如果是一个零矩阵,那么YES输出
2.判断输入矩阵存在1的那个位置,在输出矩阵的同一行同一列是否存在1,如果没有则NO输出
3.开辟数组X[MAXN],Y[MAXN]记录这一行或者这一列是否有0这个元素
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define ll long long
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
using namespace std; const int INF = 0x3f3f3f3f; int a[][], b[][], x[], y[];// Martix a as output Martix, Martix b as input Martix
int n, m; int main(){
int i, j, t, k;
while(EOF != scanf("%d%d",&n,&m)){
for(i = ; i <= n; ++i){
for(j = ; j <= m; ++j){
scanf("%d",&a[i][j]);
b[i][j] = a[i][j];
if(!a[i][j]){
x[i] = ;
y[j] = ;
}
}
}
bool ff = true;
for(i = ; i <= n; ++i){
for(j = ; j <= m; ++j){
if(x[i] || y[j]){ // nice cood
a[i][j] = ;
} else{
ff = false;
}
}
}
bool falg = false;
for(i = ; i <= n; ++i){
for(j = ; j <= m; ++j){
if(a[i][j]) falg = true;
}
}
if(ff) falg = true;
for(i = ; i <= n; ++i){
for(j = ; j <= m; ++j){
bool kk = false;
if(b[i][j]){
for(int ii = ; ii <= n; ++ii){
if(a[ii][j]) kk = true;
}
for(int jj = ; jj <= m; ++jj){
if(a[i][jj]) kk = true;
}
if(!kk){
falg = false;
}
}
}
} if(falg){
printf("YES\n");
for(i = ; i <= n; ++i){
for(j = ; j < m; ++j){
printf("%d ",a[i][j]);
}
printf("%d\n",a[i][m]);
}
}
else{
printf("NO\n");
}
}
return ;
}
Codeforces 486B - OR in Matrix的更多相关文章
- codeforces 486B.OR in Matrix 解题报告
题目链接:http://codeforces.com/problemset/problem/486/B 题目意思:给出一个m行n列的矩阵B(每个元素只由0/1组成),问是否可以利用矩阵B,通过一定的运 ...
- CodeForces 313C Ilya and Matrix
Ilya and Matrix Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Su ...
- codeforces C. Ilya and Matrix 解题报告
题目链接:http://codeforces.com/problemset/problem/313/C 题目意思:给定 4n 个整数(可以组成 2n × 2n 大小的矩阵),问通过对这些整数进行排列, ...
- Educational Codeforces Round 40 C. Matrix Walk( 思维)
Educational Codeforces Round 40 (Rated for Div. 2) C. Matrix Walk time limit per test 1 second memor ...
- Codeforces 903F Clear The Matrix(状态压缩DP)
题目链接 Clear The Matrix 题意 给定一个$4 * n$的矩形,里面的元素为$'.'$或$'*'$.现在有$4$种正方形可以覆盖掉$'*'$,正方形的边长分别为$1,2,3,4$. 求 ...
- Codeforces 903F Clear the Matrix
题目大意 考虑一个 $4$ 行 $n$ ($4\le n\le 1000$)列的矩阵 $f$,$f$ 中的元素为 * 或 . . 对 $f$ 进行若干次如下变换: 将一个 $k\times k$($1 ...
- CodeForces 486B
Let's define logical OR as an operation on two logical values (i. e. values that belong to the set { ...
- codeforces 495D Sonya and Matrix
Since Sonya has just learned the basics of matrices, she decided to play with them a little bit. Son ...
- Codeforces 884E E. Binary Matrix
题 OvO http://codeforces.com/contest/884/problem/E 884e 解 考虑并查集,每个点向上方和左方的点合并,答案即为1的总数减去需要合并的次数 由于只有1 ...
随机推荐
- 阿里云ECS每天一件事D1:配置SSH
近期因为项目需求,采购了两台阿里云ECS,选择的系统为CentOS 6.3 X64 安全加固版,额外买了160G的硬盘,应该够应付此项目的需求了. ECS默认已经配置好了sshd服务,可以使用root ...
- java 面试 复习 II
1 break 多重 循环跳出当前循环到上层循环再执行. 如若想跳出多重循环可以使用标号 2 byte,short,char都可以隐含转换为int.可以用在switch 表达式.long和str ...
- go语法之一
Go语法: Go语言要求public的变量必须以 大写字母开头,private变量则以小写字母开头,这种做法不仅免除了public.private关键字,更重要的是统一了命名风格. Go语言对{ } ...
- linux命令 收集
https://jaywcjlove.github.io/linux-command/ 源码:https://github.com/jaywcjlove/linux-command Linux思维导图 ...
- read/write拥塞与非拥塞
read/write read函数从打开的设备或文件中读取数据. #include <unistd.h> ssize_t read(int fd, void *buf, size_t co ...
- 通过原生js的ajax或jquery的ajax获取服务器的时间
在实际的业务逻辑中,经常是与时间相关的,而前端能获得的时间有两个:客户端的时间,服务器的时间. 客户端时间通过 javascript中的Date对象可以获取,如 var dt = new Date() ...
- IE6不支持<a>标签以外元素的hover的解决方案
IE6以及更低版本的浏览器对“:hover”的支持不理想,对于类似的“p:hover”.“img:hover”.“#header:hover”...,今天给大家介绍一种新的方法,可以完美解决IE6不支 ...
- QPushButton跑进度条(使用QSS的不同修饰来实现,其实是伪进度条)
主要用到qlineargradient,写以下CSS样式即可实现: background:qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, sto ...
- zkw费用流模版
/************************************************************** Problem: 3876 User: wangck1998 Langu ...
- Vijos 1100 加分二叉树
题目 1100 加分二叉树 2003年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目描述 Description 设一个n个节点的二叉树tree的中序遍历为( ...