POJ 2296 Map Labeler (2-Sat)
| 
 Map Labeler 
 Description Map generation is a difficult task in cartography. A vital part of such task is automatic labeling of the cities in a map; where for each city there is text label to be attached to its location, so that no two labels overlap. In this problem, we are concerned with a simple case of automatic map labeling.
 
Assume that each city is a point on the plane, and its label is a text bounded in a square with edges parallel to x and y axis. The label of each city should be located such that the city point appears exactly in the middle of the top or bottom edges of the label. In a good labeling, the square labels are all of the same size, and no two labels overlap, although they may share one edge. Figure 1 depicts an example of a good labeling (the texts of the labels are not shown.) Given the coordinates of all city points on the map as integer values, you are to find the maximum label size (an integer value) such that a good labeling exists for the map.  Input The first line contains a single integer t (1 <= t <= 10), the number of test cases. Each test case starts with a line containing an integer m (3 ≤ m ≤ 100), the number of cities followed by m lines of data each containing a pair of integers; the first integer (X) is the x and the second one (Y) is the y coordinates of one city on the map (-10000 ≤X, Y≤ 10000). Note that no two cities have the same (x, y) coordinates. 
Output The output will be one line per each test case containing the maximum possible label size (an integer value) for a good labeling. 
Sample Input 1 Sample Output 2 Source  | 
题意:给你n个点,要你在这n个点上方一个正方形,点只能在正方形的上边或下边的中点上,所有正方形大小一样,不能重叠,求最大的正方形
二分+2-SAT可行性判断
题意:给你n个点,要你在这n个点上放一个正方形,点
只能在正方形的上边或下边的中点上,所有正方形大小一样,
不能重叠,求最大的正方形。。。
如果abs(s[i].x-s[j].x)>=r则可以随便放
如果 abs[s[i].x-s[j].y)<r;
   如果abs(s[i].y-s[j].y)<r,如果s[i].y==s[i].y则要求一个放上面一个放下面。
                            否则只能是上面的点放上面,下面的点放下面。
   如果r<=abs(s[i].y-s[j].y)<2*r,则除了上面的点放下方、下面的点放上方的情况都是可以的。
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int VM=;
const int EM=;
const double eps=1e-; struct Edge{
int to,nxt;
}edge[EM<<]; int n,m,cnt,dep,top,atype,head[VM];
int dfn[VM],low[VM],vis[VM],belong[VM];
int stack[VM],x[VM],y[VM]; void Init(){
cnt=, atype=, dep=, top=;
memset(head,-,sizeof(head));
memset(vis,,sizeof(vis));
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
memset(belong,,sizeof(belong));
} void addedge(int cu,int cv){
edge[cnt].to=cv; edge[cnt].nxt=head[cu]; head[cu]=cnt++;
} void Tarjan(int u){
dfn[u]=low[u]=++dep;
stack[top++]=u;
vis[u]=;
for(int i=head[u];i!=-;i=edge[i].nxt){
int v=edge[i].to;
if(!dfn[v]){
Tarjan(v);
low[u]=min(low[u],low[v]);
}else if(vis[v])
low[u]=min(low[u],dfn[v]);
}
int j;
if(dfn[u]==low[u]){
atype++;
do{
j=stack[--top];
belong[j]=atype;
vis[j]=;
}while(u!=j);
}
} int abs(int x){
return x<?-x:x;
} int solve(int mid){
for(int i=;i<n;i++)
for(int j=i+;j<n;j++)
if(abs(x[i]-x[j])<mid && abs(y[i]-y[j])<*mid){
if(abs(y[i]-y[j])>=mid){
if(y[i]<y[j]){
addedge(*i+,*j+);
addedge(*j,*i);
}else{
addedge(*i,*j);
addedge(*j+,*i+);
}
}else if(y[i]<y[j]){
addedge(*i+,*i);
addedge(*j,*j+);
}else if(y[i]>y[j]){
addedge(*i,*i+);
addedge(*j+,*j);
}else{
addedge(*i+,*j);
addedge(*i,*j+);
addedge(*j,*i+);
addedge(*j+,*i);
}
} for(int i=;i<*n;i++)
if(!dfn[i])
Tarjan(i);
for(int i=;i<*n;i+=)
if(belong[i]==belong[i^])
return ;
return ;
} int main(){ //freopen("input.txt","r",stdin); int t;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d%d",&x[i],&y[i]);
int l=,r=,mid,ans=;
while(l<=r){
Init(); //因为二分每次都得重新建边,所以初始化在这里
mid=(l+r)>>;
if(solve(mid)){ //return true,说明边太少了,应该增大mid,所以l = mid
l=mid+;
ans=mid;
}else //return false,说明边太多了,应该减小mid,所以r = mid
r=mid-;
}
printf("%d\n",ans);
}
return ;
}
POJ 2296 Map Labeler (2-Sat)的更多相关文章
- POJ 2296 Map Labeler(2-sat)
		
