标签:des com http blog style class div img code c log
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 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.
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.
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.
For each input case, your program has to write a line that conttains the maximal security gap between consecutive landings.
10 44 156 153 182 48 109 160 201 55 186 54 207 55 165 17 58 132 160 87 197
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.
二分答案走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 }
标签:des com http blog style class div img code c log
原文地址:http://www.cnblogs.com/hyxsolitude/p/3702118.html