BZOJ 1923 SDOI2010 外星千足虫 异或方程组+bitset

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1923

 

  懒得贴题目了......这就是解一个异或方程组的裸题......

  YY了一下异或方程就没毛病了!

  感受了一下bitset的力量噢噢噢!!!!!!

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<queue>
 8 #include<set>
 9 #include<map>
10 #include<vector>
11 #include<cctype>
12 #include<bitset>
13 using namespace std;
14 const int maxn=1005;
15 const int maxm=2005;
16 
17 int N,M;
18 bool b[maxm],x[maxm];
19 char s[maxn];
20 bitset<maxn>a[maxm];
21 
22 void data_in()
23 {
24     scanf("%d%d",&N,&M);
25     for(int i=1;i<=M;i++){
26         scanf("%s",s+1);
27         for(int j=1;j<=N;j++) a[i][j]=s[j]-'0';
28         scanf("%s",s+1);
29         b[i]=s[1]-'0';
30     }
31 }
32 int Gauss()
33 {
34     int i=1,j=1,re=0;
35     while(i<=M&&j<=N){
36         re=max(re,i);
37         if(!a[i][j]){
38             int tmp=0;
39             for(int r=i+1;r<=M;r++)
40                 if(a[r][j]) { tmp=r; break; }
41             if(!tmp) return 0;
42             re=max(re,tmp);
43             swap(a[i],a[tmp]); swap(b[i],b[tmp]);
44         }
45         for(int r=i+1;r<=M;r++){
46             if(!a[r][j]) continue;
47             a[r]^=a[i],b[r]^=b[i];
48         }
49         i++,j++;
50     }
51     if(j<=N) return 0;
52     for(int r=N;r>=1;r--){
53         x[r]=b[r];
54         for(int rr=r-1;rr>=1;rr--)
55             b[rr]^=1*a[rr][r]*x[r];
56     }
57     return re;
58 }
59 void work()
60 {
61     int ans=0;
62     if(ans=Gauss()){
63         printf("%d\n",ans);
64         for(int i=1;i<=N;i++)
65             puts(x[i]?"?y7M#":"Earth");
66     }
67     else puts("Cannot Determine");
68 }
69 int main()
70 {
71     data_in();
72     work();
73     return 0;
74 }
View Code

 

posted @ 2018-03-22 16:51  KKKorange  阅读(125)  评论(0编辑  收藏  举报