题目链接: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. NetBeans8 类编缉器及控制台中文乱码解决

    1.类编辑器中文乱码的解决: 工具-->选项-->字体和颜色-->"语法"选项卡:右侧选择字体的地方设置一个支持中文的字体,如宋体.新宋体.微软雅黑等 2.控制台 ...

  2. NGUI系列教程三

    接下来我们再来看Progress Bar和Slider,对比参数我们可以发现,Progress Bar和slider的明显区别在于slider多一个Thumb选项,这里的Thumb就是我们拖动的时候点 ...

  3. 洛谷 P1417 烹调方案

    题目背景 由于你的帮助,火星只遭受了最小的损失.但gw懒得重建家园了,就造了一艘飞船飞向遥远的earth星.不过飞船飞到一半,gw发现了一个很严重的问题:肚子饿了~ gw还是会做饭的,于是拿出了储藏的 ...

  4. mysql的错误:The server quit without updating PID file /usr/local/mysql/data/door.pid).

    mysql错误解决: 先 参考:http://www.jb51.net/article/48625.htm 参考第四条: mysql在启动时没有指定配置文件时会使用/etc/my.cnf配置文件,请打 ...

  5. 对于数组使用sizeof(a)和使用sizeof(a[0])

    #include "stdafx.h" #include <iostream> using namespace std; int main() { ]={}; cout ...

  6. AForm — 模型驱动的自动化表单解决方案

    http://xiehuiqi220.github.io/AForm/doc/book/#

  7. 年度十佳 DevOps 博客文章(后篇)

    如果说 15 年你还没有将 DevOps 真正应用起来,16 年再不实践也未免太落伍了.在上篇文章中我们了解到 15 年十佳 DevOps 博客文章的第 6-10 名,有没有哪一篇抓住了您的眼球,让您 ...

  8. IgnoreRoute——注册路由

    routes.IgnoreRoute("home/about"); 这句话,当Route遇到Home/About的Url时,这段URL将被忽略. 效果图 需要注意的是这里route ...

  9. 【NOIP TG 解方程】

    存代码: #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> ...

  10. C语言中的宏总结

    宏定义分为两种: 1.变量式宏定义,如 #define abc def #define str "string" #define num 100 2.函数式宏定义, #define ...