la3211
2-sat+二分。。。
每次二分答案然后连边2-sat。。。边要开到n*n
样例水得跟没有一样。。。
#include<bits/stdc++.h>
using namespace std;
const int N = ;
struct edge {
int nxt, to;
} e[N * N << ];
int n, cnt = , top, Time, cot;
int dfn[N], low[N], vis[N], st[N], early[N], late[N], head[N], belong[N];
void link(int u, int v)
{
e[++cnt].nxt = head[u];
head[u] = cnt;
e[cnt].to = v;
}
void tarjan(int u)
{
st[++top] = u; dfn[u] = low[u] = ++Time; vis[u] = ;
for(int i = head[u]; i; i = e[i].nxt)
{
if(!dfn[e[i].to])
{
tarjan(e[i].to);
low[u] = min(low[u], low[e[i].to]);
}
else if(vis[e[i].to]) low[u] = min(low[u], dfn[e[i].to]);
}
if(dfn[u] == low[u])
{
++cot; int x = ;
while(x != u)
{
x = st[top--];
belong[x] = cot;
vis[x] = ;
}
}
}
bool judge(int t)
{
memset(head, , sizeof(head));
memset(dfn, , sizeof(dfn));
memset(low, , sizeof(low));
memset(belong, , sizeof(belong));
cnt = ; top = Time = cot = ;
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j) if(i != j)
{
int x = i << , y = j << ;
if(late[i] - late[j] >= && late[i] - late[j] < t)
link(x, y - ), link(y, x - );
if(late[i] - early[j] >= && late[i] - early[j] < t)
link(x, y), link(y - , x - );
if(early[i] - late[j] >= && early[i] - late[j] < t)
link(x - , y - ), link(y, x);
if(early[i] - early[j] >= && early[i] - early[j] < t)
link(x - , y), link(y - , x);
}
for(int i = ; i <= * n; ++i) if(!dfn[i]) tarjan(i);
for(int i = ; i <= n; ++i) if(belong[i * ] == belong[i * - ]) return false;
return true;
}
int main()
{
while(scanf("%d", &n) != EOF)
{
int l = , r = , ans = ;
for(int i = ; i <= n; ++i) scanf("%d%d", &early[i], &late[i]), r = max(r, late[i]);
while(r - l > )
{
int mid = (l + r) >> ;
if(judge(mid)) ans = l = mid; else r = mid;
}
printf("%d\n", ans);
}
return ;
}
la3211的更多相关文章
- LA3211 Now or later
题目大意:n架飞机,每架可选择两个着落时间.安排一个着陆时间表,使得着陆间隔的最小值最大.(转自http://blog.csdn.net/u013514182/article/details/4233 ...
- 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,不得在其他时间着陆.你的任务是为这些飞机安排着陆方式,使 ...
- 【UVALive - 3211】Now or later (二分+2-SAT)
题意: 有n架飞机需要着陆.每架飞机有两种选择,早着陆或者晚着陆,二选其一.现在为了保证飞机的着陆安全,要求两架着陆的飞机的时间间隔的最小值达到最大. 分析: 最小值最大问题我们想到二分答案.对于猜测 ...
随机推荐
- How To:分析ORACLE监听日志中的IP信息
有时候需要分析出ORACLE日志监听中的IP信息,分享一个组合命令,Linux的shell下运行正常. grep "HOST=.*establish.*\* 0" listener ...
- 散列--P1047 校门外的树
题目描述 某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米.我们可以把马路看成一个数轴,马路的一端在数轴0的位置,另一端在L的位置:数轴上的每个整数点,即0,1,2,-,L,都种有 ...
- [Python数据结构] 使用 Circular List实现Queue
[Python数据结构] 使用 Circular List实现Queue 1. Queue队列,又称为伫列(queue),是先进先出(FIFO, First-In-First-Out)的线性表.在具体 ...
- linux hexdump-显示文件十六进制格式
博主推荐:获取更多 linux文件内容查看命令 收藏:linux命令大全 hexdump命令一般用来查看“二进制”文件的十六进制编码,但实际上它能查看任何文件,而不只限于二进制文件. 语法 hexdu ...
- SQL to MongoDB Mapping Chart
http://docs.mongodb.org/manual/reference/sql-comparison/ In addition to the charts that follow, you ...
- 438D - The Child and Sequence
D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input st ...
- noip模拟赛 whzzt-Confidence
分析:做着感觉像脑筋急转弯一样......因为空间的限制,存不下每一个数,所以用数学方法来解. 设t1=Σai - Σbi = aj - bj,t2=Σi*ai - Σi*bi = j*(aj - b ...
- CF671C. Ultimate Weirdness of an Array
n<=200000个<=200000的数问所有的f(i,j)的和,表示去掉区间i到j后的剩余的数字中任选两个数的最大gcd. 数论日常不会.. 先试着计算一个数组:Hi表示f(l,r)&l ...
- CODEVS1222 信与信封问题 (匈牙利算法)
先做一遍匈牙利算法.对于已经匹配的边,如果删去之后还能最大匹配数增加,则不符合要求. 一遍匈牙利算法是O(n^3)的,对于每一条边做n次,每次O(n^2),总的复杂度是O(n^3). 注意:不要忘记输 ...
- [bzoj1022/poj3480]小约翰的游戏John_博弈论
小约翰的游戏John 题目大意:Nim游戏.区别在于取走最后一颗石子这输. 注释:$1\le cases \le 500$,$1\le n\le 50$. 想法:anti-SG游戏Colon定理. 如 ...