矩阵的 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. codeforces 557D. Vitaly and Cycle 二分图染色

    题目链接 n个点, m条边, 问最少加几条边可以出现一个奇环, 在这种情况下, 有多少种加边的方式. 具体看代码解释 #include<bits/stdc++.h> using names ...

  2. FPGA中改善时序性能的方法_advanced FPGA design

    本文内容摘自<advanced FPGA design>对应中文版是 <高级FPGA设计,结构,实现,和优化>第一章中的内容 FPGA中改善时序,我相信也是大家最关心的话题之一 ...

  3. HDU 1001 Sum Problem

    /* 注意可以是负整数,而且在过程中会超过int,所以要用longlong */ #include <cstdio> int main() { long long n; while (sc ...

  4. ajax 中文乱码

     ajax 中文乱码  Firefox 正常,IE 有问题是 解决办法 data:{"name":name,"number":number,"card ...

  5. JS动态增加页面上的控件实例

    <input   type="button"   value="继续添加"   onclick="append();"/ > & ...

  6. Break the Chocolate(规律)

    Break the Chocolate Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  7. artdialog的图片,标题,以及关闭按钮不显示的问题

    因其它css样式文件中包含“div{ overflow:hidden; }”引起的artdialog的图片,标题,以及关闭按钮不显示的问题: 如下图: 解决办法:在artdialog的样式文件顶部添加 ...

  8. hdu1281结题报告

    哎哎...自己刚刚一看到这个题目居然.....什么都想不到...看了一下别人的解题报告说最大匹配...于是就自己开始构思啦... 对于这个棋盘,有K个可以放棋子的位置....那么 首先我们开始可以求出 ...

  9. return view详解(转载)

    1.return View(); 返回值 类型:System.Web.Mvc.ViewResult将视图呈现给响应的 View() 结果. 注释 View() 类的此方法重载将返回一个具有空 View ...

  10. 记载abp中Dbcontext的疑问

    q:abp中httpcontext如何在一次请求中保证获取的是相同的实例. 大牛的原话: LifestylePerWebRequest does not works good with async. ...