[Exam reflection] 0208 provincial election simulation 21: Restrictions

Gufen 14 + 35 + 5 = 54.

A zero-loved blue.

Hit $ c ++ 11 $ keyword $ ref $. gain knowledge.

The key is to slow the machine because it is not open $ c ++ 11 $, opened to compile a long time, it has not been found. . .

Read through three questions, did not understand the question. Read it again, and consequently will not. Then he began to think, however, and consequently did not want to come out.

Look up the T2 that is relatively simple (?). Then he began to write. However, little consideration a lot of cases, because of the special nature of the data points to get some part

Then keep thinking positive solutions to both problems remaining, and then there is no much time (?).

This time found that T1 is a very classic problem of the size of the point, I think very troublesome.

The last half an hour left when in a hurry to start writing, finish the cross, CE and I do not know.

Then glanced $ T3 $ of $ 5 to $ points could get away.

Finally, I do not think to go to $ T1 $ write to beat. Wrote a violent, this violence was later determined to get $ 13 $ points.

And then began to run on more than a few sets of shoot, shoot for a wrong one change overnight.

Finally, he began to run on the beat, and then my machine can not stand to shoot, then a roar of my virtual machine stopped working. . .

Ever since, fight violence and so-called positive solutions do not pay up, then the blue is still zero. . .

However, the last $ T1 $ I wrote that really could get $ 35 $ points. . . The reason is not $ AC $ is an array of smaller overhead =

Change the title? I do not know why so smoothly, the exam's questions read explanations it seemed very simple.

T2 and did not write the final positive solution in favor of the idea and wrote the examination room like that, but also on the complexity of the water should not question it. . .

The final positive solutions but also to understand the seems to be quite disgusting so too lazy to write. . .

 

T1: Light

Effect: one color for each point sequence, one color all lamps each operating state will change, an initial no opening. After each operation the query sequence has several very long period of continuous lighting. $ N, m, q \ le 10 ^ 5 $

Unicom number of blocks = the number of edges - points. Points directly open an array of maintenance and the number of edges statistics at each modification.

After the abstract a problem on the graph, we can think of and point size of the practice. Divided according to the number of times the size of some color to appear.

Maintain a variable that "all lit the number of dots on either side of the" For some great colors.

When you modify a small point, it appears stats Contribution to enumerate violence on both sides of the location, and updates the variables.

When you modify a big point, violence enumerate all the major points discussed interaction update the answer, and then update affects the large dot point according to the above-mentioned variables.

So just need to pre-impact between the big points. Time complexity $ O (q \ sqrt (n)) $

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define S 111111
 4 int a[S],cnt[S],al[S],n,m,q,big[345],bc,tot,ed[S],crs[345][345],re[S];
 5 vector<int>v[S];
 6 int main(){
 7     //freopen("2.in","r",stdin);freopen("1.out","w",stdout);
 8     scanf("%d%d%d",&n,&m,&q);
 9     for(int i=1;i<=n;++i){scanf("%d",&a[i]);if(a[i]==a[i-1])i--,n--;}a[n+1]=0;
10     for(int i=1;i<=n;++i)cnt[a[i]]++,v[a[i]].push_back(i);
11     for(int i=1;i<=m;++i)if(cnt[i]>=300)big[++bc]=i,re[i]=bc;
12     for(int i=2;i<=n;++i)crs[re[a[i-1]]][re[a[i]]]++,crs[re[a[i]]][re[a[i-1]]]++;
13     while(q-->0){
14         int x;scanf("%d",&x);
15         if(al[x]){
16             tot-=cnt[x];
17             if(re[x]){
18                 tot+=ed[x];
19                 for(int i=1;i<=bc;++i)if(al[big[i]])tot+=crs[i][re[x]];
20             }else for(int i=0;i<v[x].size();++i)
21                 tot+=al[a[v[x][i]-1]],ed[a[v[x][i]-1]]--,tot+=al[a[v[x][i]+1]],ed[a[v[x][i]+1]]--;
22             al[x]=0;
23         }else{
24             tot+=cnt[x];al[x]=1;
25             if(re[x]){
26                 tot-=ed[x];
27                 for(int i=1;i<=bc;++i)if(al[big[i]])tot-=crs[i][re[x]];
28             }else for(int i=0;i<v[x].size();++i)
29                 tot-=al[a[v[x][i]-1]],ed[a[v[x][i]-1]]++,tot-=al[a[v[x][i]+1]],ed[a[v[x][i]+1]]++;
30         }
31         printf("%d\n",tot);
32     }
33 }
View Code

 

T2: Crossroads

Effect: n traffic lights, countdown when the red light. You all lights m observation time. All the known lamp has a common period, a certain fixed period of time the red to green, green to red a fixed time. Seeking long life cycle. $ Nm \ le 100000 $

For two observation time $ t_1, t_2 $ lamp of the same, if we observe its red light countdown is $ x, y $. Set period $ T $

We know that $ t_1 + x \ equiv t_2 + y (mod \ T) $. Because these two moments are moments green light only once, so the $ T $ congruence in each cycle.

Accordingly column type, built in the side of relations, is the point of observation time, the right side is red countdown difference. Such a construction shown in FIG., Each loop length is a multiple of $ T $ a.

Figure violence built, $ floyd $ find rings, take the smallest ring. Time complexity $ O (nm ^ 2 + m ^ 3) $.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n,m,ans=666666666,e[333][333];vector<vector<int> >v;
 4 int main(){
 5     cin>>m>>n;if(n>300&&m>300)return 0;
 6     v.resize(n+1);
 7     for(int i=1;i<=n;++i)v[i].resize(m+1);
 8     for(int j=1;j<=n;++j)for(int i=1;i<=m;++i)scanf("%d",&v[j][i]);
 9     memset(e,0x3f,sizeof e);
10     if(n>m)for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)if(v[i][j])for(int k=1;k<=m;++k)if(v[i][k]>v[i][j])
11         e[j][k]=min(e[j][k],v[i][k]-v[i][j]);
12     if(n<=m)for(int i=1;i<=m;++i)for(int j=1;j<=n;++j)if(v[j][i])for(int k=1;k<=n;++k)if(v[k][i]>v[j][i])
13         e[j][k]=min(e[j][k],v[k][i]-v[j][i]);
14     for(int i=1;i<=m;++i)e[i][i]=0;
15     for(int i=1;i<=m;++i)for(int j=1;j<=m;++j)for(int k=1;k<=m;++k)e[j][k]=min(e[j][k],e[j][i]+e[i][k]);
16     for(int i=1;i<=m;++i)for(int j=1;j<=m;++j)if(i!=j)ans=min(ans,e[i][j]+e[j][i]);
17     printf("%d\n",ans<666666666?ans:-1);
18 }
View Code

Similarly, we set it for a particular time period is two lamps red end $ t_1, t_2 $, two red lamps at a time countdown $ x, y $. Set period $ T $

We know that $ t1-x \ equiv t2-y (mod \ T) $. As is the current time after doing worse.

Similarly, and above that method, time complexity is $ O (mn ^ 2 + n ^ 3) $

If we based on $ n, m $ size relationship to determine which algorithm to run the above, this complexity is $ nm \ min (n, m) $ a. That $ nm \ sqrt (nm) $

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n,m,ans=666666666,e[333][333];vector<vector<int> >v;
 4 int main(){
 5     cin>>m>>n;
 6     v.resize(n+1);
 7     for(int i=1;i<=n;++i)v[i].resize(m+1);
 8     for(int j=1;j<=n;++j)for(int i=1;i<=m;++i)scanf("%d",&v[j][i]);
 9     memset(e,0x3f,sizeof e);
10     if(n>m)for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)if(v[i][j])for(int k=1;k<=m;++k)if(v[i][k]>v[i][j])
11         e[j][k]=min(e[j][k],v[i][k]-v[i][j]);
12     if(n<=m)for(int i=1;i<=m;++i)for(int j=1;j<=n;++j)if(v[j][i])for(int k=1;k<=n;++k)if(v[k][i]>v[j][i])
13         e[j][k]=min(e[j][k],v[k][i]-v[j][i]);
14     if(n<=m)swap(n,m);
15     for(int i=1;i<=m;++i)e[i][i]=0;
16     for(int i=1;i<=m;++i)for(int j=1;j<=m;++j)for(int k=1;k<=m;++k)e[j][k]=min(e[j][k],e[j][i]+e[i][k]);
17     for(int i=1;i<=m;++i)for(int j=1;j<=m;++j)if(i!=j)ans=min(ans,e[i][j]+e[j][i]);
18     printf("%d\n",ans<666666666?ans:-1);
19 }
View Code

 

