急~~航电的一道ACM题,求正确答案!

来源:百度知道 编辑:UC知道 时间:2024/05/19 20:18:32
最小点对问题 HDU1007: Quoit Design
Problem Description:Have you ever played quoit in a playground? Quoit is a game in which flat rings are pitched at some toys, with all the toys encircled awarded. In the field of Cyberground, the position of each toy is fixed, and the ring is carefully designed so it can only encircle one toy at a time. On the other hand, to make the game look more attractive, the ring is designed to have the largest radius. Given a configuration of the field, you are supposed to find the radius of such a ring. Assume that all the toys are points on a plane. A point is encircled by the ring if the distance between the point and the center of the ring is strictly less than the radius of the ring. If two toys are placed at the same point, the radius of the ring is considered to be 0.

Input:The input consists of several test cases. For each case, the first line contains an integer N (2 <= N <= 100,000), the total number of toys in the field. Then N lin

ac代码(G++提交):

#include <iostream>
#include <cmath>
using namespace std;

struct P { double x, y;} p[100003];
int n;
double ans;

bool cmp1(const P&a, const P&b) { return a.x == b.x ? a.y < b.y : a.x < b.x;}
bool cmp2(const P&a, const P&b) { return a.y == b.y ? a.x < b.x : a.y < b.y;}

void work()
{
for (int i=0; i<n; i++)
for (int j=i+1; j<n&&j<i+50; j++)
ans = min((p[i].x-p[j].x)*(p[i].x-p[j].x) + (p[i].y-p[j].y)*(p[i].y-p[j].y), ans);
}

int main()
{
while (scanf("%d", &n), n!=0)
{
for (int i=0; i<n; i++) scanf("%lf%lf", &p[i].x, &p[i].y);
ans = 2100000000;
sort(p, p+n, cmp1), work();
sort(p, p+n, cmp2), work();
printf("%.2lf\n", sqrt(ans)/2);
}
}