[NOIP2013] Station grading problem Solving report

Source: Internet
Author: User
Tags bitset cmath

Mother Egg this way universal group of Water (God) problem has been engaged me for a long time.
One
The first obvious thing is that each train tells the rank relationship between the station and the station, so the topology is the longest.
But the worst way to find a violent build-up is to 500*500, so the complexity of time is O(M N 2 )≈2.5? ten 8 , the constant is quite small. Data water into a dog, so absolutely can live.
Two
So I thought of bitset, each train made a long n boolean vector, after 1, not through 0, the first station left and the last station on the right side of 1,. Then for each station, take all of the vectors where it is located at 1 &, and sweep the vector edge.
The time complexity of doing this can be estimated using a long long simulation of the time complexity of the bitset, which is O(M N 2 - )≈ ten 7 , the constant is even smaller, actually run up actually is similar to 10^6.
Three
Then I looked at the code of a great God and found out that there was a serious O (NM) approach.
We found the station is more troublesome, so consider the dual conversion!!

Let's consider this, for example, the lowest level of the train passing through the train's rank, then the number of trains in the class = the number of stations?
As defined above, the number of trains is naturally less than the rank of the station, and if a station is not the rank of any train, it means that it can drop or rise its own rank until it is the rank of any train?
But the premise is that every station has at least one train passing by, so naturally we just have to add a train passing through all the stations.
In that case, we just need to ask for the rank of the train!

But what about the rank of the train? If there is not a station that allows two trains to pass through it, then it is clear that there is no direct hierarchy between the two trains, and if they do, then it is clear that the level of the train passing through more stations at the intersection will be lower, as the lower-class stations pass through all the high-grade stations!

Be sure to note the place:
① topology requires max!! when it is the longest way to find
② must be on the shoot!

Code (BITSET):

#include <iostream>using namespace STD;#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>inline voidInint&AMP;X) {CharC=getchar (); x=0; while(c<' 0 '|| C>' 9 ') C=getchar (); for(; c>=' 0 '&&c<=' 9 '; C=getchar ()) x=x*Ten+ (c^' 0 ');}intl[1005],r[1005];#include <bitset> bitset<1005>be[1005],btmp;intnext[1000005],ptr[1005],succ[1000005];int Stack[1005],level[1005],ru[1005];intMain () {Freopen ("Level2013.in","R", stdin); Freopen ("Level_ta.out","W", stdout);intN,m,i,j,stop,s; In (n), in (m); for(i=m;i--;) {in (s); In (L[i]); for(--s;--s;) {in (stop); be[i][stop]=1; } in (R[i]); for(J=L[I];J;--J) be[i][j]=1; for(J=R[I];J&LT;=N;++J) be[i][j]=1; }intetot=1; for(i=n;i;--i) {btmp.Set(); for(j=m;j--;)if(L[j]<=i&&i<=r[j]&&be[j][i]) {//cout<< "Get:" <<j<<endl;btmp&=be[j]; } for(J=N;J;--J)if(~btmp[j]) {next[etot]=ptr[i],ptr[i]=etot,succ[etot++]=j;//cout<<i<< "<<j<<": "<<ptr[i]<<" <<next[etot-1]< <endl;++RU[J]; }    }inttop=0; for(i=n;i;--i)if(ru[i]==0){Stack[Top++]=i; level[i]=1;//cout<< "first into stack:" <<i<<endl;}intNowlevel; while(top--) {nowlevel=level[Stack[Top]];//cout<< "----" <<stack[top]<< "-----\ n";         for(i=ptr[Stack[Top]]; I;i=next[i]) {Level[succ[i]]=max (level[succ[i]],nowlevel+1);//cout<<i<< ":" <<nowlevel+1<< "<<succ[i]<<endl;            if(--ru[succ[i]]==0)Stack[Top++]=succ[i]; }    }printf("%d\n", *max_element (level+1, level+n+1));}

Code (dual conversion):

#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <iostream>using namespace STD;inline voidInint&AMP;X) {CharC=getchar (); while(c<' 0 '|| C>' 9 ') C=getchar (); x=0; for(; c>=' 0 '&&c<=' 9 '; C=getchar ()) x=x*Ten+ (c^' 0 ');}intnum[1005][1005],stop[1005][1005];int Stack[1005];intnext[1000005],ptr[1005],succ[1000005],ru[1005],etot=1;intlevel[1005];inline voidAddedge (intUintV) {next[etot]=ptr[u],ptr[u]=etot,++ru[v],succ[etot++]=v;}intMain () {Freopen ("Level2013.in","R", stdin); Freopen ("Level2013.out","W", stdout);intn,m,i,j,k,tmp;    In (n), in (m); ++m; for(i=n;i;--i) num[0][i]=stop[0][i]=i; stop[0][0]=n; for(i=m;--i;) {in (stop[i][0]); for(j=1, k=1; j<=stop[i][0];++J) for(In (Stop[i][j]); k<stop[i][j];++k) num[i][k]=j-1; --j; while(k<=n) Num[i][k++]=j; }intL,r; for(i=m;i--;) for(j=i;j--;) {L=max (stop[i][1],stop[j][1])-1; R=min (stop[i][stop[i][0]],stop[j][stop[j][0]]);if(L&LT;=R)if(Num[i][r]-num[i][l]>num[j][r]-num[j][l]) Addedge (I,J);Else if(Num[i][r]-num[i][l]<num[j][r]-num[j][l]) Addedge (j,i); }inttop=0; for(i=m;i--;)if(!ru[i]) {Stack[Top++]=i; level[i]=1; }intNowlevel; while(top--) {nowlevel=level[Stack[Top]] +1; for(i=ptr[Stack[Top]]; I;i=next[i]) {Level[succ[i]]=max (level[succ[i]],nowlevel);if(!--Ru[succ[i]])Stack[Top++]=succ[i]; }    }printf("%d\n", *max_element (Level,level+m));}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

[NOIP2013] Station grading problem Solving report

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.