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.


AircraftEarlyLateSolution
A144156Early
A2153182Early
A348109Late
A4160201Late
A555186Late
A654207Early
A755165Late
A81758Early
A9132160Early
A1087197Early


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<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<climits>
using namespace std;
const int N = 4202;
const int INF = 10000000;
vector<int>G[N];
int L[N],R[N];
int low[N],dfn[N],vis[N],bel[N],inst[N];
int num,tim;
stack<int>st;
void tarjan(int u)
{
    vis[u] = 1;
    low[u] = dfn[u] = ++tim;
    inst[u] = 1; st.push(u);
    for(int i=0; i<G[u].size(); i++) {
        int v = G[u][i];
        if(!vis[v]) {
            tarjan(v);
            low[u] = min(low[u],low[v]);
        }
        else if(inst[v]) low[u] = min(low[u],dfn[v]);
    }
    if(low[u] == dfn[u]) {
        int j; ++num;
        do {
            j = st.top(); st.pop();
            inst[j] = 0;
            bel[j] = num;
        } while(j!=u);
    }
}
bool judge(int n)
{
    for(int i=1; i<n; i+=2)
        if(bel[i] == bel[i+1]) return false;
    return true;
}
int main()
{
    int i,j,k,m,n;
    while(scanf("%d",&n) == 1) {
        for(i=1; i<=n; i++) scanf("%d %d",L+i,R+i);
        n<<=1;
        for(i=1; i<=n; i++) G[i].clear();
        int l = 0, r = INF, ans = 0;
        while(l <= r) {
            m = l + r >>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<m) G[i*2-1].push_back(j*2);
                if(b<m) G[i*2-1].push_back(j*2-1);
                if(c<m) G[i*2].push_back(j*2);
                if(d<m) G[i*2].push_back(j*2-1);
            }
            memset(vis,0,sizeof(vis));
            memset(inst,0,sizeof(inst));
            while(!st.empty()) st.pop();
            num = tim = 0;
            for(i=1; i<=n; i++) if(!vis[i]) tarjan(i);
           // for(i=1; i<=n; i+=2) printf("bel[%d] = %d  bel[%d] = %d\n",i,bel[i],i+1,bel[i+1]);
            if(judge(n)) ans = m, l = m+1;
            else r = m-1;
        }
        printf("%d\n",ans);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值