POJ 2296 Map Labeler 题目链接 题意: 坐标轴上有N个点.要在每一个点上贴一个正方形,这个正方形的横竖边分别和x,y轴平行,而且要使得点要么在正方形的上面那条边的中点,或者在以下那 ...
 - 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 3678 Katu Puzzle(2 - SAT) - from lanshui_Yang
		
Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a ...
 - POJ 2296 Map Labeler
		
二分答案 + 2-SAT验证,判断正方形是否相交写起来有点烦,思路还是挺简单的. #include<cstdio> #include<cstring> #include< ...
 - POJ 2251 Dungeon Master(地牢大师)
		
p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...
 - poj 3335 Rotating Scoreboard(半平面交)
		
Rotating Scoreboard Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6420 Accepted: 25 ...
 - C++ map使用(基于hashtable)
		
C++ map使用(基于hashtable) 实际上基于hashtable的map有两种一种是hash_map,unordered_map,但是最好使用后者,原因如下[1] 因为标准化的推进,unor ...
 - POJ 2376 Cleaning Shifts(轮班打扫)
		
POJ 2376 Cleaning Shifts(轮班打扫) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] Farmer ...
 - POJ 3253 Fence Repair(修篱笆)
		
POJ 3253 Fence Repair(修篱笆) Time Limit: 2000MS Memory Limit: 65536K [Description] [题目描述] Farmer Joh ...
 
随机推荐
- Nginx配置基于多域名、端口、IP的虚拟主机
			
原文:https://www.cnblogs.com/ssgeek/p/9220922.html ------------------------------- Nginx配置基于多域名.端口.IP的 ...
 - 转: git使用时让http记住帐号密码
			
见 http://git.mydoc.io/?t=154710 https 方式每次都要输入密码,按照如下设置即可输入一次就不用再手输入密码的困扰而且又享受 https 带来的极速 按照以下设置记住密 ...
 - servlet种下cookie后如何携带cookie继续往下走
			
事情是这样的,今天我在应用1里面手动种下了一个cookie,然后它会发接着访问应用2,因为是我手动setCookie,所以它还没来得及携带cookie继续前往下一站,于是,apple pen,炸了. ...
 - Oracle PGA
			
PGA(Process Global Area),是server process一段私有内存区,它包含有全局变量,数据结构和一些控制信息.在Oracle8i 中,PGA调整非常复杂,要调整SORT_A ...
 - @TargetAPI + 版本判断实现高低API版本兼容
			
安卓开发中,在低版本SDK使用高版本的API会报错.一般处理方法是换一种实现方法,或者在高版本SDK中使用高版本API,低版本SDK中使用效果可能会差点的折衷方案:后者可以用如下技巧来实现. 步骤 S ...
 - C#.NET常见问题(FAQ)-如何判断两个类是否相同类型
			
可以用is方法判断是否是一个类 更多教学视频和资料下载,欢迎关注以下信息: 我的优酷空间: http://i.youku.com/acetaohai123 我的在线论坛: http://csr ...
 - HDU1069(还是dp基础)
			
今天不想说太多废话-由于等下要写自己主动提交机. 不知道能不能成功呢? 题目的意思就是,一个猴子,在叠砖头 ...以下的要严格大于上面的.求叠起来最高能到多少- n非常少,n^2算法毫无压力-话说dp ...
 - js - object.assign 以及浅、深拷贝
			
浅(引用)拷贝:共用同一内存地址,你改值我也变 譬如常用的对象赋值操作 深拷贝:深拷贝即创建新的内存地址保存值(互不影响) 譬如以下 const shallBasicCopy = obj => ...
 - 什么是Session分布式共享
			
在了解session分布式共享之前先来了解Session.Redis和Nginx的相关知识. 一.Session相关知识 1.Session 介绍 Session在网络应用中,称为“会话控制”. 每个 ...
 - 好久不git这么多问题
			
本来想把本地项目上传GitHub一下,打开gitbash, git init 之前配置过了 用户名和邮箱以及ssh等 $ git remote add origin https://github.co ...
 
			
		