24h購物| | PChome| 登入
2013-05-09 08:49:54| 人氣960| 回應2 | 上一篇 | 下一篇

[UVA][最鄰近點對] 11378 - Bey Battle

推薦 0 收藏 0 轉貼0 訂閱站台

Problem B

Bey Battle

Time Limit: 4 Second

 

 

Dark Blader has returned with new tactics. They are now able to create an energy field around its blade and if any blade enters inside any of these energy fields the energy level of the Bit-beast drastically decreases. So Tyson had to avoid these energy fields and finally he has won!

 

I was lucky enough to be around Kenny who was analyzing the game with his PC and helping Tyson to avoid the energy field. I saw that the energy field was Square in shape and the blade was at its centre. At that instant a problem came to my mind and let me see how efficiently you can solve that problem.

 

There will be N points in a 2D plane. Find out the maximum size such that if you draw such size squares around each point (that point will be at the center of the square) no two squares will intersect each other (can touch but not intersect). To make the problem simple the sides of the squares will be parallel to X and Y axis.

 

Input:

Input contains several test cases. Each case starts with N which will be at most 10,000 except one case which will be 100,000. Then there are N lines- pairs of integers denoting the coordinate of each point. The absolute value of the integers can be at most 1,000,000. X or Y coordinate of any two points will be unequal.

 

Output:

Output a single line for each test case- maximum side length of square.

 

SAMPLE INPUT

OUTPUT FOR SAMPLE INPUT

2

0 0

2 2

2

 

 

Problemsetter: Md. Mahbubul Hasan


題目描述:

平面上有 N 個點,將每個點都做為中心的正方形,其邊長都要一樣。
問這些正方形不牴觸(不相交)的最大邊長為何?

解法:

說是最大邊長,事實上也是拋棄 "歐幾里德距離",
計算任兩點 max(abs(pi.x - pj.x), abs(pi.y - pj.y)) 最小化為多少。
用最鄰近點對的 D&C 去解決。


#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
struct Pt {
    int x, y;
    bool operator<(const Pt &a) const {
        if(x != a.x)
            return x < a.x;
        return y < a.y;
    }
};
Pt D[100005];
void closestPair(int l, int r, int &ret) {
    if(l >= r)  return;
    int m = (l+r)/2;
    closestPair(l, m, ret);
    closestPair(m+1, r, ret);
    static int i, j;
    for(i = m; i >= l; i--) {
        if(D[m].x-D[i].x >= ret)
            break;
        for(j = m+1; j <= r; j++) {
            if(D[j].x-D[i].x >= ret)
                break;
            ret = min(ret, max(D[j].x-D[i].x, abs(D[j].y-D[i].y)));
        }
    }
}
int main() {
    int n, i;
    while(scanf("%d", &n) == 1) {
        for(i = 0; i < n; i++)
            scanf("%d %d", &D[i].x, &D[i].y);
        sort(D, D+n);
        int ret = 0xfffffff;
        closestPair(0, n-1, ret);
        printf("%d\n", ret);
    }
    return 0;
}

台長: Morris
人氣(960) | 回應(2)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][線段交點、射線法] 10321 - Polygon Intersection
此分類上一篇:[UVA][用線段樹建表] 10909 - Lucky Number

sexe videos
Thank you..
2018-06-09 23:13:36
sesso videos
Thank you..
2018-06-09 23:14:32
是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文