P3857 [TJOI2008]彩灯(线性基)

题目链接:https://www.luogu.org/problem/P3857

解题报告:

  给出一个序列,让你求出异或后有多少种可能的情况。

  将给的数插入到线性基中,最后答案即为$(1LL<<res)%2008$,res为线性基的种类数。

AC代码:

 1 #include<vector>
 2 #include<cstdio>
 3 #include<iostream>
 4 #include<cmath>
 5 #include<queue>
 6 #include<stack>
 7 #include<cmath>
 8 #include<algorithm>
 9 #define numm ch-48
10 #define pd putchar(' ')
11 #define pn putchar('\n')
12 #define pb push_back
13 #define fi first
14 #define se second
15 #define fre1 freopen("1.txt","r",stdin)
16 #define fre2 freopen("2.txt","w",stdout)
17 using namespace std;
18 template <typename T>
19 void read(T &res) {
20     bool flag=false;char ch;
21     while(!isdigit(ch=getchar())) (ch=='-')&&(flag=true);
22     for(res=numm;isdigit(ch=getchar());res=(res<<1)+(res<<3)+numm);
23     flag&&(res=-res);
24 }
25 template <typename T>
26 void write(T x) {
27     if(x<0) putchar('-'),x=-x;
28     if(x>9) write(x/10);
29     putchar(x%10+'0');
30 }
31 const int maxn=20010;
32 const int N=60;
33 const int inf=0x3f3f3f3f;
34 const int INF=0x7fffffff;
35 typedef long long ll;
36 char s[60];
37 ll a[60],p[60];
38 int n,m;
39 ll get_ans() {
40     for(int i=1;i<=m;i++) {
41         for(int j=52;~j;j--)
42             if(a[i]&(1LL<<j)) {
43                 if(!p[j]) {
44                     p[j]=a[i];
45                     break;
46                 }
47                 a[i]^=p[j];
48             }
49     }
50     ll res=0;
51     for(int j=52;~j;j--)
52         if(p[j]) res++;
53     return (1LL<<res)%2008;
54 }
55 int main()
56 {
57 
58     read(n),read(m);
59     for(int i=1;i<=m;i++) {
60         scanf("%s",s);
61         for(int j=0;j<n;j++)
62             if(s[j]=='O') a[i]^=(1LL<<j);
63     }
64     write(get_ans());
65     return 0;
66 }
代码在这里!

 

转载于:https://www.cnblogs.com/wuliking/p/11272348.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值