LA3211 Now or later
题目大意:n架飞机,每架可选择两个着落时间。安排一个着陆时间表,使得着陆间隔的最小值最大。(转自http://blog.csdn.net/u013514182/article/details/42333363)
每个飞机有两个选择:时间1或时间2,分别用xi和x'表示。最小值最大,考虑二分答案ans;
对于任意两家飞机x,y,x选择时间k,y选择时间l,如果时间差小于ans,说明1、x选k后y必须不能选l,2、y选l后x必须不能选k
边开小了,疯狂RE,边居然要开到千万级别。。。竟然出了这么极端的数据专门卡空间。。。出题人真XX
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
template<class T>
inline void swap(T &a, T &b)
{
T tmp = a;a = b;b = tmp;
}
inline void read(int &x)
{
x = ;char ch = getchar(), c = ch;
while(ch < '' || ch > '') c = ch, ch = getchar();
while(ch <= '' && ch >= '') x = x * + ch - '', ch = getchar();
if(c == '-') x = -x;
}
const int INF = 0x3f3f3f3f;
const int MAXN = + ;
struct Edge
{
int u,v,nxt;
Edge(int _u, int _v, int _nxt){u = _u;v = _v;nxt = _nxt;}
Edge(){}
}edge[];
int head[MAXN], cnt;
inline void insert(int a, int b)
{
edge[++ cnt] = Edge(a, b, head[a]), head[a] = cnt;
}
int n, t[MAXN][], dfn[MAXN], dfst, low[MAXN], b[MAXN], bb[MAXN], group, belong[MAXN], stack[MAXN], top;
void dfs(int u)
{
b[u] = bb[u] = , stack[++ top] = u, dfn[u] = low[u] = ++ dfst;
for(int pos = head[u];pos;pos = edge[pos].nxt)
{
int v = edge[pos].v;
if(!b[v]) dfs(v), low[u] = min(low[v], low[u]);
else if(bb[v]) low[u] = min(low[u], dfn[v]);
}
if(low[u] == dfn[u])
{
++ group;
int now = -;
while(now != u) now = stack[top --], belong[now] = group, bb[now] = ;
}
} void tarjan()
{
dfst = , group = , memset(belong, , sizeof(belong)), memset(dfn, , sizeof(dfn)), memset(low, , sizeof(low)), memset(b, , sizeof(b)), memset(bb, , sizeof(bb));
for(int i = ;i <= n;++ i) if(!b[i << ]) dfs(i << );
for(int i = ;i <= n;++ i) if(!b[i << | ]) dfs(i << | );
} int check(int m)
{
memset(head, , sizeof(head)), cnt = ;
for(int i = ;i <= n;++ i)
for(int k = ;k <= ;++ k)
for(int j = i + ;j <= n;++ j)
for(int l = ; l <= ;++ l)
if(abs(t[i][k] - t[j][l]) < m)
insert(i << | k, j << | (l ^ )), insert(j << | l, i << | (k ^ ));
tarjan();
for(int i = ;i <= n;++ i) if(belong[i << ] == belong[i << | ]) return ;
return ;
} int main()
{
while(scanf("%d", &n) != EOF)
{
int l = , r = , mid, ans = ;
for(int i = ;i <= n;++ i) read(t[i][]), read(t[i][]), r = max(r, max(t[i][], t[i][]));
while(l <= r)
{
mid = (l + r) >> ;
if(check(mid)) l = mid + , ans = mid;
else r = mid - ;
}
printf("%d\n", ans);
}
return ;
}
LA3211
LA3211 Now or later的更多相关文章
- LA3211 飞机调度 Now or later-二分法&TwoSet
https://vjudge.net/problem/UVALive-3211 As you must have experienced, instead of landing immediately ...
- 【LA3211 训练指南】飞机调度 【2-sat】
题意 有n嫁飞机需要着陆.每架飞机都可以选择“早着陆”和“晚着陆”两种方式之一,且必须选择一种.第i架飞机的早着陆时间为Ei,晚着陆时间为Li,不得在其他时间着陆.你的任务是为这些飞机安排着陆方式,使 ...
- la3211
2-sat+二分... 每次二分答案然后连边2-sat...边要开到n*n 样例水得跟没有一样... #include<bits/stdc++.h> using namespace std ...
- 【UVALive - 3211】Now or later (二分+2-SAT)
题意: 有n架飞机需要着陆.每架飞机有两种选择,早着陆或者晚着陆,二选其一.现在为了保证飞机的着陆安全,要求两架着陆的飞机的时间间隔的最小值达到最大. 分析: 最小值最大问题我们想到二分答案.对于猜测 ...
随机推荐
- C#查找List 某一段数据
public void SelectData() { List<int> r = new List<int>(); r.Add(); r.Add(); r.Add(); r.A ...
- jQuery鼠标拖曳改变div大小(模拟textarea右下角拖曳)
jQuery.fn.extend({ drag: function() { $(document).off("mouseup.drag").on("mouseup.dra ...
- Python全栈开发:初识Python
Pythton简介 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语 ...
- 【Uva 10003】Cutting Sticks
[Link]: [Description] 给你一根长度为l的棍子; 然后有n个切割点; 要求在每个切割点都要切割一下; 这样,最后就能形成n+1根小棍子了; 问你怎样切割,消耗的体力最小; 认为,消 ...
- python Xls文档读写
1.模块安装 2.python 代码 import xlrd import xlwt import datetime def set_style(name,height,format,bold=Fal ...
- Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.4.1
Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its dependencies could not be res ...
- 如何学习AxureRP Axure学习方法
从作者最初接触的5.5版本,到5.6版本,到后来6.0的多个迭代版本,直到现在的6.5版本,AxureRP每次的版本升级都伴随着新功能的增 加,也解决了原型设计上的一些难题.这也从另一个方面诠释了“学 ...
- 【DM642学习笔记一】关于Can't Initialize Target CPU的一种解决方法 : Error 0x80000240
花了几天时间,终于可以顺利进入ccs软件开始学习了! 我使用的是瑞泰公司的ICETEK-DM642-IDK-M图像处理系统(ICETEK5100USB仿真器,仿真芯片为DM642).使用ccs2.21 ...
- SpringMVC处理请求的大致流程是怎么样的
SpringMVC请求处理流程 Spring MVC请求处理架构图: 1.用户首先发送请求到前端控制器Dispatcher Servlet, 2.在doDispath这个方法中会为请求找到对 ...
- 使用Colaboratory的免费GPU训练神经网络
1 Colaboratory 介绍 Colaboratory 是一个 Google 研究项目,旨在帮助传播机器学习培训和研究成果.它是一个 Jupyter 笔记本环境,不需要进行任何设置就可以使用,并 ...