LA 3211

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

  1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <algorithm>
5 #include <stack>
6 #include <vector>
7 #include <cmath>
8
9 using namespace std;
10
11 const int MAX_N = 4005;
12 int N,dfs_clock,scc_cnt;
13 int low[MAX_N],pre[MAX_N],cmp[MAX_N];
14 int E[MAX_N],L[MAX_N];
15 stack<int> S;
16 vector<int> G[MAX_N];
17
18 void dfs(int u) {
19 low[u] = pre[u] = ++dfs_clock;
20 S.push(u);
21 for(int i = 0; i < G[u].size(); ++i) {
22 int v = G[u][i];
23 if(!pre[v]) {
24 dfs(v);
25 low[u] = min(low[u],low[v]);
26 } else if(!cmp[v]) {
27 low[u] = min(low[u],pre[v]);
28 }
29 }
30
31 if(pre[u] == low[u]) {
32 ++scc_cnt;
33 for(;;) {
34 int x = S.top(); S.pop();
35 cmp[x] = scc_cnt;
36 if(x == u) break;
37 }
38 }
39 }
40
41 void scc() {
42 dfs_clock = scc_cnt = 0;
43 memset(cmp,0,sizeof(cmp));
44 memset(pre,0,sizeof(pre));
45
46 for(int i = 1; i <= 2 * N; ++i){
47 if(!pre[i]) dfs(i);
48 }
49 }
50
51 bool check(int x) {
52 for(int i = 1; i <= 2 * N; ++i) G[i].clear();
53
54 for(int i = 1; i <= N; ++i) {
55 for(int j = 1; j <= N; ++j) {
56 if(i == j) continue;
57 if(abs(E[i] - E[j]) < x) {
58 G[i].push_back(j + N);
59 G[j].push_back(i + N);
60 }
61 if(abs(E[i] - L[j]) < x) {
62 G[i].push_back(j);
63 G[j + N].push_back(i + N);
64 }
65 if(abs(L[i] - E[j]) < x) {
66 G[i + N].push_back(j + N);
67 G[j].push_back(i);
68 }
69 if(abs(L[i] - L[j]) < x) {
70 G[i + N].push_back(j);
71 G[j + N].push_back(i);
72 }
73
74 }
75 }
76
77 scc();
78 for(int i = 1; i <= N; ++i) if(cmp[i] == cmp[i + N]) return false;
79 return true;
80 }
81
82 void solve() {
83 int l = 0,r = 0;
84 for(int i = 1; i <= N; ++i) {
85 r = max(r,E[i]);
86 r = max(r,L[i]);
87 }
88
89 while(l < r) {
90 int mid = (l + r + 1) / 2;
91 if(check(mid)) l = mid;
92 else r = mid - 1;
93 }
94
95 printf("%d\n",l);
96
97 }
98
99 int main()
100 {
101 //freopen("sw.in","r",stdin);
102 while(~scanf("%d",&N)) {
103 for(int i = 1; i <= N; ++i) {
104 scanf("%d%d",&E[i],&L[i]);
105 }
106
107 solve();
108 }
109 //cout << "Hello world!" << endl;
110 return 0;
111 }

LA 3211,码迷,mamicode.com

时间: 2024-10-06 12:15:34

LA 3211的相关文章

LA 3211 飞机调度(2—SAT)

https://vjudge.net/problem/UVALive-3211 题意: 有n架飞机需要着陆,每架飞机都可以选择“早着陆”和“晚着陆”两种方式之一,且必须选择一种,第i架飞机的早着陆时间为E,晚着陆时间为L,不得在其他时间着陆.你的任务是为这些飞机安排着陆方式,使得整个着陆计划尽量安全.换句话说,如果把所有飞机的实际着陆时间按照从早到晚的顺序排列,相邻两个着陆时间间隔的最小值. 思路: 二分查找最大值P,每次都用2—SAT判断是否可行. 1 #include<iostream>

