-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUva11581.cpp
More file actions
71 lines (58 loc) · 1.13 KB
/
Copy pathUva11581.cpp
File metadata and controls
71 lines (58 loc) · 1.13 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <math.h>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <sstream>
using namespace std;
int g[3][3];
void f() {
int h[3][3];
h[0][0] = (g[0][1] + g[1][0]) % 2;
h[0][1] = (g[0][0] + g[1][1] + g[0][2]) % 2;
h[0][2] = (g[0][1] + g[1][2]) % 2;
h[1][0] = (g[0][0] + g[1][1] + g[2][0]) % 2;
h[1][1] = (g[0][1] + g[1][0] + g[1][2] + g[2][1]) % 2;
h[1][2] = (g[1][1] + g[0][2] + g[2][2]) % 2;
h[2][0] = (g[2][1] + g[1][0]) % 2;
h[2][1] = (g[2][0] + g[1][1] + g[2][2]) % 2;
h[2][2] = (g[2][1] + g[1][2]) % 2;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
g[i][j] = h[i][j];
}
}
}
bool isZero() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (g[i][j] > 0)
return false;
}
}
return true;
}
int main() {
int TC;
scanf("%d", &TC);
while (TC--) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
scanf("%1d", &g[i][j]);
}
}
int ans = -1;
while (!isZero()) {
f();
ans++;
}
printf("%d\n", ans);
}
return 0;
}