Map Labeler
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1267   Accepted: 409

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
6
1 1
2 3
3 2
4 4
10 4
2 5

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)的更多相关文章

  1. POJ 2296 Map Labeler(2-sat)

    POJ 2296 Map Labeler 题目链接 题意: 坐标轴上有N个点.要在每一个点上贴一个正方形,这个正方形的横竖边分别和x,y轴平行,而且要使得点要么在正方形的上面那条边的中点,或者在以下那 ...

  2. 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 ...

  3. 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 ...

  4. POJ 2296 Map Labeler

    二分答案 + 2-SAT验证,判断正方形是否相交写起来有点烦,思路还是挺简单的. #include<cstdio> #include<cstring> #include< ...

  5. POJ 2251 Dungeon Master(地牢大师)

    p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...

  6. poj 3335 Rotating Scoreboard(半平面交)

    Rotating Scoreboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6420   Accepted: 25 ...

  7. C++ map使用(基于hashtable)

    C++ map使用(基于hashtable) 实际上基于hashtable的map有两种一种是hash_map,unordered_map,但是最好使用后者,原因如下[1] 因为标准化的推进,unor ...

  8. POJ 2376 Cleaning Shifts(轮班打扫)

    POJ 2376 Cleaning Shifts(轮班打扫) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] Farmer ...

  9. POJ 3253 Fence Repair(修篱笆)

    POJ 3253 Fence Repair(修篱笆) Time Limit: 2000MS   Memory Limit: 65536K [Description] [题目描述] Farmer Joh ...

随机推荐

  1. 10个在UNIX或Linux终端上快速工作的建议

    你有没有惊讶地看到有人在Unix/ Linux中工作得非常快,噼里啪啦的敲键盘,快速的启动命令,飞快地执行命令? 在本文中,我共享了一些在Linux中快速.高效工作所遵循的Unix/ Linux命令实 ...

  2. Oracle数据表中输入引号等特殊字符

    Oracle输入特殊字符的特殊方法: UPDATE BOOKMARK SET BM_VALUE=q'/ --在这里写下需要输入的内容(可以包括引号.回车等特殊的符号),所见即所得 /' -- WHER ...

  3. 自定义控件之万能Repeater源码

    using System.ComponentModel; using System.Web.UI; [assembly: TagPrefix("Jinlong.Control", ...

  4. PLT redirection through shared object injection into a running process

    PLT redirection through shared object injection into a running process

  5. Windows上Boost的编译步骤

    一.FQ下载Boost最新版本 官网:http://www.boost.org/ 假设解压到:D:\Applicaton\DevTools\boost\boost_1_65_1 二.使用VS编译器 c ...

  6. C# 通过SendMessage获取浏览器地址栏的地址

    1:通过SPY++获得地址栏的层次结构,然后一层一层获得 2:代码 using System; using System.Collections.Generic; using System.Linq; ...

  7. Word转PDF非常好用的软件——pdfFactory Pro

    pfdFactory Pro把word转为pdf的操作步骤: 1.打开将要转换的word的文档: 2.文件--->打印: 弹出如下对话框: 单击确定后弹出:

  8. python中string和十六进制、二进制互转

    def str_to_hex(s): return ' '.join([hex(ord(c)).replace('0x', '') for c in s]) def hex_to_str(s): re ...

  9. 简述一下 src 与 href 的区别

    href 是指向网络资源所在位置,建立和当前元素(锚点)或当前文档(链接)之间的链接,用于超链接. src是指向外部资源的位置,指向的内容将会嵌入到文档中当前标签所在位置:在请求src资源时会将其指向 ...

  10. vim 窗口操作:多tab|窗口拆分

    转 我是一个vimer,还在用着这个上古时代的编辑器,但我并不是守旧派,因为即使是 现在,vim也在不断的创新.我用vim也有一两年的光景了,但是我还是不敢我自己 精通vim,当然我使用vim基本是两 ...