POJ-2296 Map Labeler 2sat
题目链接: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的更多相关文章
- 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 ...
- POJ 2296 Map Labeler(2-sat)
POJ 2296 Map Labeler 题目链接 题意: 坐标轴上有N个点.要在每一个点上贴一个正方形,这个正方形的横竖边分别和x,y轴平行,而且要使得点要么在正方形的上面那条边的中点,或者在以下那 ...
- POJ 2296 Map Labeler (2-Sat)
Map Labeler Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1267 Accepted: 409 Descri ...
- POJ 2296 Map Labeler
二分答案 + 2-SAT验证,判断正方形是否相交写起来有点烦,思路还是挺简单的. #include<cstdio> #include<cstring> #include< ...
- 【POJ】2296 Map Labeler
http://poj.org/problem?id=2296 题意:题意:给你n个点,每个点上都放一个正方形,点只能在正方形的上边或下边的中点上,所有正方形大小一样,不能有面积重叠,求最大的正方形.( ...
- Map Labeler (poj 2296 二分+2-SAT)
Language: Default Map Labeler Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1815 Ac ...
- poj 2296
Map Labeler Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2047 Accepted: 682 Descri ...
- Map Labeler POJ - 2296(2 - sat 具体关系建边)
题意: 给出n个点 让求这n个点所能建成的正方形的最大边长,要求不覆盖,且这n个点在正方形上或下边的中点位置 解析: 当然是二分,但建图就有点还行..比较难想..行吧...我太垃圾... 2 - s ...
- POJ 2296 二分+2-sat
题目大意: 给定n个点,给每个点都安排一个相同的正方形,使这个点落在正方形的下底边的中间或者上底边的中间,并让这n个正方形不出现相互覆盖,可以共享同一条边,求 这个正方形最大的边长 这里明显看出n个点 ...
随机推荐
- HIVE 的MAP/REDUCE
对于 JOIN 操作: Map: 以 JOIN ON 条件中的列作为 Key,如果有多个列,则 Key 是这些列的组合 以 JOIN 之后所关心的列作为 Value,当有多个列时,Value 是这些列 ...
- 网络请求 post 的接受请求头的代理方法
接收响应头 content-Length content-Type - (void)connection:(NSURLConnection *)connection didReceiveRespons ...
- asp.net中下载功能
//流方式下载 protected void ButtonButtonDownload_Click(object sender, EventArgs e) { //string fileName = ...
- 解决iphone safari上的圆角问题
-webkit-appearance : none ; /*解决iphone safari上的圆角问题*/
- c# 捕捉键盘按键
//esc退出窗体 protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg , System.Windo ...
- jsp接收相同复合参数 request.getParameterValues()用法
在网站中往往需要用户选择复选框,此时需要创建多个复选框让用户进行选择: <head> <meta http-equiv="Content-Type" conten ...
- flash中函数的理解
flash 中的函数, 只有在调用时,会分配 数据地址(参数数据,返回数据等)和代码地址. 并运行语句,得到结果(返回数据). 结果(返回数据)赋值后 函数调用结束,释放所有建立的所有空间. ---- ...
- UVALive 6609 Minimal Subarray Length (查找+构建排序数组)
描述:给定n个整数元素,求出长度最小的一段连续元素,使得这段元素的和sum >= X. 对整个数组先求出sum[i],表示前i个元素的和,然后依次求出以a[i]为起点的,总和>= X的最小 ...
- Win2003部署Framework 4.5框架的MVC4项目
[一篮饭特稀原创,转载请注明出自http://www.cnblogs.com/wanghafan/p/4554672.html] Win2003中IIS6部署Framework 4.5框架的MVC4 ...
- char 与 unsigned char的本质区别
在C中,默认的基础数据类型均为signed,现在我们以char为例,说明(signed) char与unsigned char之间的区别 首先在内存中,char与unsigned char没有什么不同 ...