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. [Prism框架实用分享]如何在主程序中合理的弹出子窗体

    大家好 说起子窗体,大家都会想到ChildWindow,多熟悉的一个控件.不错,Sliverlight中已经提供了子窗体的具体实现,而在WPF中却没有这么好的事情(有的第三方控件商已经提供此控件).最 ...

  2. C# 添加一个用户对文件或者文件夹的所有权限

    private void ModifyFilePermission(string path, string user, FileType filetype) { if (filetype == Fil ...

  3. MongoDB复制机制实例

    MongoDB的主从复制是一个主可以多从已从又可以为主进行主从复制.在这里就是实现一主一从一个仲裁服务器使用一个数据库服务器通过提供不同的端口. 一.启动一个MongoDB服务名字是applicati ...

  4. WIFI 物理组件

    物理组件参考:http://book.51cto.com/art/201404/435813.htm SDIO总线参考:此总线sd卡连接也有关系.(http://www.linuxidc.com/Li ...

  5. sql server 2016 management studio没有的解决方式

    最近安装sql sever2016后发现没有 management studio管理工具,无法操作sql server,可以单独下载安装后即可. 下载地址: https://msdn.microsof ...

  6. R Tools for Visual Studio

    https://www.visualstudio.com/en-us/features/rtvs-vs.aspx https://www.microsoft.com/en-us/cloud-platf ...

  7. 如何快速重置OUTLOOK2013,2016到初始配置状态,outlook 修改数据文件位置

    适用范围: 安装OUTLOOK的机器 知识点分析: 快速清除当前OUTLOOK所有账户,回归到初始配置状态. 操作步骤: WIN+R调出运行 输入: C:\Program Files (x86)\Mi ...

  8. 用js进行日期的加减

    如题,开始查了查js的使用文档,但没发现可以直接用的函数,于是就想自己写函数来着,这就要涉及到每个月天数的判断,如果是2月份的话,还要涉及到闰年的判断,虽然不复杂但我想js应该不会这么低级,于是查了下 ...

  9. 基于Elasticsearch开发时的注意事项备忘

    记录一些自己在Elasticsearch开发过程的琐碎知识点 1.使用ScriptFields时,需在yml配置文件中添加配置(script.disable_dynamic: false)开启动态脚本 ...

  10. WCF 已超过传入消息(65536)的最大消息大小配额。若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性

    我出现这个问题主要是服务器返回数据量过大引起了,需要客户端服务端都要进行配置:我会说其实有神器的么....(工具=>wcf服务配置编辑器),用工具编辑下,就会完全搞定这个问题,再也不用纠结了 服 ...