【P2447 [SDOI2010]外星千足虫】 题解

题目链接:https://www.luogu.org/problemnew/show/P2447

dalao们都说简单...解异或方程组

可我不是dalao qwq

 1 #include <algorithm>
 2 #include <cstdio>
 3 #include <cmath>
 4 #include <iostream>
 5 #include <bitset>
 6 using namespace std;
 7 const int maxn = 2500;
 8 const double eps = 1e-7;
 9 char s[maxn];
10 bitset<maxn> A[maxn];
11 int n, m, ans[maxn], flag;
12 bool check;
13 int main() 
14 {
15     scanf("%d%d",&n,&m);
16     for(int i = 1; i <= m; i++)
17     {
18         scanf("%s",s+1);
19         for(int j = 1; j <= n; j++)
20         A[i][j] = s[j]-'0';
21         int p;
22         scanf("%d",&p);
23         A[i][n+1] = p;
24     }
25     for(int i = 1; i <= n; i++)
26     {
27         int p = i;
28         while(p < m+1 && !A[p][i]) p++;
29         if(p == m+1) 
30         {
31             printf("Cannot Determine\n");
32             return 0;        
33         }
34         else flag = max(flag, p);
35         if(i != p) swap(A[i],A[p]);    
36         for(int j = i + 1; j <= m; j++)
37         if(A[j][i]) A[j]^=A[i];
38     }
39     ans[n] = A[n][n+1];
40     for(int i = n - 1; i >= 1; i--)
41     {
42         ans[i] = A[i][n+1];
43         for(int j = i + 1; j <= n; j++)
44             ans[i] ^= ans[j] * A[i][j];    
45     }
46     printf("%d\n",flag);
47     for(int i = 1; i <= n; i++)
48     {
49         if(ans[i] == 0) printf("Earth\n");
50         if(ans[i] == 1) printf("?y7M#\n");
51     }
52     return 0;
53 }

 

posted @ 2018-05-05 21:23  Misaka_Azusa  阅读(208)  评论(0编辑  收藏  举报
Live2D