UVALive 3211 Now or later
2015-07-31 21:28
295 查看
Now or later
Time Limit: 9000msMemory 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
相关文章推荐
- javascript实现倒计时自动跳转页面
- 牛腩新闻发布系统-验证码搞通了吗?详细注释-秒懂!
- Scala学习第五天:数组的基本操作,数组的进阶操作和多维数组
- java concurrent并发详解
- pycharm快捷键、常用设置、包管理
- java进阶第一篇
- STL学习记录(十四):其它几种算法
- 第三篇 SQL Server安全主体和安全对象
- VS2010关于error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- VS2010关于error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- uvalive 4973
- 初级Javascript(一)
- Hdu 1789 Doing Homework again
- linux驱动中宏__setup(str, fn)
- 循环、数组截取、随机数的产生(2015/7/30)
- Selenium IDE简介
- ARM处理器体系架构详细说明
- 黑马程序员-C语言printf和scanf函数中格式控制符使用小结
- 黑马程序员——String类
- dsp之BF531笔记