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的更多相关文章

  1. LA3211 Now or later

    题目大意:n架飞机,每架可选择两个着落时间.安排一个着陆时间表,使得着陆间隔的最小值最大.(转自http://blog.csdn.net/u013514182/article/details/4233 ...

  2. LA3211 飞机调度 Now or later-二分法&TwoSet

    https://vjudge.net/problem/UVALive-3211 As you must have experienced, instead of landing immediately ...

  3. 【LA3211 训练指南】飞机调度 【2-sat】

    题意 有n嫁飞机需要着陆.每架飞机都可以选择“早着陆”和“晚着陆”两种方式之一,且必须选择一种.第i架飞机的早着陆时间为Ei,晚着陆时间为Li,不得在其他时间着陆.你的任务是为这些飞机安排着陆方式,使 ...

  4. 【UVALive - 3211】Now or later (二分+2-SAT)

    题意: 有n架飞机需要着陆.每架飞机有两种选择,早着陆或者晚着陆,二选其一.现在为了保证飞机的着陆安全,要求两架着陆的飞机的时间间隔的最小值达到最大. 分析: 最小值最大问题我们想到二分答案.对于猜测 ...

随机推荐

  1. 怎么让Eclipse对html和js代码自动提示

    使用eclipse自带的插件,无需另外安装插件,具体步骤如下1.打开eclipse→Windows→Preferences→Java→Editor→Content Assist修改Auto Activ ...

  2. Qt 给QWidget添加工具栏

    在Qt中,给主窗口(QMainWindow类)添加工具栏非常方便,直接使用addToolBar 即可,如下所示: fileToolBar = addToolBar(tr("&File ...

  3. 洛谷——P2007 魔方

    P2007 魔方 常神牛家的魔方都是3*3*3的三阶魔方,大家都见过. 模拟即可: #include<iostream> #include<cstdio> #include&l ...

  4. POJ3616 Milking Time【dp】

    Description Bessie is such a hard-working cow. In fact, she is so focused on maximizing her producti ...

  5. 手写redis的docker文件,通过docker-compose配置redis

    在前面一遍随笔,配置的是mysql主从的docker-compose配置.今天我们来学习配置编排容器redis. 准备环境: docker 18.06.1-ce docker-compose 1.23 ...

  6. mysql运维常用

    一.用户授权 用户授权主要指: 1.可以限制用户访问那些库.表 2.可以限制用户对库.表执行select.create.delete.alter.drop等操作 3.可以限制用户登陆的IP.IP段.或 ...

  7. linux环境下时间的查看和修改

    查看日期和时间date 查看时区date -R 查看UTC时间date -u 修改日期[root@centos ~]# date -s 20181230Sun Dec 30 00:00:00 EST ...

  8. CSC

    CSC CSC Table of Contents 1. account 2. Contacts 3. <国家公派留学人员预订回国机票说明> 4. 回国手续 4.1. 申办及开具<留 ...

  9. HDU - 6446 Tree and Permutation

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6446 本题是一个树上的问题——DFS. 一棵N个结点的树,其结点为1~N.树具有N-1条边,每一条边具有 ...

  10. Python基础(四) 基础拾遗、数据类型进阶

    一.基础拾遗 (一).变量作用域 外层变量,可以被内层变量直接调用:内层变量,无法被外层变量使用.这种说法在其它语言中适用,在python中除了栈以外,正常的变量作用域,只要执行声明并在内存中存在,该 ...