# Luogu2447 [SDOI2010]外星千足虫

## Description

$n$个未知数$x_1, x_2, \cdots, x_n$，给出$m$条消息，每条消息选出一些未知数并告诉你他们的和的奇偶性。你的目标是判断每个未知数的奇偶性

$n \leq 1000, m \leq 2000$

## Code

#include <bits/stdc++.h>

using namespace std;

#define fst first
#define snd second
#define mp make_pair
#define squ(x) ((LL)(x) * (x))
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef pair<int, int> pii;

template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }

int sum = 0, fg = 1; char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') fg = -1;
for (; isdigit(c); c = getchar()) sum = (sum << 3) + (sum << 1) + (c ^ 0x30);
return fg * sum;
}

const int maxn = 1e3 + 10;
const int maxm = 2e3 + 10;

bitset<maxn> a[maxm], ans;

int n, m;

int main() {
#ifdef xunzhen
freopen("alien.in", "r", stdin);
freopen("alien.out", "w", stdout);
#endif

for (int i = 1; i <= m; i++) {
static char s[maxn];
scanf("%s", s);
for (int j = 0; j < n; j++) a[i][j + 1] = s[j] - 0x30;
}

int Max = n;
for (int i = 1; i <= n; i++) {
int p = i;
for (int j = i + 1; j <= m; j++)
if (a[j][i]) { p = j, chkmax(Max, j); break; }
if (!a[p][i]) { printf("Cannot Determine\n"); return 0; }
if (p != i) swap(a[p], a[i]);
for (int j = i + 1; j <= m; j++)
if (a[j][i]) a[j] ^= a[i];
}

for (int i = n; i; i--) {
for (int j = i + 1; j <= n; j++)
if (a[i][j] & ans[j]) a[i].flip(n + 1);
ans[i] = a[i][n + 1];
}

printf("%d\n", Max);
for (int i = 1; i <= n; i++) printf(ans[i] ? "?y7M#\n" : "Earth\n");

return 0;
}
posted @ 2019-02-06 13:50 xunzhen 阅读(...) 评论(...) 编辑 收藏