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

飞机早或者晚两种状态,可以用一个布尔变量表示,假设当前猜测为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. Fitnesse中TemplateLibrary的使用方法

    1.新建一个SuitePage,命名为TemplateLibrary 2.然后如下图,添加作为template的TestPage,如下面的Get 3.在Get page中添加template内容,如下 ...

  2. Unity3D命令行Build

    转自:http://www.cnblogs.com/gameprogram/archive/2012/05/11/2496303.html 本来是没想用这个命令行Build方式,可惜电脑不知道怎么的就 ...

  3. unity常用插件

    Unity3D常用插件,网址:http://jingyan.baidu.com/article/7f766daf4ef2844100e1d079.html ,想想自己也有小半年unity经验了,于是整 ...

  4. 我被面试官给虐懵了,竟然是因为我不懂Spring中的@Configuration

    现在大部分的Spring项目都采用了基于注解的配置,采用了@Configuration 替换标签的做法.一行简单的注解就可以解决很多事情.但是,其实每一个注解背后都有很多值得学习和思考的内容.这些思考 ...

  5. pytest入门学习(1)

    系统ubuntu 12.04 , 可上网 一.安装: 1.安装 setuptools 下载页面:https://bitbucket.org/pypa/setuptools/get/default.ta ...

  6. PJzhang:互联网是有国界

    猫宁!!! 参考链接:https://mp.weixin.qq.com/s/NFgps_5HBpl3ZjDoR5w8XA 上世纪90年代,互联网开始崛起,美国凭借超级大国的地位,先进技术优势,以美国公 ...

  7. 解决https接口 以及谷歌错误

    <meta http-equiv="Content-Security-Policy" content="block-all-mixed-content"& ...

  8. error: unrecognized command line option "-std=c11" 解决办法

    今天在安装php版本 grpc扩展的时候报错如下: cc1: error: unrecognized command line option "-std=c11" cc1: war ...

  9. 分布式通信-tcp/ip 单播

    服务端 public class SingleBroadCastSocketServer { public static void main(String[] args) { ServerSocket ...

  10. sql索引的作用

    转https://www.cnblogs.com/hyd1213126/p/5828937.html (一)深入浅出理解索引结构 实际上,您可以把索引理解为一种特殊的目录.微软的SQL SERVER提 ...