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. 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
  2.  
  3. 最大化最小
    利用二分法将问题转化为判定型,然后使用2-SAT就可以了
  4.  
  5. 分析可知每个点只有两种情况,在正方形上面的中点和在正方形下面的中点。
    首先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. 基于jenkins自动打包并部署docker环境

    一.实验环境 git                      192.168.200.71 jenkins    192.168.200.72 docker               192.16 ...

  2. 苹果系统通过brew安装sshpass

    默认使用brew install sshpass会出现Warning: MD5 support is deprecated and will be removedin a future version ...

  3. vue+elementUI实现权限的部门管理

    回头看写过的项目,发现以前感觉有难度的地方,现在想想很简单,在此记录一下,不对的地方欢迎吐槽!!! 复制代码 1.实现效果 2.需求分析 主要用于平台各个部门不同权限的操作,将指定的账号放到对应的权限 ...

  4. C++编程入门题目--No.5

    题目: 输入三个整数x,y,z,请把这三个数由小到大输出. 程序分析: 我们想办法把最小的数放到x上,先将x与y进行比较,如果x>y则将x与y的值进行交换, 然后再用x与z进行比较,如果x> ...

  5. 数学--组合数学--当C(n,m)中n固定m++的递推模板

    ll power(ll a, ll b, ll p) { ll ans = 1 % p; for (; b; b >>= 1) { if (b & 1) ans = ans * a ...

  6. MySQL 数据库赋权

    1.进入数据库,查看数据库账户 # 进入数据库 mysql –u root –p ---> 输入密码... # 使用 mysql 库 use mysql; # 展示 mysql 库中所有表 sh ...

  7. 经过踩坑,搭建成功的Appium自动化测试环境

    因为最近本人准备搞app自动化,所以就搭建环境过程记录下来(主要踩过好几个坑) 期间有点烦躁,后面调整了下心态还是成功弄好了. 一.Appium环境搭建准备软件 所需要到的软件如下: 1.安装JDK1 ...

  8. Matlab2016b线性规划函数linprog的几个问题

    一.如何设置算法为单纯型法: options = optimoptions('linprog','Algorithm','dual-simplex') 二.linprog的参数用法: [x,Fval, ...

  9. zabbix部署与配置

    zabbix部署与配置 1.zabbix的web界面是基于php开发,所以创建lnmp环境来支持web界面的访问 yum install nginx php php-devel php-mysql p ...

  10. [hdu3572]最大流(dinic)

    题意:有m台机器,n个任务,每个任务需要在第si~ei天之间,且需要pi天才能完成,每台机器每天只能做一个任务,不同机器每天不能做相同任务,判断所有任务是否可以做完. 思路: 把影响答案的对象提取出来 ...