现在的位置: 首页 > 综合 > 正文

LA 3211 Now or later (2 – SAT) – from lanshui_Yang

2018年02月21日 ⁄ 综合 ⁄ 共 5667字 ⁄ 字号 评论关闭

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 (see Figure 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 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.

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 is reported in Table 1 (column ``Solution''). In this solution, the aircraft land in the following order: A8A1A6A10A3A9A2A7A5A4.
The security gap is realized by aircraft A1 and A6.

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$ \le$n$ \le$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$ \le$t$ \le$107.

Output 

For each input case, your program has to write a line that conttains the maximal 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. It can then be stated as follows: Given an integer p, and an instance of the optimization problem, the question is to decide if there is a solution with
security gap p or not. Note that, if you know how to solve the decision variant of an optimization problem, you can build 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 satisfaction problem. Robert suggests to associate a boolean variable per aircraft stating whether the aircraft is early (variable takes value
``true'') or late (value ``false''). It should then be easy to see that for some aircraft to land at some time 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 A3has to land late. And of course, if aircraft A3 lands early, then aircraft A1 has to land late.
That is, aircraft A1 and A3 cannot both land early and formula (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 架飞机,每架飞机都有两个着陆时间,一个是早着陆时间 E ,另一个是晚着陆时间 L 。每架飞机只能选择一种方式着陆,并且两架飞机不能在同一时间降落。两个相邻的着陆时间 的差值的最小值成为安全间隙时间。现在请你安排每架飞机的着陆方式使得安全间隙时间最大。

    解题思路:找安全间隙时间的最大值可以用二分的方式。对于一架飞机来说,要么选择早着陆,要么选择晚着陆,相当于对于一个条件 X , X 要么为真,要么为假,这就符合了2 - SAT 的基本特征 ,假设第i架飞机早着陆 为真 用
X2i
表示,晚着陆 为真 用X2i+1 表示,下面说一下如何建图:

     1、对于一个安全间隙时间 t ,举个例子:如果 Ei - Ej < t (即 不能同时安排 第i架飞机早着陆 和 第j架飞机早着陆),即X2i
与 
X2j不能同时为真, 即条件为  !(X2i && X2j)
<==> (!
X2i||
X2j),这就满足了2 - SAT 的条件。

    2、要满足上面的条件,连边 2i -> 2j + 1 和 2j -> 2i + 1 即可。

    Ps:2 - SAT 问题的建图要想明白,还有就是注意 位运算 的灵活运用。

    代码如下:

#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<queue>
#define mem(a , b) memset(a , b , sizeof(a))
using namespace std ;
const int MAXN = 2005 ;
int tm[MAXN * 2] ; // 存放时间
bool mark[MAXN * 2] ;
vector<int> G[MAXN * 2] ;
int S[MAXN * 2] , c ;  // 模拟栈
int n ;
int le , r , mid ;
void init()  // 输入
{
    r = 0 ;
    int i ;
    for(i = 0 ; i < n ; i ++)
    {
        int a , b ;
        scanf("%d%d" , &a , &b) ;
        tm[i << 1] = a ;  // tm[i * 2] 代表第 i 架飞机的早着陆时间
        r = max(a , r) ;
        tm[(i << 1) + 1] = b ; // tm[i * 2 + 1] 代表 第 i 架飞机的晚着陆时间
        r = max(b , r) ;
    }
}
void chu() // 清空图
{
    int i ;
    for(i = 0 ; i < n * 2 ; i ++)
    {
        G[i].clear() ;
    }
}
void add_e(int x , int y)  // 向图中添加边
{
    G[x].push_back(y ^ 1) ;
    G[y].push_back(x ^ 1) ;
}
void build_G(int t)  // 建图
{
    chu() ;
    int i , j ;
    for(i = 0 ; i < n * 2 ; i ++)
    {
        for(j = i + 1 ; j < n * 2 ; j ++)
        {
            if(j == (i ^ 1) )
                continue ;
            if(abs(tm[i] - tm[j]) < t)
            {
                add_e(i , j) ;
            }
        }
    }
}
bool dfs(int x)
{
    if(mark[x ^ 1]) return false ;
    if(mark[x]) return true ;
    mark[x] = true ;
    S[c ++] = x ;
    int i ;
    for(i = 0 ; i < G[x].size() ; i ++)
    {
        if(!dfs(G[x][i]))
        return false ;
    }
    return true ;
}
int can(int t)
{
    build_G(t) ;
    mem(mark , 0) ;
    int i ;
    for(i = 0 ; i < n ; i ++)
    {
        if(!mark[i * 2] && !mark[i * 2 + 1])
        {
            c = 0 ;
            if(!dfs(i * 2))
            {
                while (c > 0)
                {
                    mark[S[-- c]] = false ;
                }
                if(!dfs(i * 2 + 1))
                {
                    return 0 ;
                }
            }
        }
    }
    return 1 ;
}
void solve()
{
    le = 0 ;
    while (le < r)
    {
        mid = le + (r - le + 1) / 2 ;  // 注意此处求 mid 的方法,这是二分的一个技巧!!
        if(can(mid))
        {
            le = mid ;
        }
        else
        {
            r = mid - 1 ;
        }
    }
    printf("%d\n" , le) ;
}
int main()
{
    while (scanf("%d" , &n) != EOF)
    {
        init() ;
        solve() ;
    }
    return 0 ;
}


 

抱歉!评论已关闭.