题目的要求一个最小值最大,二分即可,但是怎么判断呢?

飞机早或者晚两种状态,可以用一个布尔变量表示,假设当前猜测为m,那么根据题意,

如果x和y所对应的时间冲突那么就是¬(xΛy)化成或的形式(¬x)V(¬y),就可以套用twoSAT了。

关于2-SAT,简单理解是,把逻辑推导变成一条有向边,然后跑图判断一下。

#include<bits/stdc++.h>
using namespace std; const int maxn = ; #define PB push_back
struct TwoSAT
{
int n,M;
vector<int> G[maxn*];
bool vis[maxn*];
int S[maxn*], c; void init(int n)
{
this->n = n;
M = n<<;
for(int i = ; i < M; i++) G[i].clear();
memset(vis,,sizeof(vis));
} bool dfs(int x)
{
if(vis[x^]) return false;
if(vis[x]) return true;
vis[x] = true;
S[c++] = x;
for(int i = ; i < (int)G[x].size(); i++){
if(!dfs(G[x][i])) return false;
}
return true; } void add_clause(int x,int xv,int y,int yv)// xv or yv
{
x = x<<|xv;
y = y<<|yv;
G[x^].PB(y);
G[y^].PB(x);
} bool solve()
{
for(int i = ; i < M; i+=){
if(!vis[i] && !vis[i+]){
c = ;
if(!dfs(i)){
while(c>) vis[S[--c]] = false;
if(!dfs(i+)) return false;
}
}
}
return true;
}
}solver; int T[maxn][]; bool ok(int m,int n)
{
solver.init(n);
for(int i = ; i < n; i++){
for(int xv = ; xv < ; xv++){
for(int j = i+; j < n; j++){
for(int yv = ; yv < ; yv++){
if(abs(T[i][xv]-T[j][yv])<m){
solver.add_clause(i,xv^,j,yv^);
}
}
}
}
}
return solver.solve();
} int main()
{
//freopen("in.txt","r",stdin);
int n;
while(~scanf("%d",&n)){
int l = , r = ;
for(int i = ; i < n; i++){
scanf("%d%d",T[i],T[i]+);
r = max(r,max(T[i][],T[i][]));
}
int mid;
for( ; l < r; ok(mid,n)?l = mid:r = mid-) mid = (l+r+)>>;
printf("%d\n",l);
}
return ;
}

UVALive 3211 Now or Later (2-SAT)的更多相关文章

  1. UVALive - 3211 - Now or later(图论——2-SAT)

    Problem   UVALive - 3211 - Now or later Time Limit: 9000 mSec Problem Description Input Output Sampl ...

  2. UVALive 7146 Defeat the Enemy(贪心+STL)(2014 Asia Shanghai Regional Contest)

    Long long ago there is a strong tribe living on the earth. They always have wars and eonquer others. ...

  3. LA 3211 飞机调度(2—SAT)

    https://vjudge.net/problem/UVALive-3211 题意: 有n架飞机需要着陆,每架飞机都可以选择“早着陆”和“晚着陆”两种方式之一,且必须选择一种,第i架飞机的早着陆时间 ...

  4. UVALive 3211 Now or later(2-sat)

    2-sat问题,一种在两种可能性中选择必然关系的问题. 推荐两篇论文,也是学2-sat公认比较好的材料.前者较好理解,后者需耐心看. http://www.google.com.hk/url?sa=t ...

  5. POJ 3678 Katu Puzzle(2 - SAT) - from lanshui_Yang

    Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a ...

  6. 学习笔记(two sat)

    关于two sat算法 两篇很好的论文由对称性解2-SAT问题(伍昱), 赵爽 2-sat解法浅析(pdf). 一些题目的题解 poj 3207 poj 3678 poj 3683 poj 3648 ...

  7. UVALive 6609 Minimal Subarray Length(RMQ-ST+二分)

    题意:给定长度为N的数组,求一段连续的元素之和大于等于K,并且让这段元素的长度最小,输出最小长度即可,若不存在这样的元素集合,则输出-1 题目链接:UVAlive 6609 做法:做一个前缀和pref ...

  8. UVALive 5903 Piece it together(二分图匹配)

    给你一个n*m的矩阵,每个点为'B'或'W'或'.'.然后你有一种碎片.碎片可以旋转,问可否用这种碎片精确覆盖矩阵.N,M<=500 WB  <==碎片 W 题目一看,感觉是精确覆盖(最近 ...

  9. UVALive 2403 77377解题报告(深搜)

    题意:给你一些固定的字符串,在给出数字,根据键盘的对应关系,输出所有的满足条件的字符串,输出顺序无所谓. 思路:因为题目说了,输出比较小,说明测试数据并不强,所以可以暴力回溯求出答案,将所有的给出的字 ...

随机推荐

  1. 2.12 Hivet中order by,sort by、distribute by和cluster by

    https://cwiki.apache.org/confluence/display/Hive/LanguageManual+SortBy 一.order by 对全局数据的排序,仅仅只有一个red ...

  2. ElasticSearch基础之映射mapping

    [01]什么是mapping? 首先去看看官方文档,非常重要:https://www.elastic.co/guide/en/elasticsearch/reference/current/mappi ...

  3. Eclipse如何查看接口实现类快捷键

    1.找到要打开的接口类 2.双击接口名选中 3.按Ctrl+T打开接口实现类 以List接口为例,如下所示

  4. UVaLive 3971 Assemble (水题二分+贪心)

    题意:你有b元钱,有n个配件,每个配件有各类,品质因子,价格,要每种买一个,让最差的品质因子尽量大. 析:很简单的一个二分题,二分品质因子即可,每次计算要花的钱的多少,每次尽量买便宜且大的品质因子. ...

  5. 洛谷1087 FBI树 解题报告

    洛谷1087 FBI树 本题地址:http://www.luogu.org/problem/show?pid=1087 题目描述 我们可以把由“0”和“1”组成的字符串分为三类:全“0”串称为B串,全 ...

  6. c# 调用 webservices (转载)

    .net 调用webservice 总结 最近做一个项目,由于是在别人框架里开发app,导致了很多限制,其中一个就是不能直接引用webservice . 我们都知道,调用webserivice 最简单 ...

  7. SourceTree配置BeyondCompare代码冲突解决工具

    一.工具准备:SourceTree这个你得有.然后下载BeyondCompare(破解教程) 二.配置环境:SourceTree->工具->选项->比较,外部对比工具和合并工具都选择 ...

  8. VR相关网站

    VR87870 http://www.87870.com/ VR玩家网 http://www.vrwanjia.cn/ VR之家 http://www.vr.cn/ http://gad.qq.com ...

  9. unity3d读写txt

    http://www.cnblogs.com/sunet/p/3851353.html?utm_source=tuicool 记录一下昨天用到的技术点:基于android平台unity3d读写txt. ...

  10. Unity3D中常用的数据结构总结与分

    阅读目录 1.几种常见的数据结构 2.几种常见数据结构的使用情景 来到周末,小匹夫终于有精力和时间来更新下博客了.前段时间小匹夫读过一份代码,对其中各种数据结构灵活的使用赞不绝口,同时也大大激发了小匹 ...