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 ...
随机推荐
- window下配置Apache2服务器
1:去Apache.org下载安装包 http://httpd.apache.org/ 2:解压到某一个目录 3:修改httpd.conf(Apache的解压目录和端口号) 4:管理员方式启动cmd执 ...
- conEmu的使用笔记
1.如何让conEmu成为windows的默认控制台程序? 解决:选中settings > Integration > Default Term里的Force ConEmu as defa ...
- 恶性循环中的永生bug,可以说是相当写实了
恶性循环中的永生bug,可以说是相当写实了
- ZH奶酪:PHP 使用DOMDocument操作XML
原文链接:http://my.oschina.net/zhangb081511/blog/160113 PHP写XML方法很多,这里主要介绍一下DOMDocument的用法,跟 JS大体上相同,其实非 ...
- 数据对接—kettle使用之四
上一篇介绍了表输出插件,并通过实例介绍插件的简单使用,如果有这样的需求大家可以参考一下并深入研究插件的其它细节设置.这一篇我们介绍和表输出对应的插件(表输入)的使用. 表输入: 1. 从步骤插入数据: ...
- 转:nginx基础概念(lingering_close)
lingering_close,字面意思就是延迟关闭,也就是说,当nginx要关闭连接时,并非立即关闭连接,而是再等待一段时间后才真正关掉连接.为什么要这样呢?我们先来看看这样一个场景.nginx在接 ...
- SQL Server配置支持中文
- python enum 枚举
http://www.cnblogs.com/codingmylife/archive/2013/05/31/3110656.html python 3.4+ from enum import Enu ...
- 规避javascript多人开发函数重名问题
命名空间 封闭空间 js模块化mvc(数据层.表现层.控制层) seajs 变量转换成对象的属性 对象化
- Webwork【02】前端OGNL试练
1.OGNL 出现的意义 在mvc中,数据是在各个层次之间进行流转是一个不争的事实.而这种流转,也就会面临一些困境,这些困境,是由于数据在不同世界中的表现形式不同而造成的: a. 数据在页面上是一个扁 ...
