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架飞机需要着陆.每架飞机有两种选择,早着陆或者晚着陆,二选其一.现在为了保证飞机的着陆安全,要求两架着陆的飞机的时间间隔的最小值达到最大. 分析: 最小值最大问题我们想到二分答案.对于猜测 ...
随机推荐
- springcloud Finchley 版本hystrix 和 hystrix Dashboard
hystrix的断路功能 引用上个项目,创建新的model ,cloud-hystrix pom.xml <?xml version="1.0" encoding=" ...
- 时间复杂度 - Convert 计算次数 TO 时间复杂度
我们假设计算机运行一行基础代码需要执行一次运算. int aFunc(void) { printf("Hello, World!\n"); // 需要执行 1 次 return 0 ...
- HTML - head标签相关
<html> <!-- head标签中主要配置浏览器的配置信息 --> <head> <!-- 网页标题标签, 用来指定网页的标题 --> <ti ...
- fetchSql是3.2.3新增的连贯操作方法,用于直接返回SQL而不是执行查询。
fetchSql是3.2.3新增的连贯操作方法,用于直接返回SQL而不是执行查询. 例如: $result = M('User')->fetchSql(true)->find(1); 输出 ...
- 前缀后缀——cf1167E
想了很久没弄明白,对于边界的情况还是有问题 等题解出了再看看 然后枚举每个后缀r,找到比它小,并且在其左边的前缀l,那么删<=l,r-1的都可以 最后的二分很迷:要多考虑特殊情况:前缀跑到后缀后 ...
- egret 篇——关于ios环境下微信浏览器的音频自动播放问题
前段时间公司突然想用egret(白鹭引擎)做一个金币游戏,大半个月边看文档边写吭哧吭哧也总算是弄完了.期间遇到一个问题,那就是ios环境下微信浏览器的音频自动播放问题. 个人感觉吧,egret自己封装 ...
- laravel框架5.5 连接redis和redis集群
'redis' => [ 'client' => 'predis', 'default' => [ 'host' => env('REDIS_HOST', '127.0.0.1 ...
- Glassfish安装、基本使用、在idea中配置Glassfish
Glassfish安装.基本使用. 一.glassfish简介 glassfish是一款web应用服务器,和tomcat一样,也是一款优秀的Servlet容器. 二.glassfish知识点 1.do ...
- PAT甲级——A1103 Integer Factorization
The K−P factorization of a positive integer N is to write N as the sum of the P-th power of Kpositiv ...
- PAT甲级——【牛客A1005】
题目描述 Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits ...