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. javascript捕获事件event

    var e = e ? e : window.event; window.event ? window.event.cancelBubble = true : e.stopPropagation(); ...

  2. GPUImage简单滤镜使用(二)

    GPUImage中,提供了许多简单的的常用的滤镜.在上一篇文章讲了如何调节图像的亮度这片文章讲一下如何通过GPUImage调节图像的对比度,饱和度,曝光度,和白平衡(美图秀秀中的色温). 原图像 调整 ...

  3. Javascript 创建对象的三种方法及比较【转载+整理】

    https://developer.mozilla.org/zh-CN/docs/JavaScript/Guide/Inheritance_and_the_prototype_chain 本文内容 引 ...

  4. gcc 0长数组学习

    首先,我们要知道,0长度的数组在ISO C和C++的规格说明书中是不允许的.这也就是为什么在VC++2012下编译你会得到一个警告:“warning C4200: 使用了非标准扩展 : 结构/联合中的 ...

  5. PHP 字符串编码的转换

    原文链接:http://mangguo.org/php-string-encoding-convert-and-detect/ GBK 和 UTF-8 编码的转换是一个非常恶心的事情,比如像 PHP ...

  6. bootstrap——强大的网页设计元素模板

    本文介绍一个网页设计工具——bootstrap,它包含了很多华丽的按钮及排版,我们可以在网页设计中直接使用它,尤其是加入我们只是想简单的使用一下的话,将会是一个不错的选择,下面是几张examples, ...

  7. flume杀掉重启

    Flume在启动的过程中加了一个钩子处理线程,用kill -3或者kill杀掉Flume进程,这样能通知钩子线程去关闭这些tmp文件 直接kill-9 会永久保留hdfs上的tmp后缀文件

  8. 算法笔记_222:串中取3个不重复字母(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 从标准输入读入一个由字母构成的串(不大于30个字符). 从该串中取出3个不重复的字符,求所有的取法. 取出的字符,要求按字母升序排列成一个串. 不同 ...

  9. MYSQL优化优化再优化!

    1.数据库设计和表创建时就要考虑性能 2.sql的编写需要注意优化 3.分区 4.分表 5.分库 .数据库设计和表创建时就要考虑性能 mysql数据库本身高度灵活,造成性能不足,严重依赖开发人员能力. ...

  10. Linux文件与目录操作

    1:目录操作指令 cd :切换目录 pwd:显示当前目录 mkdir:创建一个新目录 rmdir:删除一个空的目录rmdir -r:删除一个非空目录 . :此层目录 .. :上层目录 -:前一个工作目 ...