T3: Room Escape

Effect: i dots and i + 1 dots even edge, i and i + 1 can reach if each and only if the i-th point has $ a_i $ individual is not moving or $ i + has $ B_i $ 1 $ point number people are not moving. How many people can put up to ask them not to let 1 point sequence.

$ N \ le 1000 $, the right side of $ \ le 10000 $

Dp immortal gods exam cut ah. . .

When the number is large enough we found that a large number of people can think together on where to go. We call the interval they can reach for a while.

Specifically, the period is defined to reach all inner segments anywhere along the segment, which is called section.

Set $ ​​dp [i] [j] $ representation segment $ i $ node number where the individual has $ j $, $ i $ ago at this time how many people can put points.

Players will take the best decisions. So $ dp $ Compare apparently transferred. We dp from $ [i] [j] $ outward expansion.

If $ j <a [i] $ then the people on the $ i $ not right away on their own, so consider release on $ i + 1 $ points, if people put less than $ b [i] $ months that $ i $ dot of people do not go i + 1 $ a.

也即$dp[i+1][0,1,...,b[i]-1]=dp[i][j]+(0,1,...,b[i]-1)$

And if you put people reached $ b [i] $ one left who go out into the right side of the Bay. $ Dp [i + 1] [j + b [i]] = dp [i] [j] + b [i] $

If the number on the left side reached $ a [i] $ less of them $ a [i] $ personally responsible press the button the rest of the people on it right away.

$dp[i+1][j-a[i]]=dp[i][j]$

Not considered the right people in place, and anyway can be put through is the same on the left.

If $ j \ geq a [i] + b [i] $ Even so that both sides of the section of the freely back and forth.

$ Dp [i + 1] [j] = dp [i] [j] $. Because people do not consider the extra left can walk.

The second dimension of the array determine how big? Here we need to understand a little deeper or it will to me $ WA $.

$ 20,000 $. Because for a period if the number of which exceeds 2 times the maximum edge weight it must go 0 to get a good point. Rather than to two times likely to come to the stage.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int dp[1111][21111],a[1111],b[1111],n,m,ans;
 4 int main(){
 5     scanf("%d%d",&n,&m);memset(dp,0x80,sizeof dp);
 6     for(int i=1;i<m;++i)dp[1][i]=i;dp[1][0]=0;
 7     for(int i=1;i<n;++i)scanf("%d%d",&a[i],&b[i]);
 8     for(int i=1;i<n;++i){
 9         int mx=0x80000000;
10         for(int j=0;j<a[i];++j)dp[i+1][j+b[i]]=max(dp[i+1][j+b[i]],dp[i][j]+b[i]),mx=max(mx,dp[i][j]);
11         for(int j=0;j<b[i];++j)dp[i+1][j]=max(dp[i+1][j],mx+j);
12         for(int j=a[i];j<a[i]+b[i];++j)dp[i+1][j-a[i]]=max(dp[i+1][j-a[i]],dp[i][j]);
13         for(int j=a[i]+b[i];j<=20000;++j)dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
14     }for(int i=0;i<=20000;++i)ans=max(ans,dp[n][i]);cout<<ans<<endl;
15 }
View Code

 

Guess you like

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