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

Sample Output

  1. 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,则除了上面的点放下方、下面的点放上方的情况都是可以的。

 
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4.  
  5. using namespace std;
  6.  
  7. const int VM=;
  8. const int EM=;
  9. const double eps=1e-;
  10.  
  11. struct Edge{
  12. int to,nxt;
  13. }edge[EM<<];
  14.  
  15. int n,m,cnt,dep,top,atype,head[VM];
  16. int dfn[VM],low[VM],vis[VM],belong[VM];
  17. int stack[VM],x[VM],y[VM];
  18.  
  19. void Init(){
  20. cnt=, atype=, dep=, top=;
  21. memset(head,-,sizeof(head));
  22. memset(vis,,sizeof(vis));
  23. memset(low,,sizeof(low));
  24. memset(dfn,,sizeof(dfn));
  25. memset(belong,,sizeof(belong));
  26. }
  27.  
  28. void addedge(int cu,int cv){
  29. edge[cnt].to=cv; edge[cnt].nxt=head[cu]; head[cu]=cnt++;
  30. }
  31.  
  32. void Tarjan(int u){
  33. dfn[u]=low[u]=++dep;
  34. stack[top++]=u;
  35. vis[u]=;
  36. for(int i=head[u];i!=-;i=edge[i].nxt){
  37. int v=edge[i].to;
  38. if(!dfn[v]){
  39. Tarjan(v);
  40. low[u]=min(low[u],low[v]);
  41. }else if(vis[v])
  42. low[u]=min(low[u],dfn[v]);
  43. }
  44. int j;
  45. if(dfn[u]==low[u]){
  46. atype++;
  47. do{
  48. j=stack[--top];
  49. belong[j]=atype;
  50. vis[j]=;
  51. }while(u!=j);
  52. }
  53. }
  54.  
  55. int abs(int x){
  56. return x<?-x:x;
  57. }
  58.  
  59. int solve(int mid){
  60. for(int i=;i<n;i++)
  61. for(int j=i+;j<n;j++)
  62. if(abs(x[i]-x[j])<mid && abs(y[i]-y[j])<*mid){
  63. if(abs(y[i]-y[j])>=mid){
  64. if(y[i]<y[j]){
  65. addedge(*i+,*j+);
  66. addedge(*j,*i);
  67. }else{
  68. addedge(*i,*j);
  69. addedge(*j+,*i+);
  70. }
  71. }else if(y[i]<y[j]){
  72. addedge(*i+,*i);
  73. addedge(*j,*j+);
  74. }else if(y[i]>y[j]){
  75. addedge(*i,*i+);
  76. addedge(*j+,*j);
  77. }else{
  78. addedge(*i+,*j);
  79. addedge(*i,*j+);
  80. addedge(*j,*i+);
  81. addedge(*j+,*i);
  82. }
  83. }
  84.  
  85. for(int i=;i<*n;i++)
  86. if(!dfn[i])
  87. Tarjan(i);
  88. for(int i=;i<*n;i+=)
  89. if(belong[i]==belong[i^])
  90. return ;
  91. return ;
  92. }
  93.  
  94. int main(){
  95.  
  96. //freopen("input.txt","r",stdin);
  97.  
  98. int t;
  99. scanf("%d",&t);
  100. while(t--){
  101. scanf("%d",&n);
  102. for(int i=;i<n;i++)
  103. scanf("%d%d",&x[i],&y[i]);
  104. int l=,r=,mid,ans=;
  105. while(l<=r){
  106. Init(); //因为二分每次都得重新建边,所以初始化在这里
  107. mid=(l+r)>>;
  108. if(solve(mid)){ //return true,说明边太少了,应该增大mid,所以l = mid
  109. l=mid+;
  110. ans=mid;
  111. }else //return false,说明边太多了,应该减小mid,所以r = mid
  112. r=mid-;
  113. }
  114. printf("%d\n",ans);
  115. }
  116. return ;
  117. }

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. Kafka:ZK+Kafka+Spark Streaming集群环境搭建(十九)ES6.2.2 安装Ik中文分词器

    注: elasticsearch 版本6.2.2 1)集群模式,则每个节点都需要安装ik分词,安装插件完毕后需要重启服务,创建mapping前如果有机器未安装分词,则可能该索引可能为RED,需要删除后 ...

  2. 一分钟读懂互联网广告竞价策略GFP+GSP+VCG

    原文:http://ju.outofmemory.cn/entry/116780 一分钟读懂互联网广告竞价策略GFP+GSP+VCG 两个广告位,三家广告主竞价,广告平台究竟应该制定广告竞价策略呢?这 ...

  3. MySQL表级锁和行级锁

    一:概述 相对其他数据库而言,MySQL的锁机制比较简单,其最显著的特点是不同的存储引擎支持不同的锁机制.比如,MyISAM和MEMORY存储引擎采用的是表级锁(table-level locking ...

  4. Springmvc 服务器端文件下载

    转自:http://blog.csdn.net/boneix/article/details/51303280 业务场景:点击下载后直接保存而不是打开 解决代码:前端传入url /** * 返回流 * ...

  5. Oracle——数据库启动与关闭

    本文内容 服务器环境 客户端环境 概述 启动数据库 关闭数据库 补充 参考资料 本文说明 Oracle 数据库的启动和关闭,内容虽然基础,但是在数据库很多操作中都需要,因此,基础而重要,必须深入理解. ...

  6. WIN10系统如何隐藏底部搜索框

    右击任务栏,搜索,可以切换三种模式,建议还是显示搜索图标,因为这个搜索还是能比较快速定位到系统功能的,只不过显示搜索框的话比较占地方,不方便

  7. spring boot使用slf4j输出日志

    spring boot使用slf4j输出日志 https://blog.csdn.net/qq442270636/article/details/79406346 Spring Boot SLF4J日 ...

  8. JavaScript 之 动态加载JS代码或JS文件

    2.动态加载JS文件 <script type="text/javascript"> function loadScript(url, callback) { var ...

  9. 当Ruby的model名字出错时,在现实view时显示错误的提示

    app/controllers/courses_controller.rb:1:in `<top (required)>' app/controllers/courses_controll ...

  10. 第五周 Word注释与交叉引用

    第五周 Word注释与交叉引用 教学时间 2013-3-26 教学课时 2 教案序号 4 教学目标 1.掌握脚注.尾注.题注的概念和应用 2.掌握交叉引用的操作方法 教学过程: 复习提问 1.如何利用 ...