zoukankan      html  css  js  c++  java
  • la 3211 uva 1146

    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: A8, A1, A6, A10, A3, A9, A2, A7, A5, A4. 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 A3 has 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.

    二分 + 2-SAT,用布尔xi表示飞机i是否在此时间点降落(Ei,或Li),则对一个当前可达最大最小时间间距二分值,枚举所有不同飞机,对|时间间距差| < 二分值的建立约束,使得二者xi, xj不同时满足,具体看代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<vector>
    #include<cstdlib>
    #include<algorithm>
    
    using namespace std;
    
    #define LL long long
    #define ULL unsigned long long
    #define UINT unsigned int
    #define MAX_INT 0x7fffffff
    #define MAX_LL 0x7fffffffffffffff
    #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
    #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
    
    #define MAXN 4444
    
    int t[MAXN>>1][2];
    vector<int> g[MAXN];
    bool mark[MAXN];
    int c, s[MAXN];
    
    bool dfs(int u){
        if(mark[u]) return true;
        if(mark[u^1]) return false;     //因为当前要表记u为真,但u^1已经为真,所以矛盾。
        mark[u]=true;   s[c++]=u;
        int i, tl=g[u].size();
        for(i=0; i<tl; i++){
            if(!dfs(g[u][i])) return false;
        }
        return true;
    }
    
    inline void add(int x, int a, int y, int b){
        x=(x<<1) + a;           //hash时间点到图上点
        y=(y<<1) + b;
        g[x].push_back(y^1);    //若x为真,则y必为假,即y^1为真, 这个是在dfs中体现的。
        g[y].push_back(x^1);
    }
    
    bool test(int n, int m){
        int i,j;
        for(i=0; i<n<<1; i++) g[i].clear();
        for(i=0; i<n; i++)
            for(j=i+1; j<n; j++){
                for(int a=0; a<2; a++)          //枚举所有点,加边约束
                    for(int b=0; b<2; b++) if(abs(t[i][a]-t[j][b])<m)
                        add(i, a, j, b);
            }
    
        memset(mark, 0, sizeof(mark));
        for(i=0; i<n<<1; i+=2) if(!mark[i] && !mark[i+1]){
            c=0;
            if(!dfs(i)){
                while(c--) mark[s[c]]=false;
                if(!dfs(i+1)) return false;
            }
        }
        return true;
    }
    
    int main(){
        //freopen("C:\Users\Administrator\Desktop\in.txt","r",stdin);
        int n;
        while(scanf(" %d", &n)==1){
            int i, ub=0;
            for(i=0; i<n; i++){
                scanf(" %d %d", &t[i][0], &t[i][1]);    //early, late
                ub=MAX(ub, t[i][1]);                    //最大时间来自最晚时间
            }
            int l=0, ans=0;
            while(l<=ub){                               //binary search
                int m=(l+ub)>>1;
                if(test(n, m)) {ans=m; l=m+1;}
                else ub=m-1;
            }
            printf("%d
    ", ans);
        }
        return 0;
    }
    
  • 相关阅读:
    SPSS-Friedman 秩和检验-非参数检验-K个相关样本检验 案例解析
    SPSS-多重响应-频率和交叉表案例分析(问卷调查分析)
    SPSS--回归-多元线性回归模型案例解析
    深入理解RunLoop
    杂七杂八集合
    单元测试
    笔记
    http断点续传
    iOS性能优化
    群聊协议
  • 原文地址:https://www.cnblogs.com/ramanujan/p/3311433.html
Copyright © 2011-2022 走看看