As you must have experienced, instead of landing immediately, anaircraft sometimes waits in a holding loop close to the runway. Thisholding mechanism is required by air traffic controllers to spaceapart aircraft as much as possible on the runway (while keeping delayslow). It is formally defined as a ``holding pattern'' and is a predeterminedmaneuver designed to keep an aircraft within a specified airspace (seeFigure 1 for an example).
Jim Tarjan, an air-traffic controller, has asked his brother Robert tohelp him to improve the behavior of the airport.
The Terminal Radar Approach CONtrol (TRACON) controls aircraftapproaching and departing when they arebetween 5 and 50 miles of the airport. Inthis final scheduling process, air traffic controllers make someaircraft wait before landing. Unfortunately this ``waiting'' processis complex as aircraft follow predetermined routes and their speedcannot be changed. To reach some degree of flexibility in theprocess, the basic delaying procedure is to make aircraft follow aholding pattern that has been designed for the TRACON area. Suchpatterns generate a constant prescribed delay for an aircraft (seeFigure 1 for an example). Several holding patterns may exist in the same TRACON.
In the following, we assume that there is a single runway andthat when an aircraft enters the TRACON area, it is assigned an early landing time, a late landing timeand a possible holdingpattern. The early landing time corresponds to the situation where theaircraft does not wait and lands as soon as possible. The late landingtime corresponds to the situation where the aircraft waits in theprescribed 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 possibletimes for the landing.
The security gap is the minimal elapsed time betweenconsecutive landings. The objective is to maximize the securitygap. Robert believes that you can help.
Assume there are 10 aircraft in the TRACON area. Table 1 provides the corresponding early and late landing times (columns``Early'' and ``Late'').
Aircraft | Early | Late | Solution |
A1 | 44 | 156 | Early |
A2 | 153 | 182 | Early |
A3 | 48 | 109 | Late |
A4 | 160 | 201 | Late |
A5 | 55 | 186 | Late |
A6 | 54 | 207 | Early |
A7 | 55 | 165 | Late |
A8 | 17 | 58 | Early |
A9 | 132 | 160 | Early |
A10 | 87 | 197 | Early |
The maximal security gap is 10 and the corresponding solution isreported in Table 1 (column ``Solution''). In thissolution, the aircraft land in the following order: A8,A1, A6, A10, A3, A9, A2, A7, A5, A4. The security gap is realized byaircraft A1 and A6.
The input file, that contains allthe relevant data, contains several test cases
Each test case is described in the following way. The first line contains the number n of aircraft(2n2000). This line is followed by n lines.Each of these lines contains two integers, which representthe early landing time and the late landing time of an aircraft.Note that all times t are such that 0t107.
For each input case, your program has to write a line that conttains themaximal security gap between consecutive landings.
10 44 156 153 182 48 109 160 201 55 186 54 207 55 165 17 58 132 160 87 197
10
Note: The input file corresponds to Table 1.
Robert's Hints
And now comes Robert's big insight:our problem has a solution, if and only if we have no contradiction.A contradiction being something like Ai ¬Ai.
题意:”n架飞机要着陆。每架飞机都可以选择“早着陆”和“晚着陆”两种方式之一,且必须选择一种。给出早晚着陆时间,求最大安全时间间隔。
分析:2-SAT 水题。二分时间间隔,判断即可。
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int N = 4202;
const int INF = 10000000;
vectorG[N];
int L[N],R[N];
int low[N],dfn[N],vis[N],bel[N],inst[N];
int num,tim;
stackst;
void tarjan(int u)
{
vis[u] = 1;
low[u] = dfn[u] = ++tim;
inst[u] = 1; st.push(u);
for(int i=0; i>1;
// printf("l=%d r=%d m=%d\n",l,r,m);
for(i=1; i<=n; i++) G[i].clear();
for(i=1; i<=(n>>1); i++)
for(j=1; j<=(n>>1); j++) if(i!=j){
int a = abs(L[i]-L[j]);
int b = abs(L[i]-R[j]);
int c = abs(R[i]-L[j]);
int d = abs(R[i]-R[j]);
if(a