bzoj3811 uoj36 玛里苟斯

做题前问了一下miaom,得到了一个奇怪的回答

mmp

这题分类讨论

k=1sb题

k=2按位计算,把每个数看成几个2的幂次的和,按位跑期望

k>2线性基sb题

没了

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #define N 100005
 6 #define M 75
 7 #define ll unsigned long long
 8 using namespace std;
 9 
10 int n,flag; ll ans,res,mod,bin[M],a[N],base[M]; bool f[M][M];
11 void calc(){
12     int i,j;
13     for (i=1; i<=n; i++)
14         for (j=31; j>=0; j--) if (a[i]&bin[j])
15             if (!base[j]){
16                 base[j]=a[i]; break;
17             } else a[i]^=base[j];
18     for (j=n=0; j<32; j++) if (base[j]) a[++n]=base[j];
19 }
20 void solve1(){
21     int i,j,k,t;
22     for (i=0; i<32; i++)
23         for (j=1; j<=n; j++) f[i][j]=(a[j]&bin[i])?1:0;
24     for (i=0; i<32; i++)
25         for (j=0; j<32; j++){
26             for (k=1; k<=n; k++) if (f[i][k]) break;
27             if (k>n) continue;
28             for (k=1; k<=n; k++) if (f[j][k]) break;
29             if (k>n) continue;
30             t=0;
31             for (k=1; k<=n && !t; k++)
32                 if (f[i][k]!=f[j][k]) t=1;
33             if (i+j-1-t<0) res++; else ans+=bin[i+j-1-t];
34             ans+=res>>1; res&=1;
35         }
36     printf("%llu",ans); puts(res?".5":"");
37 }
38 void dfs(int k,ll now){
39     if (k>n){
40         int i; ll u=0,v=1;
41         for (i=1; i<=flag; i++){
42             u*=now; v*=now;
43             u+=v>>n; v&=mod;
44         }
45         ans+=u; res+=v;
46         ans+=res>>n; res&=mod;
47         return;
48     }
49     dfs(k+1,now); dfs(k+1,now^a[k]);
50 }
51 void solve2(){
52     mod=bin[n]-1; dfs(1,0);
53     printf("%llu",ans); puts(res?".5":"");
54 }
55 int main(){
56     scanf("%d%d",&n,&flag); int i;
57     bin[0]=1; for (i=1; i<63; i++) bin[i]=bin[i-1]<<1;
58     for (i=1; i<=n; i++) scanf("%llu",&a[i]);
59     if (flag==1){
60         for (i=1; i<=n; i++) ans|=a[i];
61         printf("%llu",ans>>1); puts((ans&1)?".5":"");
62         return 0;
63     }
64     calc();
65     if (flag==2) solve1(); else solve2();
66     return 0;
67 }

 

posted @ 2017-07-31 11:23  汪立超  阅读(227)  评论(0编辑  收藏  举报