3211 - Now or later
Time limit: 9.000 seconds
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).

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'').
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 ( 2n
2000). This line is followed by nlines. 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
t
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



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.
题意:
给出 N (2 ~ 2000)个飞机降落时间,一架飞机要不在早时间点 S(0 ~ 10 ^ 7) 降落,要不在晚时间点 E(0 ~ 10 ^ 7) 降落。现要求飞机降落时间间隔最小值最大化。
思路:
2 - sat + 二分。枚举时间间隔 T,若两个时间点间隔 t < T,则可以确定一种确定关系,两者选其一。每二分结果一次就建图一次,区间左闭右开,最后左区间值即为所求。
AC:
#include <cstdio> #include <cstring> #include <algorithm> #include <stack> #include <cmath> #include <vector> using namespace std; const int NMAX = 2005 * 2; const int INF = 10000005; int n; int Sta[NMAX], End[NMAX]; vector<int> G[NMAX]; int scc_cnt, dfs_clock; int pre[NMAX], low[NMAX], cmp[NMAX]; stack<int> s; void dfs(int u) { pre[u] = low[u] = ++dfs_clock; s.push(u); for (int i = 0; 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 (low[u] == pre[u]) { ++scc_cnt; for(;;) { int x = s.top(); s.pop(); cmp[x] = scc_cnt; if (x == u) break; } } } void scc() { dfs_clock = scc_cnt = 0; memset(cmp, 0, sizeof(cmp)); memset(pre, 0, sizeof(pre)); for (int i = 1; i <= 2 * n; ++i) { if (!pre[i]) dfs(i); } } bool C(int d) { for (int i = 1; i <= 2 * n; ++i) G[i].clear(); for (int i = 1; i <= n - 1; ++i) { for (int j = i + 1; j <= n; ++j) { if (abs(Sta[i] - Sta[j]) < d) { G[i].push_back(j + n); G[j].push_back(i + n); } if (abs(Sta[i] - End[j]) < d) { G[i].push_back(j); G[n + j].push_back(n + i); } if (abs(End[i] - Sta[j]) < d) { G[n + i].push_back(n + j); G[j].push_back(i); } if (abs(End[i] - End[j]) < d) { G[n + i].push_back(j); G[n + j].push_back(i); } } } scc(); for (int i = 1; i <= n; ++i) if (cmp[i] == cmp[i + n]) return false; return true; } void solve() { int l = 0, r = INF; while (r - l > 1) { int mid = l + (r - l) / 2; if (C(mid)) l = mid; else r = mid; } printf("%d\n", l); } int main() { while (~scanf("%d", &n)) { for (int i = 1; i <= n; ++i) scanf("%d%d", &Sta[i], &End[i]); solve(); } return 0; }
相关推荐
+-------------+-------------+------+-----+---------+-------+ 4 rows in set (0.00 sec) · 6、 往表中加入记录 我们先用SELECT命令来查看表中的数据: mysql> select * from mytable; Empty set (0.00 sec...
+---------------------+------------+------------+---------------------+ | utc_timestamp() | utc_date() | utc_time() | now() | +---------------------+------------+------------+---------------------+ | ...
+---------------------+------------+------------+---------------------+ | utc_timestamp() | utc_date() | utc_time() | now() | +---------------------+------------+------------+---------------------+ | ...
+---------------------+------------+------------+---------------------+ | utc_timestamp() | utc_date() | utc_time() | now() | +---------------------+------------+------------+---------------------+ | ...
This means that developers now are faced with the challenge of building build applications that are native to the cloud. For this, they need to be aware of the environment, tools, and resources they'...
* shutdown -h now:立即关机 * source /etc/profile:使配置文件修改立即生效 四、结语 本文档指导您搭建了 Hadoop 分布式环境,包括安装和配置 Hadoop、ZooKeeper 和 HBase,同时也介绍了相关的网络配置和 Linux...
DateTime.Now.Millisecond + fileName.Substring(fileName.LastIndexOf(".")); string path = Server.MapPath("~/upFiles/"); size = Math.Round(fb.ContentLength/1024.0)+"KB"; if (!Directory.Exists(path)) ...
var minutes = now.getMinutes(); var seconds = now.getSeconds(); // 更新时钟指针角度 $('#clock-hand-hour').css('transform', 'rotate(' + hours * 30 + 'deg)'); $('#clock-hand-minute').css('...
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board ...
2. **先行词的习惯搭配**:某些名词后面习惯接特定的介词,这与名词的意义和用法有关。 例句: - "The day on which I joined the Party"(我入党的那一天)。 - "The address to which my letters were sent"...
t needed anymore* changes in IIF function: now it works like macro- bug fixesversion 3.06----------+ added BCB packages for FR3 Enterprise+ added TfrxReportServer.OnGetVariables event handler+ ...
+-------+-------+-----+-------------+ ``` #### 五、注意事项 1. **权限问题**:创建视图需要具有相应的权限。 2. **性能考虑**:视图的性能取决于底层查询的复杂性和数据量。 3. **更新限制**:某些类型的...
now predict which advertisement the user is going to click on next, or which product they would like to buy, or it can also show whether the image of a tumor is cancerous or not. The opportunities ...
SQL NOW() 函数 NOW() 函数 NOW() 函数返回当前系统的日期和时间。...+----+--------------+---------------------------+-------+---------+ | id | name | url | alexa | country | +----+-------------
+------------+---------------+ | VERSION() | CURRENT_DATE | +------------+---------------+ | 5.1.2-alpha| 2005-10-11 | +------------+---------------+ 1 row in set (0.01 sec) ``` 2. **执行数学...
-0 to -2 for fast (2X over -3) but poor compression, uses 2-6 MB memory -3 for reasonably fast and good compression, uses 18 MB (default) -4 better compression but 3.5X slower, uses 64 MB -5 ...
However, now is the time to be a bit more rigorous and see what coding is from a more technical perspective. [ 6 ] Chapter 1 When we write code, we're instructing a computer on what are the things ...
2、代码使用Visual Studio Code开发,C语言编程。例程在ESP32-S3上运行。若在其他型号上运行,请自行调整。 3、如果接入其他传感器,请查看发布的其他资料。 4、ESP32与模块的接线,在代码当中均有定义,请自行对照...
The ubiquity of the language, which can now be found in browsers, servers, mobile phones, and whatnot, has also impelled interest in better development strategies. Also, even if JavaScript wasn't ...