【BZOJ】【P1923】【Sdoi2010】【外星千足虫】【题解】【高斯消元】

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1923

仰慕TimeMachine http://timeplayer.blog.163.com/blog/static/20371825420141011503044/

Code:

#include<bits/stdc++.h>
using namespace std;
const int maxn=1010;
int n,m,ans;
bitset<maxn>a[maxn<<1];
bool Gauss(){
	for(int i=1;i<=n;i++){
		int r=0;
		for(int j=i;j<=m;j++)
		if(a[j][i]){r=j;break;}
		if(!r)return 0;
		ans=max(ans,r);
		swap(a[i],a[r]);
		for(int j=i+1;j<=m;j++)
		if(a[j][i])a[j]^=a[i];
	}for(int i=n;i>=1;i--){
		for(int j=i+1;j<=n;j++)if(a[i][j])
		a[i][n+1]=a[i][n+1]^a[j][n+1];
	}return 1;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		char c=getchar();
		while(!isdigit(c))c=getchar();
		for(int j=1;j<=n;j++){
			a[i][j]=c=='1';
			c=getchar();
		}c=getchar();
		a[i][n+1]=c=='1'; 
	}
	if(Gauss()){
		printf("%d\n",ans);
		for(int i=1;i<=n;i++)puts(a[i][n+1]?"?y7M#":"Earth");	
	}else{puts("Cannot Determine");}
	return 0;
}




你可能感兴趣的:(bzoj)