Map Labeler (poj 22,962 min. +2-sat)

Source: Internet
Author: User

Language:DefaultMap Labeler
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 1815 Accepted: 599

Description

Map generation is a difficult task in cartography. A vital part of such task was automatic labeling of the cities in a map; Where for each city there is the text label to being attached to its location, so, no, and labels overlap. In this problem, we is concerned with a simple case of automatic map labeling.

Assume a point on the plane, and its label are a text bounded in a square with edges parallel to X and Y Axis. The label of each city should is 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 is all of the same size, and no to labels overlap, although they may share one EDG E. Figure 1 depicts a example of a good labeling (the texts of the labels is not shown.)

Given the coordinates of all city points on the map as integers values, you is to find the maximum label size (an integer Value) Such a good labeling exists for the map.

Input

The first line contains a single integer t (1 <= t <=), 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) are the y coordinates of one city on the map ( -10000≤x, y≤10000). Note that no and both cities have the same (x, y) coordinates.

Output

The output would be is one line per each test case containing the maximum possible label size (an integer value) for a good LA Beling.

Sample Input

161 12 33 24 410 42 5

Sample Output

2

Source

Tehran 2003


Test instructions: There are n points on the plane, each point draws a square and the point falls to the top of the square or the middle of the bottom, asking how much the side length of the largest square satisfies the condition.

Train of thought: Two sides long mid, the map uses 2-sat as the judging condition.

I mean it's drawn on top, ~i.
If|xi-xj|>=mid continue;
else if |yi-yj|>=2*mid continue;
else if |yi-yj|==0 then i->~j,~i->j,j->~i,~j->i;
else if |yi-yj|>0 then ~i->i,j->~j;
else |yi-yj|>=mid then j->i,~i->~j;

Code:

#include <iostream> #include <functional> #include <cstdio> #include <cstring> #include < algorithm> #include <cmath> #include <string> #include <map> #include <stack> #include < vector> #include <set> #include <queue> #pragma comment (linker, "/stack:102400000,102400000") #define Pi  ACOs ( -1.0) #define EPS 1e-6#define lson rt<<1,l,mid#define rson rt<<1|1,mid+1,r#define FRE (i,a,b) for (i = A; I <= b;  i++) #define FREE (i,a,b) for (i = A, I >= b; i--) #define FRL (i,a,b) for (i = A; I < b; i++) #define FRLL (i,a,b) for (i = A i > B; i--) #define MEM (T, v) memset ((t), V, sizeof (t)) #define SF (n) scanf ("%d", &n) #define SFF (A, b) scanf ("%d%d         ", &a, &b) #define SFFF (a,b,c) scanf ("%d%d%d ", &a, &b, &c) #define PF Printf#define DBG PF ("hi\n") typedef long long ll;using namespace std; #define INF 0x3f3f3f3f#define mod 1000000009const int maxn = 1005;co NST int MAXN = 2005;const int MAXM = 20010;const int N = 1005;struct node{int x, y;} node[maxn];struct edge{int to,next;} Edge[maxm];int tot,head[maxn];int low[maxn],dfn[maxn],stack[maxn],belong[maxn];bool Instack[MAXN];int TOP,SCC,    Index;void init () {tot=0; memset (head,-1,sizeof (Head));}    void Addedge (int u,int v) {edge[tot].to=v;    Edge[tot].next=head[u]; head[u]=tot++;}    void Tarjan (int u) {int V;    low[u]=dfn[u]=index++;    Instack[u]=true;    Stack[top++]=u;        for (int i=head[u];~i;i=edge[i].next) {int v=edge[i].to; if (!            Dfn[v]) {Tarjan (v);        if (Low[u]>low[v]) low[u]=low[v];    } else if (Instack[v]&&low[u]>dfn[v]) low[u]=dfn[v];        } if (Low[u]==dfn[u]) {scc++;            do{V=stack[--top];            Instack[v]=false;        BELONG[V]=SCC;    }while (V!=u); } return;    BOOL Solvable (int n) {memset (dfn,0,sizeof (DFN));    memset (instack,false,sizeof (instack)); Top=scc=index=0; for (int i=0;i<n;i++) {if (!    Dfn[i]) Tarjan (i);    } for (int i=0;i<n;i+=2) {if (belong[i]==belong[i^1]) return false; } return true;    BOOL isOK (int mid,int N)//based on mid build {init (); for (int i=0;i<n;i++) {for (int j=i+1;j<n;j++) {if (ABS (node[i].x-node[j].x) >=mid)            Continue            if (ABS (NODE[I].Y-NODE[J].Y) >=2*mid) continue;                if (node[i].y==node[j].y) {Addedge (2*i,2*j+1);                Addedge (2*j+1,2*i);                Addedge (2*j,2*i+1);            Addedge (2*I+1,2*J); } else if (Node[i].y-node[j].y>0&&node[i].y-node[j].y<mid) {Addedge (                I+1,2*i);            Addedge (2*j,2*j+1); } else if (Node[j].y-node[i].y>0&&node[j].y-node[i].y<mid) {Addedge (                J+1,2*J);  Addedge (2*i,2*i+1);          } else if (Node[i].y-node[j].y>=mid) {Addedge (2*i+1,2*j+1);            Addedge (2*j,2*i);                } else if (Node[j].y-node[i].y>=mid) {Addedge (2*j+1,2*i+1);            Addedge (2*I,2*J);    }}} if (solvable (2*n)) return true; return false;}    void solve (int n)//two min {int l=0,r=10000,ans;        while (l<=r) {//DBG;        int mid= (L+R) >>1;            if (isOK (mid,n)) {//DBG;            Ans=mid;        l=mid+1;    } else r=mid-1; } printf ("%d\n", ans);}    int main () {#ifndef Online_judge freopen ("C:/users/lyf/desktop/in.txt", "R", stdin), #endif int i,j,t,m;    scanf ("%d", &t);        while (t--) {scanf ("%d", &m);        for (i=0;i<m;i++) scanf ("%d%d", &node[i].x,&node[i].y);    Solve (m); } return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Map Labeler (poj 22,962 min. +2-sat)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.