Hdu1007--quoit Design (planar closest point pair)

Source: Internet
Author: User

Problem Description

Has the ever played Quoit in a playground? Quoit is a game in which flat rings be pitched at some toys, with all the toys encircled awarded.
The field of Cyberground, the position of each toy are 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 was designed to the largest radius. Given a configuration of the field, you is supposed to find the radius of such a ring.
Assume that all the toys is points on a plane. A point was encircled by the ring if the distance between the point and the center of the ring are strictly less than the RA Dius of the ring. If the placed at the same point, the radius of the ring was considered to be 0.

Input

The input consists of several test cases. For each case, the first line contains a integer N (2 <= N <= 100,000), the total number of the toys in the field. Then N lines follow, each contains a pair of (x, y) which is the coordinates of a toy. The input is terminated by N = 0.

Output

For all test case, print in one line the radius of the ring required by the Cyberground manager, accurate up to 2 decimal Places.

Sample Input

20 01 121 11 13-1.5 00 00 1.50

Sample Output

0.710.000.75

Author

CHEN, Yue

Source

ZJCPC2004

Recommend

Jgshining

Effect:

There are n points in the plane, so that a circle with a fixed radius can only enclose the maximum radius of one point at a time

That is, to find the nearest point pair in the point set

Ideas:

Using the divide-and-conquer method introduced in the introduction of the algorithm in section 33.4 to find the plane nearest point pair, the time complexity is: O (NLOGN)

Code:

//Planar nearest point pair, using divide-and-conquer method#include <stdio.h>#include<string.h>#include<algorithm>#include<iostream>#include<math.h>using namespacestd;Const DoubleEPS = 1e-6;Const intMAXN =100010;Const DoubleINF =1e20;structpoint{Doublex, y;};DoubleDist (Point A, point B) {returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-b.y));} Point P[MAXN]; Point TMPT[MAXN];BOOLCmpxy (Point A, point B)//comparison function when sorting{    if(a.x! = b.x)returnA.x <b.x; Else returnA.y <b.y;}BOOLCmpy (Point A, point B)//Sort by Y value{    returnA.y <b.y;}DoubleClosest_pair (intLeftintRight ) {    DoubleD =INF; if(left = right)returnD; if(Left +1==Right )returnDist (P[left], p[right]);//recursive boundary    intMid = (left + right)/2; DoubleD1 = Closest_pair (left, mid);//Divide and conquer the nearest point pair of the two-point set    DoubleD2 = Closest_pair (mid +1, right); D=min (d1, D2); intK =0;  for(inti = left; I <= right; i++)    {        if(Fabs (p[mid].x-p[i].x) <=d) Tmpt[k++] =P[i]; }        //Tmpt is a collection of points with a centerline distance less than or equal to DSort (tmpt, Tmpt +K, cmpy);  for(inti =0; I < K; i++)    {         for(intj = i +1; J < K && Tmpt[j].y-tmpt[i].y < D; J + +) {D=min (d, Dist (Tmpt[i], tmpt[j])); }    }//results of merger and treatment    returnD;}intMain () {intN;  while(SCANF ("%d", &n) = =1&&N) { for(inti =0; I < n; i++) scanf ("%LF%LF", &p[i].x, &p[i].y); Sort (p, p+ N, cmpxy);//to pre-sort pprintf"%.2lf\n", Closest_pair (0N1) /2); }    return 0;}

Hdu1007--quoit Design (planar closest point pair)

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.