[Exam reflection] 0308 provincial election simulation 40: Observation

 

Today, when the examination coach after 10:30 the language changed to $ C ++ $ from $ C ++ 11 $

And wrote the compiler parameters on $ OJ $ game interface.

However, in the $ pdf $ in the waves, I did not notice what is wrong.

Ok. . . You know what I want to express. .

Blue is $ 0 $ ah ah ah. . . I guess I was the league's most often the CE. .

If not, then CE will be more than $ 22pts $. It is $ rk3 $.

Details Write hung, the tree is special sentence I write is the number of points equal to the number of edges $ -1 $. Otherwise is $ 50pts $, that is a $ rk2 $

However, there is no "if." Simpleton Simpleton is, the longer it wants in mind.

Very full part of an examination. Tip significance is also quite strong. Very good set of questions.

The $ T1 $ can think part of the idea, but "think essentially" still a lot of difference.

Then $ T2 $, then guess generating function may be regrettable unskilled, and another idea is completely unthinkable, take violence on foot.

$ T3 $ is given to a part of the network flow quite clear, but even want to take the time to write or spend a little more.

 

T1: Coloring Problem

Effect: Unicom undirected graph, $ k $ colors, dyeing node, both ends of each edge different colors. Find a few programs. $ N \ le 10 ^ 5, m \ le n + 5, k \ le 10 ^ 5 $

We found greater than $ m $ $ $ n-much, but Unicom, so almost from the tree structure.

First, for a small point, we can search, when the color is large, with the smallest representation on it.

For a tree, the answer is $ k (k-1) ^ {n-1} $

For a tree ring, and then if we handpicked a ring on a point of color, we found outside the ring portion of the contribution each point is the answer multiplied by $ k-1 $.

That we can continue to get rid of degree $ 1 $ points.

Thus only one ring. Ring found reasons not to do that if you do as a sequence, from beginning to end may be the same.

So we do $ dp $ Kee far ends of the chain color is the number of phases of the program at the same time. We can do it.

And then found, in which case the value of your dp has been transferred to the chain, and only on the two ends of the chain.

So that in addition to the two ends of a chain, the degree are $ 2 $. And we can also be found for a degree is $ 2 $ points, $ dp $ value of its points on both sides can be combined.

Provided at both ends of the same $ f $, $ G $ are different, then there is $ f = f_0f_1 + (k-1) g_0g_1, g = f_0g_1 + f_1g_0 + (k-2) g_0g_1 $

So this point disappeared two sides also combined into a new edge.

In this way, there is no degree of Ituri is $ 2 $ a point.

Because $ mn \ le 5 $ degrees so figure $ \ geq 3 $ a few points, you can search.

For the three-membered ring, we finally put it shrunk to $ 2 $ points would be better treated.

Support plus side the border erase it, not directly with the complexity of the array, $ map / vector $ looks like you can use, but with $ set $ write better code.

(Do not think $ unordered $ friends, about $ C ++ 11 $, it is dead)

Listen $ LNC $ can say with $ mutable $, good giant ah, good code is written and less constant.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define mod 1000000007
 4 #define S 100005
 5 struct P{
 6     int to,f,g;
 7     P(){} P(int a,int b,int c): to(a),f(b),g(c){}
 8     friend bool operator<(P x,P y){return x.to<y.to||(x.to==y.to&&x.g+x.f<y.g+y.f);}
 9 };multiset<P>s[S];
10 int n,m,k,rt=1,ans,co[S],A[S],q[S],ald[S],t;
11 void sch(int al,int alc){
12     if(al==t+1){
13         int a=1;
14         for(int i=1;i<=t;++i)for(set<P>::iterator it=s[q[i]].begin();it!=s[q[i]].end();++it)
15             if((*it).to>=q[i])a=1ll*a*(co[q[i]]==co[(*it).to]?(*it).f:(*it).g)%mod;
16         ans=(ans+1ll*a*rt%mod*A[alc])%mod;
17         return;
18     }for(int i=1;i<=k&&i<=alc+1;++i)co[q[al]]=i,sch(al+1,max(alc,i));
19 }
20 int main(){//freopen("0.in","r",stdin);
21     cin>>n>>m>>k;
22     for(int i=A[0]=1;i<=n||i<=k;++i)A[i]=A[i-1]*(k-i+1ll)%mod;
23     for(int i=1,a,b;i<=m;++i){
24         scanf("%d%d",&a,&b);
25         s[a].insert(P(b,0,1));s[b].insert(P(a,0,1));
26     }
27     for(int i=1;i<=n;++i)if(s[i].size()==1)q[++t]=i;
28     for(int h=1,p;p=q[h],h<=t;++h)if(s[p].size()==1){
29         int u=(*s[p].begin()).to; s[u].erase(s[u].lower_bound(P(p,0,0)));
30         if(s[u].size()==1)q[++t]=u; ald[p]=1; rt=rt*(k-1ll)%mod;
31     }
32     for(int i=1;i<=n;++i)if(s[i].size()==2){
33         P x=*s[i].begin(),y=*(--s[i].end());
34         if(x.to==y.to)continue; ald[i]=1;
35         s[x.to].erase(s[x.to].lower_bound(P(i,0,0)));
36         s[y.to].erase(s[y.to].lower_bound(P(i,0,0)));
37         s[x.to].insert(P(y.to,(1ll*x.f*y.f+(k-1ll)*x.g%mod*y.g)%mod,((k-2ll)*x.g%mod*y.g+1ll*x.f*y.g+1ll*x.g*y.f)%mod));
38         s[y.to].insert(P(x.to,(1ll*x.f*y.f+(k-1ll)*x.g%mod*y.g)%mod,((k-2ll)*x.g%mod*y.g+1ll*x.f*y.g+1ll*x.g*y.f)%mod));
39     }t=0;
40     for(int i=1;i<=n;++i)if(!ald[i])q[++t]=i;
41     sch(1,0);
42     cout<<ans<<endl;
43 }
View Code

 

