uva 11378 - Bey Battle (最近点对变形)

本文介绍了一种在特定比赛中避免能量场干扰的战术,并通过算法分析了如何在二维平面上找到最大尺寸的正方形,使得这些正方形不会相互交叠。文章提供了完整的代码实现,并解释了算法背后的逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

距离的含义有点不同。没有用分治法去做,维护一个当前已知的最短距离,然后从左向右扫描一下就可以了。

#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <iostream>
#include <stack>
#include <set>
#include <cstring>
#include <stdlib.h>
#include <cmath>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 100000+5;
const int INF = 1000000000;

P p[maxn];

int dis(int x, int y){
    return max(abs(p[x].first-p[y].first), abs(p[x].second-p[y].second));
}

int main(){
    int n;
    while(scanf("%d", &n) != EOF){
        for(int i = 0;i < n;i++){
            int x, y;
            scanf("%d%d", &x, &y);
            p[i] = P(x, y);
        }
        if(n == 1){
            printf("0\n");
            continue;
        }
        sort(p, p+n);
        int ans = INF;
        for(int i = 0;i < n;i++){
            for(int j = i+1;j < n;j++){
                if(p[j].first-p[i].first >= ans)
                    break;
                ans = min(ans, dis(i, j));
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值