codeforces 486B OR in Matrix
2014-11-15 12:19
232 查看
From matrix A, Nam creates another matrix
B of the same size using formula:
![](http://espresso.codeforces.com/4332dfa4828fa3b9679abe53387834c43c801689.png)
.
(Bij is
OR of all elements in row
i and column j of matrix
A)
先把矩阵A全部置为1,再把B矩阵中为0的位置,对应的A中位置的行和列置为0.就得到了原矩阵A;
B of the same size using formula:
![](http://espresso.codeforces.com/4332dfa4828fa3b9679abe53387834c43c801689.png)
.
(Bij is
OR of all elements in row
i and column j of matrix
A)
先把矩阵A全部置为1,再把B矩阵中为0的位置,对应的A中位置的行和列置为0.就得到了原矩阵A;
/******************** * Author:fisty * Data:2014-11-15 * cf468B * *******************/ #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define MAX_N 110 int a[MAX_N][MAX_N], b[MAX_N][MAX_N]; int main(){ int n, m; scanf("%d%d", &n, &m); for(int i = 1;i <= n; i++){ for(int j = 1; j <= m; j++){ scanf("%d", &b[i][j]); a[i][j] = 1; } } for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ if(!b[i][j]){ for(int k = 1; k <= m; k++) a[i][k] = 0; for(int k = 1; k <= n; k++) a[k][j] = 0; } } } for(int i = 1;i <= n; i++){ for(int j = 1; j <= m; j++){ if(b[i][j]){ int f = 0; for(int k = 1;k <= m; k++) f |= a[i][k]; for(int k = 1; k <= n; k++) f |= a[k][j]; if(!f){ printf("NO\n"); return 0; } } } } printf("YES\n"); for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ printf("%d ",a[i][j]); } printf("\n"); } return 0; }
相关文章推荐
- codeforces 258B Little Elephant and Elections 数位DP+DFS
- CodeForces 534F Simplified Nonogram (记忆化搜索)
- Codeforces 6225B KMP
- Codeforces 115A. Party
- CodeForces - 729D(思路)
- CodeForces 158 A.Next Round(水~)
- CodeForces-884D:Boxes And Balls(合并石子)
- codeforces 166?
- Codeforces 492E Vanya and Field(拓展欧几里得)
- Codeforces 653C Bear and Up-Down 【模拟】
- Codeforces 707D.Persistent Bookcase(离线算法,dfs树,好题!)
- CodeForces 776D The Door Problem【并查集】
- CodeForces 22b_Bargaining Table_dp(暴力)
- codeforces 82A Double Cola
- [代码]codeforces 274B Zero Tree
- 【贪心】Codeforces 353E Antichain
- codeforces 598C C. Nearest vectors(极角排序)
- Codeforces- 124B-Permutations (深搜找全排列以及取出一个数的每一位)
- Codeforces 583C GCD Table【贪心】
- CodeForces - 822C Hacker, pack your bags!(区间端点处理技巧+思维)