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 ...
随机推荐
- hdu 4619 Warm up 2 二分图匹配
题目链接 给两种长方形, 水平的和垂直的, 大小都为1*2, n个水平的, m个垂直的, 给出它们的坐标. 水平的和垂直的可以相互覆盖, 但是同种类型的没有覆盖. 去掉一些长方形, 使得剩下的全部都没 ...
- [LeetCode]题解(python):133-Clone Graph
题目来源: https://leetcode.com/problems/clone-graph/ 题意分析: 克隆一个无向图.每个节点包括一个数值和它的邻居. 题目思路: 直接深度拷贝. 代码(pyt ...
- [LeetCode]题解(python):075-Sort Colors
题目来源: https://leetcode.com/problems/sort-colors/ 题意分析: 给定n个颜色,红色,白色和蓝色.分别用0,1,2代替,将这些颜色排序,0在1前,1在2前. ...
- python函数cmp()
cmp(x, y) 中文说明:比较两个对象x和y,如果x < y ,返回负数:x == y, 返回0:x > y,返回正数. 版本:该函数只有在python2中可用,而且在python2所 ...
- Linux 系统之Systemd
子贡问为仁.子曰:“工欲善其事,必先利其器.居是邦也,事其大夫之贤者,友其士之仁者.”——孔子(春秋)<论语·卫灵公> [工欲善其事,必先利其器] 掌握一门技术,知道其发展历程是非常重要的 ...
- Linux 动态库剖析
进程与 API 动态链接的共享库是 GNU/Linux® 的一个重要方面.该种库允许可执行文件在运行时动态访问外部函数,从而(通过在需要时才会引入函数的方式)减少它们对内存的总体占用.本文研究了创建和 ...
- (C#)Windows Shell 外壳编程系列6 - 执行
原文(C#)Windows Shell 外壳编程系列6 - 执行 (本系列文章由柠檬的(lc_mtt)原创,转载请注明出处,谢谢-) 接上一节:(C#)Windows Shell 外壳编程系列5 - ...
- Android studio如何使用SVN进行版本控制?
通过这两天对Android Studio的研究,终于搞通了Android Studio的基本操作及与SVN的相关关联操作(这样才能在公司的开发工作中使用):Google年底将会停止ADT插件的更新和支 ...
- TEX Quotes(字符串,水)
TEX Quotes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9674 Accepted: 5073 Descri ...
- hdu3416 Marriage Match IV【最短路+最大流】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4297581.html ---by 墨染之樱花 题目链接:http://acm.hdu.ed ...