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.
 

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 ( 2n2000). 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 0t107.

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  ¬A3 (A3  ¬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  ¬Ai.

二分答案走2 - sat

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <vector>
#include <cmath> using namespace std; const int MAX_N = ;
int N,dfs_clock,scc_cnt;
int low[MAX_N],pre[MAX_N],cmp[MAX_N];
int E[MAX_N],L[MAX_N];
stack<int> S;
vector<int> G[MAX_N]; void dfs(int u) {
low[u] = pre[u] = ++dfs_clock;
S.push(u);
for(int i = ; i < G[u].size(); ++i) {
int v = G[u][i];
if(!pre[v]) {
dfs(v);
low[u] = min(low[u],low[v]);
} else if(!cmp[v]) {
low[u] = min(low[u],pre[v]);
}
} if(pre[u] == low[u]) {
++scc_cnt;
for(;;) {
int x = S.top(); S.pop();
cmp[x] = scc_cnt;
if(x == u) break;
}
}
} void scc() {
dfs_clock = scc_cnt = ;
memset(cmp,,sizeof(cmp));
memset(pre,,sizeof(pre)); for(int i = ; i <= * N; ++i){
if(!pre[i]) dfs(i);
}
} bool check(int x) {
for(int i = ; i <= * N; ++i) G[i].clear(); for(int i = ; i <= N; ++i) {
for(int j = ; j <= N; ++j) {
if(i == j) continue;
if(abs(E[i] - E[j]) < x) {
G[i].push_back(j + N);
G[j].push_back(i + N);
}
if(abs(E[i] - L[j]) < x) {
G[i].push_back(j);
G[j + N].push_back(i + N);
}
if(abs(L[i] - E[j]) < x) {
G[i + N].push_back(j + N);
G[j].push_back(i);
}
if(abs(L[i] - L[j]) < x) {
G[i + N].push_back(j);
G[j + N].push_back(i);
} }
} scc();
for(int i = ; i <= N; ++i) if(cmp[i] == cmp[i + N]) return false;
return true;
} void solve() {
int l = ,r = ;
for(int i = ; i <= N; ++i) {
r = max(r,E[i]);
r = max(r,L[i]);
} while(l < r) {
int mid = (l + r + ) / ;
if(check(mid)) l = mid;
else r = mid - ;
} printf("%d\n",l); } int main()
{
//freopen("sw.in","r",stdin);
while(~scanf("%d",&N)) {
for(int i = ; i <= N; ++i) {
scanf("%d%d",&E[i],&L[i]);
} solve();
}
//cout << "Hello world!" << endl;
return ;
}

LA 3211的更多相关文章

  1. LA 3211 飞机调度

    题目链接:http://vjudge.net/contest/142615#problem/A 题意:n架飞机,每架可选择两个着落时间.安排一个着陆时间表,使得着陆间隔的最小值最大. 分析: 最小值最 ...

  2. LA 3211 飞机调度(2—SAT)

    https://vjudge.net/problem/UVALive-3211 题意: 有n架飞机需要着陆,每架飞机都可以选择“早着陆”和“晚着陆”两种方式之一,且必须选择一种,第i架飞机的早着陆时间 ...

  3. 飞机调度 Now or Later? LA 3211 (2-SAT问题)

    洛谷题目传送门 题目描述 有n架飞机需要着陆.每架飞机都可以选择“早着陆”和“晚着陆”两种方式之一,且必须选择一种.第i架飞机的早着陆时间为Ei,晚着陆时间为Li,不得在其他时间着陆.你的任务是为这些 ...

  4. 2-SAT 问题与解法小结

    2-SAT 问题与解法小结 这个算法十分的奇妙qwq... 将一类判定问题转换为图论问题,然后就很容易解决了. 本文有一些地方摘录了一下赵爽<2-SAT解法浅析> (侵删) 一些概念: \ ...

  5. leggere la nostra recensione del primo e del secondo

    La terra di mezzo in trail running sembra essere distorto leggermente massima di recente, e gli aggi ...

  6. Le lié à la légèreté semblait être et donc plus simple

    Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...

  7. Mac Pro 使用 ll、la、l等ls的别名命令

    在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输 ...

  8. Linux中的动态库和静态库(.a/.la/.so/.o)

    Linux中的动态库和静态库(.a/.la/.so/.o) Linux中的动态库和静态库(.a/.la/.so/.o) C/C++程序编译的过程 .o文件(目标文件) 创建atoi.o 使用atoi. ...

  9. BZOJ 3211 题解

    3211: 花神游历各国 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 2549  Solved: 946[Submit][Status][Discus ...

随机推荐

  1. WPF工作笔记:本地化支持、主进程通知、两种最常用异步编程方式

    1.本地化支持 (1)重写控件默认的依赖属性LanguageProperty FrameworkElement.LanguageProperty.OverrideMetadata( typeof(Fr ...

  2. L2-015. 互评成绩

    学生互评作业的简单规则是这样定的:每个人的作业会被k个同学评审,得到k个成绩.系统需要去掉一个最高分和一个最低分,将剩下的分数取平均,就得到这个学生的最后成绩.本题就要求你编写这个互评系统的算分模块. ...

  3. poj 1789 Truck History

    题目连接 http://poj.org/problem?id=1789 Truck History Description Advanced Cargo Movement, Ltd. uses tru ...

  4. ios中用drawRect方法绘图的时候设置颜色

    设置画笔颜色可以直接 [[UIColor grayColor] set];就可以设置颜色.

  5. go语言包与包引用

    go语言中包(package)与java中的包(package)非常类似,都是组织代码的方式,而且都和磁盘上的目录结构存在对应关系. go语言中,包名一般为go代码所在的目录名,但是与java不同的是 ...

  6. Android实现入门界面布局

    Android实现入门界面布局 开发工具:Andorid Studio 1.3 运行环境:Android 4.4 KitKat 代码实现 首先是常量的定义,安卓中固定字符串应该定义在常量中. stri ...

  7. Protocol-RS-232/422/485标准

    引: 通常的微处理器都集成有1路或多路硬件UART通道,可以非常方便地实现串行通讯.在工业控制.电力控制.智能仪表等领域中,也常常使用简便易用的串行通讯方式作为数据交换的手段. 但是,在工业控制等环境 ...

  8. mozilla css developer center

    https://developer.mozilla.org/en-US/docs/Web/CSS

  9. 53张牌中找出缺少的牌的花色和点数--raid3,4,5,6的容错原理

    一副扑克牌,抽出一张,要求找出抽出的牌的点数和花色. 算法的主要思想就是用异或运算来确定丢的牌的花色.四种花色分别如下表示:红桃用1(二进制0001)表示,黑桃用2(二进制0010)表示,黑桃用4(0 ...

  10. github 使用体会

    开始使用git: 在本机上安装git,听一些同学说他们当时用的是github的中文版即oschina开源中国,似乎操作更加简便一些,还可以安装tortoisegit,是一个gui界面.不过我想用习惯了 ...