BZOJ 1923: [Sdoi2010]外星千足虫 高斯消元+bitset
作者:互联网
高斯消元求解异或方程组.
#include <cstdio> #include <bitset> #define N 2004 #define setIO(s) freopen(s".in","r",stdin) , freopen(s".out","w",stdout) using namespace std; int n,m,ans; char str[N]; bitset<N>v[N]; int main() { int i,j,k; // setIO("input"); scanf("%d%d",&n,&m); for(i=1;i<=m;++i) { int tmp; scanf("%s%d",str+1,&tmp); for(j=1;j<=n;++j) v[i][j]=(str[j]=='0'?0:1); v[i][n+1]=tmp; } for(i=1;i<=n;++i) { for(j=i;j<=m;++j) { if(v[j][i]) { ans=max(ans,j),swap(v[j],v[i]); break; } } if(!v[i][i]) { printf("Cannot Determine\n"); return 0; } for(j=i+1;j<=m;++j) if(v[j][i]) v[j]^=v[i]; } printf("%d\n",ans); for(i=1;i<=n;++i) { for(j=i+1;j<=n;++j) if(v[i][j]) v[i]^=v[j]; if(v[i][n+1]) printf("?y7M#\n"); else printf("Earth\n"); } return 0; }
标签:千足虫,int,Sdoi2010,setIO,freopen,include,高斯消,define 来源: https://www.cnblogs.com/guangheli/p/11525479.html