[Exam reflection] 0309 provincial election simulation 41: Breakthrough

 

 

 

A person is not in the title of the highest points. But what use it.

The three most violent, add up top, but a $ AC $

On the one hand is not focused thinking, on the other hand is a timing too dispersed.

Each question time is not long enough to stay on a result did not want to come out.

Obviously did not go how God but the feeling did not think how it looked on the 10 o'clock. And then they are forced to play violent.

Change the topic efficiency is not high, see large data structures on $ T2 $ counsels, and has been the Hao Zhao. . .

 

T1: To change of name

Effect: Given $ $ n-string, a nonempty sequence requires each string selected pairwise disjoint, the longest as short as possible. Output program. $ N, maxlen \ le 300 $

First, a roughly idea that for each string, to which all even sides of the sub-sequences, to build a bipartite graph, to see whether the n-$ $ matching pair.

And then I found that when a sub-sequence number exceeds $ n-$ string, the string must be able to participate in a match without conflict with the other strings.

So we only need each string shortest seized $ n $ subsequence on it, and finally run the largest network streaming match on the line.

Search sequences of words, to maintain $ nxt [i] [j] [k] $ $ I $ indicates after the first string of positions J $ $ $ k $ next character position. This is something sweep over backwards to get.

Then the BFS $ $ $ 26 $ per extended characters like, can be found so that the length can be obtained incremented lexicographically increasing the string.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 map<string,int>M;
 4 int nxt[333][333][33],n,len[333],pc,q[333],cnt,mxf,fir[123456],l[999999],to[999999],ec=1,w[999999],d[123456],Q[123456];
 5 string qs[333],ans[333],res[99999];char s[333][333];
 6 vector<int>v[333];
 7 void link(int a,int b,int W){l[++ec]=fir[a];fir[a]=ec;to[ec]=b;w[ec]=W;}
 8 void con(int a,int b,int W){link(a,b,W);link(b,a,0);}
 9 bool bfs(){
10     for(int i=1;i<=cnt+n+1;++i)d[i]=cnt+n+2;
11     for(int h=1,t=1;h<=t;++h)for(int i=fir[Q[h]];i;i=l[i])if(d[to[i]]>d[Q[h]]+1&&w[i])
12         d[Q[++t]=to[i]]=d[Q[h]]+1;
13     return d[cnt+n+1]<cnt+n+2;
14 }
15 int dfs(int p,int f){int r=f;
16     if(p==cnt+n+1)return f;
17     for(int i=fir[p];i&&r;i=l[i])if(w[i]&&d[to[i]]==d[p]+1){
18         int x=dfs(to[i],1);
19         if(!x)d[to[i]]=0;
20         w[i]-=x;w[i^1]+=x;r-=x;
21     }return f-r;
22 }
23 int main(){
24     scanf("%d",&n);
25     for(int i=1;i<=n;++i)scanf("%s",s[i]+1),len[i]=strlen(s[i]+1);
26     for(int i=1;i<=n;++i)for(int j=len[i];j;--j){
27         for(int c=0;c<26;++c)nxt[i][j-1][c]=nxt[i][j][c];
28         nxt[i][j-1][s[i][j]-'a']=j;
29     }
30     for(int i=1;i<=n;++i)for(int h=1,t=1;h<=t;++h)for(int c=0;c<26;++c)if(t-1<=n&&nxt[i][q[h]][c]){
31         qs[++t]=qs[h]+(char)('a'+c);q[t]=nxt[i][q[h]][c];
32         if(!M[qs[t]])M[qs[t]]=++cnt,res[cnt]=qs[t];
33         v[i].push_back(M[qs[t]]);
34     }
35     for(int i=1;i<=cnt;++i)con(0,i,0);
36     for(int i=1;i<=n;++i)for(auto j:v[i])con(j,i+cnt,1);
37     for(int i=1;i<=n;++i)con(i+cnt,cnt+n+1,1);
38     for(int I=1;I<=n;++I){
39         for(int i=fir[0];i;i=l[i])if(res[to[i]].size()==I)w[i]++;
40         while(bfs())mxf+=dfs(0,n);
41         if(mxf==n){
42             cout<<I<<endl;
43             for(int i=fir[0];i;i=l[i])if(!w[i])for(int j=fir[to[i]];j;j=l[j])
44                 if(to[j]&&!w[j])ans[to[j]-cnt]=res[to[i]];
45             for(int i=1;i<=n;++i)cout<<ans[i]<<endl;
46             return 0;
47         }
48     }puts("-1");
49 }
View Code

 

 T2: the dynamic half plane cross

 Effect: the tree, the right point. Repeatedly asking $ p $ subtree distance of not more than $ u $ dot dot right $ lcm $. $ N \ le 10 ^ 5, a_i \ le 10 ^ 7 $

 Large data structure, the first pigeon.

 

