蓝书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. 02-JAVA 初始化

    构造器 概念:在创建对象时被自动调用的方法,构造器采用和类名一样的名称 创建对象时,会为其分配存储空间,并调用相应的构造器进行初始化.这就确保了在操作对象之前,这个对象已经被恰当的初始化了. 不接受仁 ...

  2. 使用C和C++实现“电梯”的区别

    C 面向过程:       该电梯不允许未卜先知,故程序需逐条处理乘客请求并更新当前各变量状态.       如何获得最短时间:是否立即响应请求,计算出不同决策下的总时间,并进行比较,然后选择最短时间 ...

  3. 福大软工1816:Beta总结

    第三视角Beta答辩总结 博客链接以及团队信息 组长博客链接 成员信息(按拼音排序) 姓名 学号 备注 张扬 031602345 组长 陈加伟 031602204 郭俊彦 031602213 洪泽波 ...

  4. Java compiler level does not match the version of the installed Java project facet. map解决方法

    右键项目"Properties",在弹出的"Properties"窗口左侧,单击"Project Facets",打开"Proje ...

  5. KeyBoard 操作 !

    键盘操作:tab/ enter/ crtl+c ,crtl+v ; import java.awt.*; import java.awt.datatransfer.StringSelection; i ...

  6. JAVA字节流(读写文件)

    InputStream此抽象类是表示字节输入流的所有类的超类.需要定义 InputStream 的子类的应用程序必须始终提供返回下一个输入字节的方法. int available()返回此输入流方法的 ...

  7. 我们为什么要使用Spring Cloud?

    我们为什么要使用Spring Cloud? 两个需要好好看看: Spring Boot Spring Clude Spring Cloud是一个集成了众多开源的框架,利用Spring Boot的开发便 ...

  8. Centos7安装完毕后联网-设置ip地址(VMware虚拟机)

    VMware虚拟机中安装了Centos7,为了让Centos能够访问外网及设置固定的ip地址以方便本地通过SSH访问Centos,做以下几步.本文来自osfipin note. 1.确认虚拟机网络链接 ...

  9. HDU 4767——Bell

    昨天比赛被虐的这个题目. 今天听斌牛讲过他的思路后就A掉了. 题目的意思是要你求出bell数的第n项对95041567取模. 首先,95041567=31*37*41*43*47: 然后取模就是先分别 ...

  10. Collection接口框架

    1. Collection接口 其主要的UML类图: Collection接口继承自Iterable接口.Iterable接口中定义了Iterable方法,该方法会返回一个迭代器,用于遍历合集中的元素 ...