T2: IOer

大意:给定$n,m,u,v$求$\sum\limits_{A}[\sum\limits_{x=1}^{m} A_x = n] \prod\limits_{x=1}^{m} (v_ui)^{A_i}$。$n \le 10^{18},m\le  2 \times 10^5,u,v \le 10^9$

It seems nothing to say, explanations thinking too pure surprising. The difficulty lies in the meaning of the questions transformation.

Easy to understand bad thought.

It wants to. Stick coming.

 

 

 

 

 

 It can also be used in addition to $ $ LNC who heard generating function to carry out his appreciated, a large number of push equation.

Several ideas focus on: the exact same sequence of elements ignore their internal requirements, in addition to the final factorial.

And the "critical point" is also embodied as a ball, similar to the idea of ​​card, so you can force it to appear.

In fact, nothing new, but it is hard to think of. Shake the clever

However, the code is actually really good writing

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define mod 998244353
 4 #define S 200005
 5 int qp(int b,long long t,int a=1){for(;t;t>>=1,b=1ll*b*b%mod)if(t&1)a=1ll*a*b%mod;return a;}
 6 long long n;int t,m,u,v,fac[S],inv[S],ans;
 7 int main(){
 8     for(int i=fac[0]=1;i<S;++i)fac[i]=1ll*fac[i-1]*i%mod;
 9     inv[S-1]=qp(fac[S-1],mod-2);
10     for(int i=S-2;~i;--i)inv[i]=inv[i+1]*(i+1ll)%mod;
11     cin>>t;while(t--){
12         cin>>n>>m>>u>>v;ans=0;
13         for(int i=0;i<m;++i)ans=(ans+(i&1?mod-1ll:1ll)*inv[m-1-i]%mod*inv[i]%mod*qp((1ll*(m-i)*u+v)%mod,n+m-1))%mod;
14         cout<<1ll*ans*qp(u,(m-1ll)*(mod-2))%mod<<endl;
15     }
16 }
View Code

 

T3:deadline

Effect: $ n $ $ m $ day tasks. Each task has a wide $ 0 / $ 1, $ k $ relationship has the form: a first U $ $ $ day may be the first task V $.

Requires you to specify a schedule agreed to do which $ 0 / $ 1 class tasks every day, then the other side will meet under the premise of do the task schedule as much as possible. Minimize the number of final completion of the task.

$ N, m \ 2000, k \ le $ 5000

A very intuitive network flow. Minimum cut.

All $ 0 $ class Duties source $ 1 $ class task even exchange, then two points for each built in a day even $ 1 $ edges. Then the task to the corresponding side even days.

If the sides do not want the day off, that is, if this day do not want to do the task, it requires day $ 0 / $ 1 in at least one type of task to be done, which is cut off.

So right. Network stream is not that complexity.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define S 66666
 4 int n,m,k,t[S],o[S][2],pc,q[S],d[S],v[S],fir[S],l[S],to[S],ec=1,ans;
 5 void link(int a,int b,int w){l[++ec]=fir[a];fir[a]=ec;to[ec]=b;v[ec]=w;}
 6 void con(int a,int b){link(a,b,1);link(b,a,0);}
 7 bool bfs(){
 8     for(int i=1;i<=pc;++i)d[i]=pc+1;
 9     for(int h=1,t=1;h<=t;++h)for(int i=fir[q[h]];i;i=l[i])if(v[i]&&d[to[i]]>d[q[h]]+1)
10         d[q[++t]=to[i]]=d[q[h]]+1;
11     return d[pc]<=pc;
12 }
13 int dfs(int p,int f){
14     if(p==pc)return f; int r=f;
15     for(int i=fir[p];i&&r;i=l[i])if(v[i]&&d[to[i]]==d[p]+1){
16         int x=dfs(to[i],1);
17         if(!x)d[to[i]]=-1;
18         else v[i]--,v[i^1]++,r--;
19     }return f-r;
20 }
21 int main(){
22     scanf("%d%d%d",&n,&m,&k);
23     pc=n;
24     for(int i=1;i<=m;++i)o[i][0]=++pc,o[i][1]=++pc,con(pc-1,pc);
25     ++pc;
26     for(int i=1;i<=n;++i)scanf("%d",&t[i]);
27     for(int i=1;i<=n;++i)if(t[i])con(i,pc);else con(0,i);
28     for(int i=1,x,y;i<=k;++i){
29         scanf("%d%d",&y,&x);
30         if(t[y])con(o[x][1],y);
31         else con(y,o[x][0]);
32     }
33     while(bfs())ans+=dfs(0,n);
34     cout<<ans<<endl;
35 }
View Code

 

Guess you like

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