UVALive 3211 Now or later

Now or later

Time Limit: 9000ms

Memory Limit: 131072KB

This problem will be judged on UVALive. Original ID: 3211
64-bit integer IO format: %lld      Java class name: Main

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.

Input

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.

Output

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.

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

Source

Regionals 2004, Europe - Southwestern

解题i:二分+2sat

  1 #include <bits/stdc++.h>
  2 using namespace std;
  3 const int maxn = 5010;
  4 struct arc {
  5     int to,next;
  6     arc(int x = 0,int y = -1) {
  7         to = x;
  8         next = y;
  9     }
 10 };
 11 arc e[maxn*maxn];
 12 int head[maxn],dfn[maxn],low[maxn],belong[maxn];
 13 int tot,cnt,scc,n,m;
 14 bool instack[maxn];
 15 stack<int>stk;
 16 void add(int u,int v) {
 17     e[tot] = arc(v,head[u]);
 18     head[u] = tot++;
 19 }
 20 void init() {
 21     for(int i = 0; i < maxn; i++) {
 22         belong[i] = 0;
 23         low[i] = dfn[i] = 0;
 24         head[i] = -1;
 25         instack[i] = false;
 26     }
 27     while(!stk.empty()) stk.pop();
 28     tot = cnt = scc = 0;
 29 }
 30 void tarjan(int u) {
 31     dfn[u] = low[u] = ++cnt;
 32     instack[u] = true;
 33     stk.push(u);
 34     for(int i = head[u]; ~i; i = e[i].next) {
 35         if(!dfn[e[i].to]) {
 36             tarjan(e[i].to);
 37             if(low[e[i].to] < low[u]) low[u] = low[e[i].to];
 38         } else if(instack[e[i].to] && dfn[e[i].to] < low[u])
 39             low[u] = dfn[e[i].to];
 40     }
 41     if(dfn[u] == low[u]) {
 42         scc++;
 43         int v;
 44         do {
 45             v = stk.top();
 46             stk.pop();
 47             instack[v] = false;
 48             belong[v] = scc;
 49         } while(v != u);
 50     }
 51 }
 52 bool solve() {
 53     for(int i = 0; i < (n<<1); i++)
 54         if(!dfn[i]) tarjan(i);
 55     for(int i = 0; i < n; i++)
 56         if(belong[i] == belong[i+n]) return false;
 57     return true;
 58 }
 59 int tim[maxn][2];
 60 bool check(int t) {
 61     init();
 62     for(int i = 0; i < n; ++i)
 63         for(int j = i+1; j < n; ++j) {
 64             if(abs(tim[i][0] - tim[j][0]) < t) {
 65                 add(i,j+n);
 66                 add(j,i+n);
 67             }
 68             if(abs(tim[i][0] - tim[j][1]) < t) {
 69                 add(i,j);
 70                 add(j+n,i+n);
 71             }
 72             if(abs(tim[i][1] - tim[j][0]) < t) {
 73                 add(i+n,j+n);
 74                 add(j,i);
 75             }
 76             if(abs(tim[i][1] - tim[j][1]) < t) {
 77                 add(i+n,j);
 78                 add(j+n,i);
 79             }
 80         }
 81     for(int i = 0; i < 2*n; ++i)
 82         if(!dfn[i]) tarjan(i);
 83     for(int i = 0; i < n; ++i)
 84         if(belong[i] == belong[i+n]) return false;
 85     return true;
 86 }
 87 int main() {
 88     while(~scanf("%d",&n)) {
 89         int low = 0,high = 0;
 90         for(int i = 0; i < n; ++i) {
 91             for(int j = 0; j < 2; ++j) {
 92                 scanf("%d",tim[i]+j);
 93                 high = max(high,tim[i][j]);
 94             }
 95         }
 96         int ret = -1;
 97         while(low <= high) {
 98             int mid = (low + high)>>1;
 99             if(check(mid)) {
100                 ret = mid;
101                 low = mid+1;
102             } else high = mid-1;
103         }
104         printf("%d\n",ret);
105     }
106     return 0;
107 }

时间: 2024-12-23 06:26:09

UVALive 3211 Now or later的相关文章

two-sat hdu3062 UVALive 3211