6.12白书第五章图论总结——司雨寒

之前我的图论一直都是DFS一下,BFS一下,求个欧拉回路,拓扑排个序这种渣渣水平. 终于鼓起勇气拾起白书第五章的东西. 学(bei)习(song)了一下求双连通分量,二分图的判定,强连通分量,2-SAT. DFS加上时间戳这个东西,很强大. 最后刷了白书上的例题: BCC: LA3523 可以参加会议的是双联通分量上的奇圈 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include

2-SAT 问题与解法小结

2-SAT 问题与解法小结 这个算法十分的奇妙qwq... 将一类判定问题转换为图论问题,然后就很容易解决了. 本文有一些地方摘录了一下赵爽<2-SAT解法浅析> (侵删) 一些概念: \(SAT\)问题:就是给一些布尔变量赋值,使得所有给你的条件成立的问题---适定性(Satisfiability)问题.我们令\(k\)为所有条件中含有变量的最大值,那么我们就可以称其为\(k-SAT\)问题. 可以证明\(k>2\)时候为NP完全问题,而\(k=2\)的时候存在多项式解法. \(2-S

hdu 5745 la vie en rose

这道题的官方题解是dp,但是可以暴力出来.改天再研究怎么dp. 暴力的时候,如果计算sum的时候,调用strlen函数会超时,可见这个函数并不是十分的好.以后能不用尽量不用. La Vie en rose Time Limit: 14000/7000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 861    Accepted Submission(s): 461 Problem

让MAC OS也能使用LL LA L等LS的别名

linux下默认ll是ls -l的别名.OS X下默认不支持.习惯了linux下使用ll,我们同样也可以将习惯搬到os x下的shell中. 再当前用户家目录下新建.bash_profile文件.根据你的习惯,添加下面格式内容即可. 1 2 3 alias ll='ls -l' alias la='ls -a' alias l='ls -la' 然后执行:source .bash_profile你还可以添加你喜欢的其他别名.

ZOJ 3211 Dream City (J) DP

Dream City Time Limit: 1 Second      Memory Limit: 32768 KB JAVAMAN is visiting Dream City and he sees a yard of gold coin trees. There are n trees in the yard. Let's call them tree 1, tree 2 ...and tree n. At the first day, each tree i has ai coins

LA 3942 Remember the Word (Trie)

Remember the Word 题目:链接 题意:给出一个有S个不同单词组成的字典和一个长字符串.把这个字符串分解成若干个单词的连接(单词可以重复使用),有多少种方法? 思路:令d[i]表示从字符i开始的字符串(后缀s[i..L])的分解数,这d[i] = sum{d(i+len(x)) | 单词x是其前缀}.然后将所有单词建成一个Trie树,就可以将搜索单词的复杂度降低. 代码: #include<map> #include<set> #include<queue>

LA 2678 Subsequence

有一个正整数序列,求最短的子序列使得其和大于等于S,并输出最短的长度. 用数组b[i]存放序列的前i项和,所以b[i]是递增的. 遍历终点j,然后在区间[0, j)里二分查找满足b[j]-b[i]≥S的最大的i,时间复杂度为O(nlongn). 这里二分查找用到库函数lower_bound() 1 //#define LOCAL 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #inclu

LA 4127 - The Sky is the Limit (离散化 扫描线 几何模板)

题目链接 非原创 原创地址:http://blog.csdn.net/jingqi814/article/details/26117241 题意:输入n座山的信息(山的横坐标,高度,山底宽度),计算他们的轮廓线, 即露出来的表面边长,有些山是重叠的不计.空白地带不计,每座山都是等腰三角形. 分析:大白书P414页. 求小山的总长度,用一些虚线将其离散化,分成一段一段的,特征点:山脚,山顶,交点.这样就能保 证相邻两个扫描点之间再无交点.然后一最上面的点就是分割点,维护上一个点lastp即可. 1