-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (52 loc) · 1.22 KB
/
main.cpp
File metadata and controls
54 lines (52 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<iostream>
using namespace std;
const int MAXN = 220;
bool r[MAXN], c[MAXN];
int n, m, a[MAXN][MAXN];
bool check()
{
bool b = false;
//n遍历行数
for(int i = 1, j, s; i <= n; ++i)
{
s = a[i][1] ^ c[1];
for(j = 2; j <= m; ++j)
if((a[i][j] ^ c[j]) != s)
{
if(b)
return false;
b = true, s = a[i][j] ^ c[j];
}
r[i] = (s ^ !b ? 0 : 1);
}
return true;
}
int main()
{
//从系统中读入行数n和列数m
scanf("%d %d", &n, &m);
//从系统中读入数据
for(int i = 1, j; i <= n; ++i)
for(j = 1; j <= m; ++j)
scanf("%d", &a[i][j]);
for(int i = 1; i <= m; ++i)
c[i] = !a[1][i];
for(int i = 1; i <= m + 1; ++i)
{
//如果颠倒后check成功的话
if(check())
{
printf("YES\n");
for(int j = 1; j <= n; ++j)
//r[j]是row的颠倒
printf("%d", r[j]);
printf("\n");
//c[j]是column的颠倒
for(int j = 1; j <= m; ++j)
printf("%d", c[j]);
exit(0);
}
c[i] = !c[i];
}
printf("NO\n");
}