UVA - 1146 Now or later

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).

Figure 1: A simple Holding Pattern as described in a pilot text book.


\epsfbox{p3211.eps}

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

The TRACON area 

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.

Example 

Assume there are 10 aircraft in the TRACON area. Table 1 provides the corresponding early and late landing times (columns``Early'' and ``Late'').


Table 1: A 10 aircraft instance of the problem.


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.

Input 

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(2$ \le$n$ \le$2000). 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 0$ \le$t$ \le$107.

Output 

For each input case, your program has to write a line that conttains themaximal security gap between consecutive landings.

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


Note: The input file corresponds to Table 1.


Robert's Hints

Optimization vs. Decision
Robert advises you to work on the decision variant of the problem. Itcan then be stated as follows: Given an integer p, and an instanceof the optimization problem, the question is to decide if there is asolution with security gap p or not. Note that, if you know how tosolve the decision variant of an optimization problem, you canbuild a binary search algorithm to find the optimal solution.

On decision
Robert believes that the decision variant of the problem can be modeled as a very particular boolean satisfactionproblem.Robert suggests to associate a booleanvariable per aircraft stating whether the aircraft is early (variabletakes value ``true'') or late (value ``false'').It should then be easy to see that for some aircraft to land at sometime has consequences for the landing times of other aircraft.For instance in Table 1 and with a delay of 10,if aircraft A1 lands early, then aircraft A3 has to land late.And of course, if aircraft A3 lands early, thenaircraft A1 has to land late.That is, aircraft A1 and A3 cannot both land early andformula (A1$ \Rightarrow$ ¬A3) $ \wedge$ (A3$ \Rightarrow$ ¬A1) must hold.


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$ \Leftrightarrow$ ¬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


你可能感兴趣的:(2-SAT)