2-sat就是给定形如 x=xval or y=yval的若干约数,求是否存在全部满足. 这是一种dfs的算法,参考大白书 hdu3062 基本上是模板题吧,xval和yval都告诉你了. #include<bits/stdc++.h> using namespace std; const int N=(int)2e3+10; int n,m; int mark[N],s[N],top=0; vector<int> g[N]; bool dfs(int x) { if(mark[x

UVALive - 3211 (2-SAT + 二分)

layout: post title: 训练指南 UVALive - 3211 (2-SAT + 二分) author: "luowentaoaa" catalog: true mathjax: true tags: - 2-SAT - 图论 - 训练指南 Now or later UVALive - 3211 题意 n架飞机,每架可选择两个着落时间.安排一个着陆时间表,使得着陆间隔的最小值最大 题解 二分查找最大值P,每次都用2-SAT判断是否可行. #include<bits

UVALive - 3211 - Now or later(图论——2-SAT)

Problem   UVALive - 3211 - Now or later Time Limit: 9000 mSec Problem Description Input Output 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 题解:2-SAT问题板子题,这个问题主要是理论难度比较大,有了结论之后代码很容易,有专门的论文阐释算

UVALive - 3211 Now or later (2-SAT)

题目大意:有n架飞机需要着陆.每架飞机有两种选择,早着陆或者晚着陆,二选其一 现在为了保证飞机的着陆安全,要求两架着陆的飞机的时间间隔的最小值达到最大 解题思路:最小值最大,二分枚举 设第i架飞机选择着陆方式为a,第j架飞机选择着陆的方式为b,枚举的时间间隔为mid 如果abs(plane[i][a] - plane[j][b]) < mid,表明这两架飞机以这样的着陆方式是矛盾的,所以只能二选其一,这样,关系式就推出来了 链式前向星 #include <cstdio> #include

UVALive 3211 Now or later(2-SAT,二分,Kosaraju)

题意:有n个飞机要降落,每机都可以在两个时间点上选择降落.但是两机的降落时间间隔太小会影响安全性,所以,要求两机的降落时间应该达到最大,当然也不能冲突了.问最大的时间间隔是多少?(其实问的是max(每种方案中两机间的最小间隔) ) 思路: 用Kosaraju算法也是可以过的,而且代码也比较少,那就用此法解决了. 主要的步骤是: 二分穷举每个时间间隔,对于每个间隔,建反向图,对图进行DFS着色看是否有冲突,无冲突的话证明此间隔是可以实现的.要找一个可以实现的,且间隔最大的. 1 #include

{TwoSAT}

今天学习图论的时候,碰到了2sat问题 虽然不是很难理解,感觉很精妙 ▄█?█● 用的LRJ白书上的模板. 套路如下:  2 - SAT就是2判定性问题,是一种特殊的逻辑判定问题. 选择的置为1,未选的置为0 对于2SAT,每组矛盾都会有四种情况(2*2),题目会限制一种不成立,我们要做的就是找出这一种,用逻辑连接词表示出来,然后取反,加边即可. 具体过程白书上p324有讲,这里就不说了. 下面附三道题,做做就知道套路了 Party HDU - 3062 1 #include <bits/std

UVALive 4848 Tour Belt

F - Tour Belt Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVALive 4848 Description Korea has many tourist attractions. One of them is an archipelago (Dadohae in Korean), a cluster of small islands sca

UVALive 6467 Strahler Order 拓扑排序

这题是今天下午BNU SUMMER TRAINING的C题 是队友给的解题思路,用拓扑排序然后就可以了 最后是3A 其中两次RE竟然是因为: scanf("%d",mm); ORZ 以后能用CIN还是CIN吧 QAQ 贴代码了: 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <math.h> 5 #include <iostre

UVALive 7077 Little Zu Chongzhi&#39;s Triangles (有序序列和三角形的关系)

这个题……我上来就给读错了,我以为最后是一个三角形,一条边可以由多个小棒组成,所以想到了状态压缩各种各样的东西,最后成功了……结果发现样例过不了,三条黑线就在我的脑袋上挂着,改正了以后我发现N非常小,想到了回溯每个棍的分组,最多分5组,结果发现超时了……最大是5^12 =  244,140,625,厉害呢…… 后来想贪心,首先想暴力出所有可能的组合,结果发现替换问题是一个难题……最后T T ,我就断片了.. 等看了别人的办法以后,我才发现我忽视了三角形的特性,和把数据排序以后的特点. 如果数据从