蓝书325页的基础题

二分+2-sat

//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker,"/STACK:102400000,102400000")
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha printf("haha\n")
const int maxn = + ; struct TwoSAT{
int n;
vector<int> G[maxn];
bool mark[maxn];
int c, s[maxn];///c是表示目前dfs到的个数和已经被标记的集合s
bool dfs(int x){
if (mark[x ^ ]) return false;
if (mark[x]) return true;
mark[x] = true;
s[c++] = x;
for (int i = ; i < G[x].size(); i++)
if (!dfs(G[x][i])) return false;
return true;
} void init(int n){
this->n = n;
for (int i = ; i < * n; i++) G[i].clear();
memset(mark, , sizeof(mark));
} void add_edge(int x, int xval, int y, int yval){
x = x * + xval, y = y * + yval;
G[x ^ ].push_back(y);
G[y ^ ].push_back(x);
} bool solve(){
for (int i = ; i < * n; i += ){
if (!mark[i] && !mark[i + ]){
c = ;
if (!dfs(i)){
while (c) mark[s[--c]] = false;
if (!dfs(i + )) return false;
}
}
}
return true;
}
}; TwoSAT sat;
int n;
int E[maxn], L[maxn];
int ti[maxn][]; bool test(int p){
sat.init(n);
for (int i = ; i < n; i++){
for (int x = ; x < ; x++){
for (int j = i + ; j < n; j++){
for (int y = ; y < ; y++){
if (abs(ti[i][x] - ti[j][y]) < p){
///那就说明不成立,因此要建立成立的边
sat.add_edge(i, x ^ , j, y ^ );
}
}
}
}
}
return sat.solve();
} int main(){
while (scanf("%d", &n) == ){
int lb = , rb = ;
for (int i = ; i < n; i++){
scanf("%d%d", E + i, L + i);
ti[i][] = E[i], ti[i][] = L[i];
rb = max(rb, max(E[i], L[i]));
}
rb++;
while (lb < rb - ){
int mid = (lb + rb) / ;
if (test(mid)) lb = mid;
else rb = mid;
}
printf("%d\n",lb);
}
return ;
}

2-sat基础题 uvalive 3211的更多相关文章

  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 - 3211 (2-SAT + 二分)

    layout: post title: 训练指南 UVALive - 3211 (2-SAT + 二分) author: "luowentaoaa" catalog: true m ...

  3. Android测试基础题(三)

    今天接着给大家带来的是Android测试基础题(三).    需求:定义一个排序的方法,根据用户传入的double类型数组进行排序,并返回排序后的数组 俗话说的好:温故而知新,可以为师矣 packag ...

  4. 小试牛刀3之JavaScript基础题

    JavaScript基础题 1.让用户输入两个数字,然后输出相加的结果. *prompt() 方法用于显示可提示用户进行输入的对话框. 语法: prompt(text,defaultText) 说明: ...

  5. 小试牛刀2:JavaScript基础题

    JavaScript基础题 1.网页中有个字符串“我有一个梦想”,使用JavaScript获取该字符串的长度,同时输出字符串最后两个字. 答案: <!DOCTYPE html PUBLIC &q ...

  6. HDU 1301 Jungle Roads (最小生成树,基础题,模版解释)——同 poj 1251 Jungle Roads

    双向边,基础题,最小生成树   题目 同题目     #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<stri ...

  7. nyist oj 79 拦截导弹 (动态规划基础题)

    拦截导弹 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描写叙述 某国为了防御敌国的导弹突击.发展中一种导弹拦截系统.可是这样的导弹拦截系统有一个缺陷:尽管它的第一发炮弹可以 ...

  8. linux面试题-基础题1

    第1章 基础题1 1.1 在装系统创建Linux分区时,一般至少需要创建两个分区( ) A.FAT.NTFS   B. /usr.swap    C. /boot.swap  D.swap./ 1.2 ...

  9. Java面试题以及答案精选(架构师面试题)-基础题1

    基础题 一.String,StringBuffer, StringBuilder 的区别是什么?String为什么是不可变的?1. String是字符串常量,StringBuffer和StringBu ...

随机推荐

  1. CS小分队第一阶段冲刺站立会议(5月11日)

    昨日成果:完成了倒计时器的制作,为其添加了声音:并对扫雷游戏的失败添加了动态效果: 遇到的困难:把图片放入picturebox中无法改变图片的大小,音乐格式只能使用.wav,该格式音乐比较大,增加了整 ...

  2. 【最小生成树+LCA】Imperial roads

    http://codeforces.com/gym/101889 I 先跑一遍最小生成树,把经过的边和答案记录下来 对于每个询问的边,显然如果处于MST中,答案不变 如果不在MST中,假设这条边连上了 ...

  3. 1st 英文文章词频统计

    英文文章词频统计: 功能:统计一篇英文文章的单词总数及出现频数并输出,之后排序,输出频数前十的单词及其频数. 实现方法:使用C语言,用fopen函数读入txt文件,fscanf函数逐个读入单词,结构体 ...

  4. 【Linux 命令】- find 命令

    find 是日常工具箱中功能更强大.更灵活的命令行工具之一,因此值得花费更多的时间. 最简单的,find 跟上路径寻找一些东西.例如: find / 它将找到(并打印出)系统中的每个文件.而且由于一切 ...

  5. 开源人脸识别face_recognition

    环境:python36 1.安装dlib.face_recognition windows版 下载dlib,cp后面是py版本 下载地址:https://pypi.org/simple/dlib/ 提 ...

  6. Hibernate 中 load() 方法导致的 noSession 异常

    之所以要写这个,是因为最近碰到了一个延迟加载的 load() 导致出现 noSession 的异常. 下面第三种方式解决这个问题需要用到一个本地线程的对象,也就是 ThreadLocal 类,之前写过 ...

  7. chrome 常用插件集锦

    stylish 改变浏览器CSS样式

  8. Java线程间怎么实现同步

    1.Object#wait(), Object#notify()让两个线程依次执行 /** * 类AlternatePrintDemo.java的实现描述:交替打印 */ class NumberPr ...

  9. 【计算机网络】NAT:网络地址转换

    NAT(Network Address Translation,网络地址转换)是1994年提出的.当在专用网内部的一些主机本来已经分配到了本地IP地址(即仅在本专用网内使用的专用地址),但现在又想和因 ...

  10. [十七]SpringBoot 之 使用自定义的properties

    Springboot使用application.properties默认了很多配置.但需要自己添加一些配置的时候,我们应该怎么做呢. 如果继续在application.properties中添加 如: ...