LA3211 飞机调度 Now or later-二分法&TwoSet

时间:2023-03-09 15:15:34
LA3211 飞机调度 Now or later-二分法&TwoSet

https://vjudge.net/problem/UVALive-3211

As you must have experienced, instead of landing immediately, an aircraft sometimes waits in a holding loop close to the runway. This holding mechanism is required by air traffic controllers to space apart aircraft as much as possible on the runway (while keeping delays low). It is formally defined as a “holding pattern” and is a predetermined maneuver designed to keep an aircraft within a specified airspace.

Jim Tarjan, an air-traffic controller, has asked his brother Robert to help him to improve the behavior of the airport.

The TRACON area

The Terminal Radar Approach CONtrol (TRACON) controls aircraft approaching and departing when they are between 5 and 50 miles of the airport. In this final scheduling process, air traffic controllers make some aircraft wait before landing. Unfortunately this “waiting” process is complex as aircraft follow predetermined routes and their speed cannot be changed. To reach some degree of flexibility in the process, the basic delaying procedure is to make aircraft follow a holding pattern that has been designed for the TRACON area. Such patterns generate a constant prescribed delay for an aircraft (see Figure 1 for an example). Several holding patterns may exist in the same TRACON.

In the following, we assume that there is a single runway and that when an aircraft enters the TRACON area, it is assigned an early landing time, a late landing time and a possible holding pattern. The early landing time corresponds to the situation where the aircraft does not wait and lands as soon as possible. The late landing time corresponds to the situation where the aircraft waits in the prescribed holding pattern and then lands at that time. We assume that an aircraft enters at most one holding pattern. Hence, the early and late landing times are the only two possible times for the landing.

The security gap is the minimal elapsed time between consecutive landings. The objective is to maximize the security gap. Robert believes that you can help.

Input The input file, that contains all the relevant data, contains several test cases Each test case is described in the following way. The first line contains the number n of aircraft (2 ≤ n ≤ 2000). This line is followed by n lines. Each of these lines contains two integers, which represent the early landing time and the late landing time of an aircraft. Note that all times t are such that 0 ≤ t ≤ 107 .

Output For each input case, your program has to write a line that conttains the maximal security gap between consecutive landings. Note: The input file corresponds to Table 1.

Sample Input 10 44 156 153 182 48 109 160 201 55 186 54 207 55 165 17 58 132 160 87 197

Sample Output 10

//有空再来写翻译和思路,调了好久才AC(事实上就是把和标程不一样的地方改过来...)

 #include<iostream>
 #include<vector>
 #include<cstdio>
 #include<cmath>
 #include<cstring>
 using namespace std;
 ;
 struct TwoSet{
     ],S[maxn*];
     int n,c;
     vector<];
     void init(){
         ;i<n*;i++) G[i].clear();
         memset(mark,,sizeof(mark));
     }
     void add(int x,int xval,int y,int yval){
         x=x*+xval;
         y=y*+yval;
         G[x^].push_back(y);
         G[y^].push_back(x);
     }
     bool dfs(int u){
         ]) return false;
         if(mark[u]) return true;
         mark[u]=;
         S[c++]=u;
         ;i<G[u].size();i++) if(!dfs(G[u][i])) return false;
         return true;
     }
     bool Judge(){
         ;i<n*;i+=){
             ]){
                 c=;
                 if(!dfs(i)){
                     ) mark[S[--c]]=;
                     )) return false;
                 }
             }
         }
         return true;
     }

 };
 TwoSet solver;
 ];
 bool check(int x){
     solver.init();
     ;i<n;i++) ;a<;a++)
         ;j<n;j++) ;b<;b++)
             ,j,b^);
     return solver.Judge();
 }
 int main()
 {
     &&n){
         ,R=;
         solver.n=n;
         ;i<n;i++) ;a<;a++)
         scanf("%d",&T[i][a]),R=max(R,T[i][a]);
         while(L<R){
         )/;
         if(check(M)) L=M;
         ;
         }
         printf("%d\n",L);
     }
     ;
 }