矩阵的 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的更多相关文章

  1. codeforces 486B.OR in Matrix 解题报告

    题目链接:http://codeforces.com/problemset/problem/486/B 题目意思:给出一个m行n列的矩阵B(每个元素只由0/1组成),问是否可以利用矩阵B,通过一定的运 ...

  2. CodeForces 313C Ilya and Matrix

    Ilya and Matrix Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Su ...

  3. codeforces C. Ilya and Matrix 解题报告

    题目链接:http://codeforces.com/problemset/problem/313/C 题目意思:给定 4n 个整数(可以组成 2n × 2n 大小的矩阵),问通过对这些整数进行排列, ...

  4. 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 ...

  5. Codeforces 903F Clear The Matrix(状态压缩DP)

    题目链接 Clear The Matrix 题意 给定一个$4 * n$的矩形,里面的元素为$'.'$或$'*'$.现在有$4$种正方形可以覆盖掉$'*'$,正方形的边长分别为$1,2,3,4$. 求 ...

  6. Codeforces 903F Clear the Matrix

    题目大意 考虑一个 $4$ 行 $n$ ($4\le n\le 1000$)列的矩阵 $f$,$f$ 中的元素为 * 或 . . 对 $f$ 进行若干次如下变换: 将一个 $k\times k$($1 ...

  7. CodeForces 486B

    Let's define logical OR as an operation on two logical values (i. e. values that belong to the set { ...

  8. codeforces 495D Sonya and Matrix

    Since Sonya has just learned the basics of matrices, she decided to play with them a little bit. Son ...

  9. Codeforces 884E E. Binary Matrix

    题 OvO http://codeforces.com/contest/884/problem/E 884e 解 考虑并查集,每个点向上方和左方的点合并,答案即为1的总数减去需要合并的次数 由于只有1 ...

随机推荐

  1. java生成随机字符串

    学习java comparable特性时候,定义如下Student类,需要需要随机添加学生姓名以及学号和成绩,这是java如何随机生成名字,根据我的查询,我找到目前java库支持两种方法. 1. or ...

  2. Git Version recovery command introduction - git reset

    reset命令有3种方式: git reset –mixed:此为默认方式,不带任何参数的git reset,即时这种方式,它回退到某个版本,只保留源码,回退commit和index信息 git re ...

  3. Android系统设置— android.provider.Settings

    android.provider.Settings Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS); sta ...

  4. AES 加密

    package com.sprucetec.tms.utils; import java.security.Key; import javax.crypto.Cipher;import javax.c ...

  5. Php 使用 fsockopen发送http请求

    <?php function HTTP_Post($URL,$data, $referrer="") { // parsing the given URL $URL_Info ...

  6. kinect for windows - 手势识别之一,kinect手势识别框架

    何为手势识别,就是电脑认识人手的自然动作.自然动作包括摆手,握拳,双手合十等等.如果电脑能认识我们这些手势,将来的人机交互将会变得简单而有趣.这里手势不等同于某些规定的动作,比如按鼠标左键,则不属于手 ...

  7. C++模板:qsort

    void qsort(int l,int r){ int i,j,t,mid; mid=b[(l+r)>>1]; i=l; j=r; do{ while (b[i]<mid) i++ ...

  8. c 整数的逆序输出 输入3,2就算 2+22+222的结果

    #include<stdio.h> #include<math.h> //整数逆序输出 void nixu() { int num,i; i = ; scanf("% ...

  9. Java代码优化策略

    1.生成对象时,合理分配空间和大小:new ArrayList(100); 2.优化for循环: Vector vect = new Vector(1000); For(int i=0; i<v ...

  10. C指针陷阱

    问题一: #include <stdio.h> int main(int argc, char *argv[]) { ]={ ,,,, }; ); printf(),*(p-)); ; } ...