• poj 2296


    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时,那么如果上面的向下,下面的一定向下;同时下面的向上,那么上面的也一定向上,在由此建两条边就好了。

  • 相关阅读:
    Python 认识元组
    Python 认识字典
    Python 字符串中常见的一些方法续
    python 打印 A ~ Z
    Python3的print怎么让它不换行
    Python 中的 lstrip、rstrip、strip
    Python判断一个字符串是否包含指定字符串的方法
    Python 字符串中常见的一些方法
    Python 认识字符串
    苹果电脑MacbookPro双开微信!
  • 原文地址:https://www.cnblogs.com/mfys/p/7301726.html
Copyright © 2020-2023  润新知