传送门:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1923
裸裸的高斯消元,bitset大法好...
#include<bitset> #include<cstdio> #include<cstring> #include<algorithm> const int maxn=1010,maxm=2010; using namespace std; bitset<maxn> a[maxm]; int n,m,ans;char s[maxn]; void gauss(){ for (int i=1;i<=n;i++){ int j=i; for (;j<=m&&!a[j][i];j++); if (j>m){ans=-1;return;} ans=max(ans,j); swap(a[i],a[j]); for (int j=1;j<=m;j++) if (j!=i&&a[j][i]) a[j]^=a[i]; } } int main(){ scanf("%d%d",&n,&m); for (int i=1,x;i<=m;i++){ scanf("%s",s+1); for (int j=1;j<=n;j++) a[i][j]=s[j]-'0'; scanf("%d",&x),a[i][n+1]=x; } gauss(); if (ans==-1){puts("Cannot Determine");return 0;} printf("%d ",ans); for (int i=1;i<=n;i++) puts(a[i][n+1]?"?y7M#":"Earth"); return 0; } /*6 7 011010 1 101011 0 110100 1 100101 0 011101 0 101011 1 011110 1 */