您的位置:首页 > 其它

UVALive 3211 Now or later

2015-07-31 21:28 295 查看

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).

[align=CENTER]Figure 1: A simple Holding Pattern as described in a pilot text book.[/align]

[align=CENTER] [/align]

#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
struct arc {
int to,next;
arc(int x = 0,int y = -1) {
to = x;
next = y;
}
};
arc e[maxn*maxn];
int head[maxn],dfn[maxn],low[maxn],belong[maxn];
int tot,cnt,scc,n,m;
bool instack[maxn];
stack<int>stk;
void add(int u,int v) {
e[tot] = arc(v,head[u]);
head[u] = tot++;
}
void init() {
for(int i = 0; i < maxn; i++) {
belong[i] = 0;
low[i] = dfn[i] = 0;
head[i] = -1;
instack[i] = false;
}
while(!stk.empty()) stk.pop();
tot = cnt = scc = 0;
}
void tarjan(int u) {
dfn[u] = low[u] = ++cnt;
instack[u] = true;
stk.push(u);
for(int i = head[u]; ~i; i = e[i].next) {
if(!dfn[e[i].to]) {
tarjan(e[i].to);
if(low[e[i].to] < low[u]) low[u] = low[e[i].to];
} else if(instack[e[i].to] && dfn[e[i].to] < low[u])
low[u] = dfn[e[i].to];
}
if(dfn[u] == low[u]) {
scc++;
int v;
do {
v = stk.top();
stk.pop();
instack[v] = false;
belong[v] = scc;
} while(v != u);
}
}
bool solve() {
for(int i = 0; i < (n<<1); i++)
if(!dfn[i]) tarjan(i);
for(int i = 0; i < n; i++)
if(belong[i] == belong[i+n]) return false;
return true;
}
int tim[maxn][2];
bool check(int t) {
init();
for(int i = 0; i < n; ++i)
for(int j = i+1; j < n; ++j) {
if(abs(tim[i][0] - tim[j][0]) < t) {
add(i,j+n);
add(j,i+n);
}
if(abs(tim[i][0] - tim[j][1]) < t) {
add(i,j);
add(j+n,i+n);
}
if(abs(tim[i][1] - tim[j][0]) < t) {
add(i+n,j+n);
add(j,i);
}
if(abs(tim[i][1] - tim[j][1]) < t) {
add(i+n,j);
add(j+n,i);
}
}
for(int i = 0; i < 2*n; ++i)
if(!dfn[i]) tarjan(i);
for(int i = 0; i < n; ++i)
if(belong[i] == belong[i+n]) return false;
return true;
}
int main() {
while(~scanf("%d",&n)) {
int low = 0,high = 0;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < 2; ++j) {
scanf("%d",tim[i]+j);
high = max(high,tim[i][j]);
}
}
int ret = -1;
while(low <= high) {
int mid = (low + high)>>1;
if(check(mid)) {
ret = mid;
low = mid+1;
} else high = mid-1;
}
printf("%d\n",ret);
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: