注意事项:无。

代码:

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
int n, m;
bool a[MAXn + 10][MAXm + 10];
int guass() {
int row = 1, mxchoser = 0;
for (int col = 1; col <= m && row <= n; ++col) {
int choser = -1;
for (int i = row; i <= n; ++i) {
if (a[i][col]) {
choser = i;
break;
}
}
if (choser == -1) continue;
mxchoser = max(mxchoser, choser);
if (choser != row) swap(a[row], a[choser]);
for (int i = 1; i <= n; ++i) {
if (i == row) continue;
if (a[i][col]) {
for (int j = col; j <= m + 1; ++j) {
a[i][j] ^= a[row][j];
}
}
}
++row;
}
bool noans = 0, moreans = 0;
if (row <= m) {
for (int i = row; i <= n; ++i) {
if (a[i][m + 1]) {
noans = 1;
break;
}
}
if (noans == 0) moreans = 1;
}
if (noans) return 0;
else if (moreans) return -1;
else return mxchoser;
}

Luogu P2447 [SDOI2010] 外星千足虫

代码(本代码中 nnmm 和题面中的是反的,代码中 nn 代表矩阵的行数,mm 代表列数):

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
72
73
74
75
76
77
78
79
#include<bits/stdc++.h>
using namespace std;
const int MAXn = 2e3;
const int MAXm = 1e3;

template <typename T>
inline void read(T &a) {
char c;for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar());bool f = c == '-';T x = f ? 0 : (c ^ '0');for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) {x = x * 10 + (c ^ '0');}a = f ? -x : x;
}
template <typename T, typename ...Argv>
inline void read(T &a, Argv &...argv) {
read(a), read(argv...);
}

int n, m;
bool a[MAXn + 10][MAXm + 10];
int guass() {
int row = 1, mxchoser = 0;
for (int col = 1; col <= m && row <= n; ++col) {
int choser = -1;
for (int i = row; i <= n; ++i) {
if (a[i][col]) {
choser = i;
break;
}
}
if (choser == -1) continue;
mxchoser = max(mxchoser, choser);
if (choser != row) swap(a[row], a[choser]);
for (int i = 1; i <= n; ++i) {
if (i == row) continue;
if (a[i][col]) {
for (int j = col; j <= m + 1; ++j) {
a[i][j] ^= a[row][j];
}
}
}
++row;
}
bool noans = 0, moreans = 0;
if (row <= m) {
for (int i = row; i <= n; ++i) {
if (a[i][m + 1]) {
noans = 1;
break;
}
}
if (noans == 0) moreans = 1;
}
if (noans) return 0;
else if (moreans) return -1;
else return mxchoser;
}

char str[MAXm + 10];
signed main() {
read(m, n);
for (int i = 1; i <= n; ++i) {
scanf("%s", str + 1);
for (int j = 1; j <= m; ++j) {
a[i][j] = str[j] - '0';
}
scanf("%d", &a[i][m + 1]);
}
int res = guass();
if (res == 0) {
puts("Error1");
exit(1);
} else if (res == -1) {
puts("Cannot Determine");
} else {
printf("%d\n", res);
for (int i = 1; i <= m; ++i) {
if (a[i][m + 1]) puts("?y7M#");
else puts("Earth");
}
}
return 0;
}