Map Labeler
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2047   Accepted: 682

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

最大化最小
利用二分法将问题转化为判定型,然后使用2-SAT就可以了 分析可知每个点只有两种情况,在正方形上面的中点和在正方形下面的中点。
首先e[i].x-e[j].x的绝对值小于diff才会有影响。
特殊情况是e[i].y==e[j].y,建4条边
而后e[i].y-e[j].y的绝对值小于diff时只能是一个向上一个向下,由此建两条边
然后就是e[i].y-e[j].y的绝对值小于diff时,那么如果上面的向下,下面的一定向下;同时下面的向上,那么上面的也一定向上,在由此建两条边就好了。

poj 2296的更多相关文章

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

  2. POJ 2296 Map Labeler(2-sat)

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

  3. POJ 2296 二分+2-sat

    题目大意: 给定n个点,给每个点都安排一个相同的正方形,使这个点落在正方形的下底边的中间或者上底边的中间,并让这n个正方形不出现相互覆盖,可以共享同一条边,求 这个正方形最大的边长 这里明显看出n个点 ...

  4. POJ 2296 Map Labeler

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

  5. Map Labeler POJ - 2296(2 - sat 具体关系建边)

    题意: 给出n个点  让求这n个点所能建成的正方形的最大边长,要求不覆盖,且这n个点在正方形上或下边的中点位置 解析: 当然是二分,但建图就有点还行..比较难想..行吧...我太垃圾... 2 - s ...

  6. POJ 2296 Map Labeler (2-Sat)

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

  7. Map Labeler (poj 2296 二分+2-SAT)

    Language: Default Map Labeler Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1815   Ac ...

  8. 【图论】2-sat总结

    2-sat总结 2-sat问题,一般表现的形式为.每一个点有两种方式a,b,要么选a,要么选b.而且点点之间有一些约束关系.比如:u和v至少一个选a.那么这就是一个表达式.把a当成真,b当成假,那就是 ...

  9. 关于2-sat的建图方法及解决方案

    转载增减: https://blog.csdn.net/qq_24451605/article/details/47126143 https://blog.csdn.net/u012915516/ar ...

随机推荐

  1. mysql-管理命令【创建用户、授权、修改密码、删除用户和授权、忘记root密码】

    一.创建用户 命令: CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 关键参数说明: username - 创建登录用户名, host ...

  2. Python下redis包安装

    找到Python的第三方包安装路径,在dos命令行中切换到该目录,输入: pip install redis 最后在Python解释器中即可.

  3. Ubuntu登陆时忘记密码怎么办

    有时候由于各种原因,用户会忘记自己登陆Ubuntu的登陆密码,这个时候我们能怎么办呢? 第一步:先重启电脑,开机时长按shift键,进入grub菜单: 第二步:按“e”键编辑启动项,显示如下图,将下图 ...

  4. Linux命令(4):touch

    功能说明: touch命令参数可创建新文件以及更改文档或目录的日期时间,包括存取时间和更改时间. 命令格式: touch [选项]... 文件... 命令参数: -a   或--time=atime或 ...

  5. mysql查询语句中like 的用法

    1.常见用法: (1)搭配%使用 %代表一个或多个字符的通配符,譬如查询字段name中以大开头的数据: (2)搭配_使用 _代表仅仅一个字符的通配符,把上面那条查询语句中的%改为_,会发现只能查询出一 ...

  6. Entity Framework使用EntityState和Attach来保存数据变化以及更新实体的个别字段

    在使用Entity Framework作为ORM来存取数据的过程中,最常规的操作就是对数据对象的更新.本文将会包含如何Attach Entity到一个数据Context中,以及如何使用EntitySt ...

  7. 《Docker从入门到跑路》之多阶段构建

    多阶段构建就是在一个Dokcerfile中定义多个FROM,每个FROM都可以使用不同的基础镜像,并表示开始一个新的构建阶段,我们可以很方便的将一个阶段的文件复制到另外一个阶段中,在最终的阶段保存你需 ...

  8. Java 创建并应用PPT幻灯片母版

    幻灯片母版,可在幻灯片中预先存储设计模板信息,包括字形.占位符大小或位置.背景设计和配色方案等:对设定好的母版可应用于所有幻灯片,也可设计多个不同母版应用于不同幻灯片.下面通过Java代码示例介绍如何 ...

  9. 使用npm发布插件

    使用npm发布插件 博客说明 文章所涉及的资料来自互联网整理和个人总结,意在于个人学习和经验汇总,如有什么地方侵权,请联系本人删除,谢谢! 简介 npm是一个全球性的包管理工具,上面有着许许多多的前端 ...

  10. 吃零食 csust oj 贪心

    吃零食 桌上有n袋零食,不同的零食会有不同的美味程度wi和腐坏程度di,每种零食在一单位时间内美味程度都会下降di,但是不会降到0以下. qwb每一单位时间可以吃掉一袋零食.现在qwb想要在吃完所有零 ...