UVa 3211 Now or later (二分+2-Sat)
题意:有 n 架飞机,每个飞机早着陆,或者晚着陆,让你安排一个方式,让他们着陆的时间间隔尽量大。
析:首先对于时间间隔,可以用二分来解决,然后就成了一个判定性问题,然后怎么判断该时间间隔是不是成立呢,那么用2-Sat能解决,每次对于时间间隔都小于正在判定的,然后给他们连上相应的边,是连两条,然后跑一遍2-sat 就OK了。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define all 1,n,1
#define FOR(x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e15;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 2000 + 10;
const int mod = 3;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} // UVaLive 3211 int ta[maxn], tb[maxn]; struct TwoSAT{
int n;
vector<int> G[maxn<<1];
bool mark[maxn<<1];
int S[maxn<<1], c; bool dfs(int x){
if(mark[x^1]) return false;
if(mark[x]) return true;
mark[x] = 1;
S[c++] = x;
for(int i = 0; i < G[x].sz; ++i)
if(!dfs(G[x][i])) return false;
return true;
} void init(int n){
this->n = n;
for(int i = 0; i < n*2; ++i) G[i].cl;
ms(mark, 0);
} void add_clause(int x, int xval, int y, int yval){
x = x * 2 + xval;
y = y * 2 + yval;
G[x^1].pb(y);
G[y^1].pb(x);
} bool solve(){
for(int i = 0; i < 2*n; i += 2){
if(!mark[i] && !mark[i+1]){
c = 0;
if(!dfs(i)){
while(c > 0) mark[S[--c]] = 0;
if(!dfs(i+1)) return false;
}
}
}
return true;
}
}; TwoSAT twosat; bool judge(int m){
twosat.init(n);
for(int i = 0; i < n; ++i)
for(int j = i+1; j < n; ++j){
if(abs(ta[i] - ta[j]) <= m) twosat.add_clause(i, 0, j, 0);
if(abs(ta[i] - tb[j]) <= m) twosat.add_clause(i, 0, j, 1);
if(abs(tb[i] - ta[j]) <= m) twosat.add_clause(i, 1, j, 0);
if(abs(tb[i] - tb[j]) <= m) twosat.add_clause(i, 1, j, 1);
}
return twosat.solve();
} int main(){
while(scanf("%d", &n) == 1){
int l = 0, r = 0;
for(int i = 0; i < n; ++i){
scanf("%d %d", ta+i, tb+i);
r = max(r, tb[i]);
}
while(l <= r){
int m = l + r >> 1;
if(judge(m)) l = m + 1;
else r = m - 1;
}
printf("%d\n", l);
}
return 0;
}
UVa 3211 Now or later (二分+2-Sat)的更多相关文章
- UVa 714 Copying Books(二分)
题目链接: 传送门 Copying Books Time Limit: 3000MS Memory Limit: 32768 KB Description Before the inventi ...
- UVA 10816 + HDU 1839 Dijstra + 二分 (待研究)
UVA 题意:两个绿洲之间是沙漠,沙漠的温度不同,告诉起点,终点,求使得从起点到终点的最高温度最小的路径,如果有多条,输出长度最短的路径: 思路:用最小费用(最短路径)最大流(最小温度)也能搞吧,但因 ...
- UVA 10668 - Expanding Rods(数学+二分)
UVA 10668 - Expanding Rods 题目链接 题意:给定一个铁棒,如图中加热会变成一段圆弧,长度为L′=(1+nc)l,问这时和原来位置的高度之差 思路:画一下图能够非常easy推出 ...
- uva 10566 Crossed Ladders (二分)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVa 10539 (筛素数、二分查找) Almost Prime Numbers
题意: 求正整数L和U之间有多少个整数x满足形如x=pk 这种形式,其中p为素数,k>1 分析: 首先筛出1e6内的素数,枚举每个素数求出1e12内所有满足条件的数,然后排序. 对于L和U,二分 ...
- uva 10004 Bicoloring(dfs二分染色,和hdu 4751代码差不多)
Description In the ``Four Color Map Theorem" was proven with the assistance of a computer. This ...
- UVA 1335 Beijing Guards(二分答案)
入口: https://cn.vjudge.net/problem/UVA-1335 [题意] 有n个人为成一个圈,其中第i个人想要r[i]种不同的礼物,相邻的两个人可以聊天,炫耀自己的礼物.如果两个 ...
- UVa 12715 Watching the Kangaroo(二分)
题意:n条线段(n <= 100000) (L<=R <= 1e9) ,m组询问(m <= 100000) 每次询问一个点的覆盖范围的最大值.一个点x对于一条包括其的线段,覆盖 ...
- UVA 11865 Stream My Contest (二分+最小树形图)
题意:给定一个网络,一个服务器,其他的是客户机,有 m 条连线,每条有一个带宽和花费(单向边),让你用不超过 c 的花费,使得 0 到 所有的机器都能到达,并且使得最小带宽最大. 析:很明显是二分题, ...
随机推荐
- 第十章 hbase默认配置说明
hbase.rootdir:这个目录是region server的共享目录,用来持久化Hbase.URL需要是'完全正确'的,还要包含文件系统的scheme.例如,要表示hdfs中的 '/hbase ...
- 第十章 Secret & Configmap(下)
10.4 ConfigMap Secret可以为Pod提供密码.Token.私钥等敏感数据:对于一些非敏感数据,比如一些配置信息,则可以用ConfigMap. configMap的使用方式与Secre ...
- Histogram
folly/Histogram.h Classes Histogram Histogram.h defines a simple histogram class, templated on the t ...
- Long.parseLong(String s) 其中s必须是数字形式的字符串,才能运用该函数转化为长整型。
public class ConverTo { public static void main(String [] args) { String numberIn =args[0]; convertN ...
- scp 远程复制
1. 上传本地文件到远程机器指定目录 命令: scp /opt/soft/nginx-0.5.38.tar.gz root@192.168.120.204:/opt/soft/scptest 上传本地 ...
- python开发_python中的list操作
对python中list的操作,大家可以参考: Python list 操作 以下是我个人的笔记: ============================================ Add b ...
- [z]【Bash命令行处理】[详解]
(转自:http://www.linuxsir.org/bbs/thread99465.html) 我看很多兄弟写脚本或命令时出现错误的主要原因,是因为不了解bash的命令行处理.我在这里总结了一下, ...
- 读<分布式一致性原理>初识zookeeper
zookeeper是什么 zookeeper是一个典型的分布式数据一致性的解决方案,分布式应用程序可以基于它实现诸如:数据发布/订阅,负载均衡,命名服务,分布式协调/通知 ,集群管理,Master选举 ...
- subprocess in python3.5
subprocess 该子模块允许你创建新的流程,连接到它们的输入/输出/错误管道,并获取他们的返回值.该模块打算替换多个旧的模块和功能:os.system 和 os.spawn * 使用sub ...
- django -- 自定义simpletag 和 filter
django中自定义simpletag,即使用自己定义的函数在html中处理数据. 步骤: 1.创建并注册app settings.py INSTALLED_APPS = [ 'django.cont ...