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 ...
随机推荐
- 高效操作DOM
DOM树与Render树 这个应该都是知道的.就是用户请求HTML下来后,浏览器渲染引擎的基本工作中两个概念. copy一张图,流程大概就是:解析html构建DOM树,渲染树构建,渲染树布局,绘制渲染 ...
- python之math模块
1.math简介 >>>import math #导入math模块 >>>dir(math) #这句可查看所有函数名列表 >>>help(math ...
- hdu 2815 Mod Tree 高次方程,n不为素数
Accepted 406MS 8576K 2379 B C++/** 这里加了一点限制,,大体还是一样的,, **/ #include <iostream> #include <cs ...
- 【转】AC算法详解
原文转自:http://blog.csdn.net/joylnwang/article/details/6793192 AC算法是Alfred V.Aho(<编译原理>(龙书)的作者),和 ...
- Adobe Flash Player已经终止一项可能不安全的操作,解决方案
http://www.macromedia.com/support/documentation/cn/flashplayer/help/settings_manager04.html
- Leetcode 动态规划 Unique Paths
本文为senlie原创.转载请保留此地址:http://blog.csdn.net/zhengsenlie Unique Paths Total Accepted: 17915 Total Submi ...
- C++使用之常量的定义
在介绍C++的常前,先看下下面的代码. for (int i = 0; i < 512; ++i) { …; } 512是什么,它具有什么含义?在代码中若直接使用类似512这些“魔数”(magi ...
- HDU 1222 Wolf and Rabbit(gcd)
HDU 1222 Wolf and Rabbit (最大公约数)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- centos7/redhat7 将网卡名字改成eth样式的方法
方法/步骤 1. 编辑 /etc/sysconfig/grub 找到“GRUB_CMDLINE_LINUX”这一行
- BZOJ 1230: [Usaco2008 Nov]lites 开关灯( 线段树 )
线段树.. --------------------------------------------------------------------------------- #include< ...