T3: get places

Effect: the number of columns, seeking $ 1- \ prod \ limits_ {i = l} ^ {r} (1- \ frac {a_i} {x}) $. Repeatedly asked given $ l, r, x $. $ N, q \ le 6 \ times 10 ^ 5, eps = 10 ^ {- 9} $ 

If we find that each $ a_i $ singled out the biggest, and so the answer will converge quickly.

Then for $ \ frac {a_i} {x}> 0.5 $ to find the maximum value of the constant interval on both sides of the recursive like. $ Log $ layer gets the job done.

$ A_i $ small for how to do?

Multiplies them hard to deal with, we know that $ \ prod a_i = exp (\ sum ln a_i) $

We also know that $ ln (1-x) = \ sum \ limits_ {j = 1} ^ {+ \ infty} \ frac {x ^ j} {j} $

This is a classic Taylor expansion, as long as the pretreatment $ a_i ^ j $ prefix and, a $ 20 $ iterative round just fine.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define S 666666
 4 long double a[S],pre[28][S],ST[28][S],ans,x;int STp[28][S],hb[S],A[S],n,mx,m;
 5 void DaC(int l,int r){
 6     if(l>r)return;
 7     if(ans<1e-7)return;
 8     int B=hb[r-l+1],P;double m;
 9     if(ST[B][l]>ST[B][r-(1<<B)+1])m=ST[B][l]/x,P=STp[B][l];
10     else m=ST[B][r-(1<<B)+1]/x,P=STp[B][r-(1<<B)+1];
11     if(m>0.4)ans*=1-m,DaC(l,P-1),DaC(P+1,r);
12     else{
13         double sum=0,pw=x;
14         for(int i=1;i<27;++i)sum+=(pre[i][r]-pre[i][l-1])/pw/i,pw*=x;
15         ans*=exp(-sum);
16     }
17 }
18 int main(){
19     scanf("%d%d",&n,&m);
20     for(int i=1;i<=n;++i)scanf("%d",&A[i]),mx=max(A[i],mx);
21     for(int i=200075;i<=200125;++i)cerr<<A[i]<<endl;
22     for(int i=1;i<=n;++i)a[i]=1.*A[i]/mx;
23     for(int i=1;i<=n;++i){
24         long double pw=a[i];
25         for(int j=1;j<27;++j)pre[j][i]=pre[j][i-1]+pw,pw*=a[i];
26     }
27     for(int i=1;i<=n;++i)ST[0][i]=a[i],STp[0][i]=i;
28     for(int j=1;1<<j<n;++j)for(int i=1;i+(1<<j)-1<=n;++i)
29         if(ST[j-1][i]>ST[j-1][i+(1<<j-1)])ST[j][i]=ST[j-1][i],STp[j][i]=STp[j-1][i];
30         else ST[j][i]=ST[j-1][i+(1<<j-1)],STp[j][i]=STp[j-1][i+(1<<j-1)];
31     for(int j=0;1<<j<n;++j)for(int i=1<<j;i<1<<j+1&&i<=n;++i)hb[i]=j;
32     while(m--){
33         int l,r,X;scanf("%d%d%d",&l,&r,&X);x=1.*X/mx;
34         ans=1;DaC(l,r);printf("%.10Lf\n",1-ans);
35     }
36 }
View Code

 

Guess you like

Origin www.cnblogs.com/hzoi-DeepinC/p/12458937.html