题目链接:http://poj.org/problem?id=2296

  二分+2sat,每个点的上下两个方向为2sat的两个状态。

 //STATUS:C++_AC_16MS_536KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef long long LL;
typedef unsigned long long ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int nod[N][];
int first[N*],next[N*N*],vis[N*],S[N*];
int T,n,mt,cnt; struct Edge{
int u,v;
}e[N*N*]; void adde(int a,int b)
{
e[mt].u=a,e[mt].v=b;
next[mt]=first[a];first[a]=mt++;
} int dfs(int u)
{
if(vis[u^])return ;
if(vis[u])return ;
int i;
vis[u]=;
S[cnt++]=u;
for(i=first[u];i!=-;i=next[i]){
if(!dfs(e[i].v))return ;
}
return ;
} int Twosat()
{
int i,j;
for(i=;i<n;i+=){
if(vis[i] || vis[i^])continue;
cnt=;
if(!dfs(i)){
while(cnt)vis[S[--cnt]]=;
if(!dfs(i^))return ;
}
}
return ;
} int judge(double *a1,double *a2,double *b1,double *b2)
{
if(Max(a1[],a2[])<=Min(b1[],b2[])
|| Min(a1[],a2[])>=Max(b1[],b2[])
|| Max(a1[],a2[])<=Min(b1[],b2[])
|| Min(a1[],a2[])>=Max(b1[],b2[]))return ;
return ;
} void init(double limt)
{
int i,j,x,y;
double a1[],a2[],b1[],b2[];
mt=;mem(vis,);
mem(first,-);
for(i=;i<n;i++){
for(j=i+;j<n;j++){
x=i<<;y=j<<;
a1[]=nod[i][]-limt/,a1[]=nod[i][];b1[]=nod[j][]-limt/,b1[]=nod[j][];
a2[]=nod[i][]+limt/,b2[]=nod[j][]+limt/;
a2[]=nod[i][]-limt;b2[]=nod[j][]-limt;
if(judge(a1,a2,b1,b2)){
adde(x,y^);adde(y,x^);
}
b2[]=nod[j][]+limt;
if(judge(a1,a2,b1,b2)){
adde(x,y);adde(y^,x^);
}
a2[]=nod[i][]+limt;b2[]=nod[j][]-limt;
if(judge(a1,a2,b1,b2)){
adde(x^,y^);adde(y,x);
}
b2[]=nod[j][]+limt;
if(judge(a1,a2,b1,b2)){
adde(x^,y);adde(y^,x);
}
}
}
} int binary(int l,int r)
{
int mid;
while(l<r){
mid=(l+r)>>;
// printf("%d %d\n",l,r);
init(mid);
if(Twosat())l=mid+;
else r=mid;
}
return l;
} int main()
{
// freopen("in.txt","r",stdin);
int i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=;i<n;i++){
scanf("%d%d",&nod[i][],&nod[i][]);
} printf("%d\n",binary(,)-);
}
return ;
}

POJ-2296 Map Labeler 2sat的更多相关文章

  1. POJ 2296 Map Labeler / ZOJ 2493 Map Labeler / HIT 2369 Map Labeler / UVAlive 2973 Map Labeler(2-sat 二分)

    POJ 2296 Map Labeler / ZOJ 2493 Map Labeler / HIT 2369 Map Labeler / UVAlive 2973 Map Labeler(2-sat ...

  2. POJ 2296 Map Labeler(2-sat)

    POJ 2296 Map Labeler 题目链接 题意: 坐标轴上有N个点.要在每一个点上贴一个正方形,这个正方形的横竖边分别和x,y轴平行,而且要使得点要么在正方形的上面那条边的中点,或者在以下那 ...

  3. POJ 2296 Map Labeler (2-Sat)

    Map Labeler Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1267   Accepted: 409 Descri ...

  4. POJ 2296 Map Labeler

    二分答案 + 2-SAT验证,判断正方形是否相交写起来有点烦,思路还是挺简单的. #include<cstdio> #include<cstring> #include< ...

  5. 【POJ】2296 Map Labeler

    http://poj.org/problem?id=2296 题意:题意:给你n个点,每个点上都放一个正方形,点只能在正方形的上边或下边的中点上,所有正方形大小一样,不能有面积重叠,求最大的正方形.( ...

  6. Map Labeler (poj 2296 二分+2-SAT)

    Language: Default Map Labeler Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1815   Ac ...

  7. poj 2296

    Map Labeler Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2047   Accepted: 682 Descri ...

  8. Map Labeler POJ - 2296(2 - sat 具体关系建边)

    题意: 给出n个点  让求这n个点所能建成的正方形的最大边长,要求不覆盖,且这n个点在正方形上或下边的中点位置 解析: 当然是二分,但建图就有点还行..比较难想..行吧...我太垃圾... 2 - s ...

  9. POJ 2296 二分+2-sat

    题目大意: 给定n个点,给每个点都安排一个相同的正方形,使这个点落在正方形的下底边的中间或者上底边的中间,并让这n个正方形不出现相互覆盖,可以共享同一条边,求 这个正方形最大的边长 这里明显看出n个点 ...

随机推荐

  1. android正在运行进程和后台缓存进程的区别

    正在运行的进程:需要占用一定的cpu资源和RAM(内存)空间,多少的话看是什么应用,要消耗一定的电量,影响手机速度等性能. 后台缓存的进程:不需要占用cpu资源,会在RAM中写入一部分数据,当下次打开 ...

  2. bootstrap form

    http://getbootstrap.com/examples/starter-template/ <form class="form-horizontal" role=& ...

  3. C++编写操作系统(1):基于 EFI 的 Bootloader

    很久以前就对操作系统很好奇,用了这么多年Windows,对他的运作机理也不是很清楚,所以一直想自己动手写一个,研究一下操作系统究竟是怎么实现的.后来在网上也找到过一些教程(比如:<自己动手写操作 ...

  4. 解决iphone safari上的圆角问题

    -webkit-appearance : none ; /*解决iphone safari上的圆角问题*/

  5. 虚拟机重复创建系统去除SID

    我们安装完的操作系统都会有一个SID,为了简化安装,现在大部分人会选择GHOST克隆安装,经过克隆后的系统SID是相同的,有时需要重新获取SID    以前WIN2003有修改SID的工具NEWSID ...

  6. BZOJ 2442: [Usaco2011 Open]修剪草坪

    Description 在一年前赢得了小镇的最佳草坪比赛后,FJ变得很懒,再也没有修剪过草坪.现在,新一轮的最佳草坪比赛又开始了,FJ希望能够再次夺冠.然而,FJ的草坪非常脏乱,因此,FJ只能够让他的 ...

  7. csuoj 1353: Guessing the Number

    这个题我想到要用kmp找到循环节: 但是后面的我就不会做了: 看到题解才知道是字符串的最小表示: #include<cstdio> #include<cstring> #inc ...

  8. static和const

    转自说出static和const关键字尽可能多的作用 static关键字至少有下列n个作用: 函数体内static变量的作用范围为该函数体,不同于auto变量,该变量的内存只被分配一次,因此其值在下次 ...

  9. Memcached总结一:memcached简介及适用和不适应场景

    Memcached是免费的,开源的,高性能的,分布式内存对象的缓存系统(键/值字典),旨在通过减轻数据库负载加快动态Web应用程序的使用. Memcached是由布拉德·菲茨帕特里克(Brad Fit ...

  10. C++的表驱动法

    目的:使用表驱动法,替换复杂的if/else和switch/case语句. 说明:JS 等其他语言也都支持的. 表驱动发示例:http://blog.csdn.net/zhouyulu/article ...