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个点 ...
随机推荐
- 如何根据w3wp.exe的进程pid查看是哪个应用程序池
如何根据w3wp.exe的进程pid查看是哪个应用程序池? 根据iisapp 查看PID所对应的IIS应用程序池及详细介绍: 从IIS6.0可以在IIS中架设多个站点并给每个站点指定不同的应用程序池, ...
- 异步委托 多线程实现摇奖器 winform版
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
- 创建第一个UI
创建一个2D UI 制作UI时,首先要创建UI的"根".在Unity顶部NGUI菜单中选择Create,然后选择2D UI. 创建完成后,在Scene窗口中,NGUI自动生成了一个 ...
- 魔兽争霸Ⅲ运行时不能初始化directX的错误解决
运行魔兽争霸3不能初始化DirectX错误这样解决: 1:在运行中输入(win+r):dxdiag,查看显示栏,确定电脑已安装好directx 8.1以上,且下面的三个加速都已开启. 2:如果没有安装 ...
- CODEVS 1004四子连棋
[题目描述 Description] 在一个4*4的棋盘上摆放了14颗棋子,其中有7颗白色棋子,7颗黑色棋子,有两个空白地带,任何一颗黑白棋子都可以向上下左右四个方向移动到相邻的空格,这叫行棋一步,黑 ...
- js中构造字符串若放入Grails中gsp的<g:link>标签出错
Grails的ajax使用json格式返回,在js中构造字符串时若放入<g:link>标签,字符串构造就会错误 如下就会发生错误,导致回调函数无法执行 function show(obj) ...
- Windows Phone 8 开发环境搭建
原地址:http://blog.csdn.net/md521/article/details/11015139 Windows Phone 8将采用与Windows 8相同的NT内核,这就意味着WP8 ...
- c helloworld on zynq
A linux os runs on zynq board. I want ro run a hello world c program on it. I linked zynq board to a ...
- c#中的delegate(委托)和event(事件)
c#中的delegate(委托)和event(事件) 一.delegate是什么东西? 完全可以把delegate理解成C中的函数指针,它允许你传递一个类A的方法m给另一个类B的对象,使得类B的对象能 ...
- java中path和classpath
Path 路径,是java编译时需要调用的程序(如java,javac等)所在的地方; CLASSPATH的作用是指定查找类的路径:当使用java命令执行一个类(类中的main方法)时,会从class ...