HDU 1007 Quoit Design (most recent point pair)

Source: Internet
Author: User
Quoit DesignProblem Description has 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 on one line the radius of the ring required by the Cyberground manager, accurate up to 2 Decimal places.

Sample Input
2 0 0 1 1 2 1 1 1 1 3-1.5 0 0 0 0 1.5 0
Sample Output
0.71
0.00
0.75

"Thinking Analysis"
Find the nearest point pair in a plane. The main point of use is the idea of dichotomy.
That is, the points are sorted by the horizontal axis from small to large, the point set is divided into two parts, and then find the two parts of the nearest point pair, and has been two points down. Finally, the distance of the nearest point pair to the left is D1, the distance of the nearest point pair to the right is D2, and δ= min (d1,d2) is set. However, δ is not necessarily the final result, because if two points are located on both sides of the midpoint, they may be smaller than Δ, so further confirmation is required.

As shown in the figure above (stolen image = =), set the centerline L to the whole S region for the SL and SR two regions, and set Δ to two the nearest point to the distance of the minimum value, with L as the axis of symmetry, δ wide, to the left and right to do a long zone, then the distance between the points in this area may be less Write a direct sentence fabs (p[i].x-p[mid].x) value is less than Δ, if satisfied, then record the number position of the point I.




The points that meet the above criteria are then grouped into array B by the ordinate from small to large (note that they are sorted together instead of sorted by left and right, for reasons below). For the two points on the left of the above figure p, Q, it is possible that the nearest point pair.
Further discussion, as shown in the diagram on the right, over point P do the vertical line of L, and do two with the perpendicular to the public side of the delta as the side length of the square, then there is a maximum of 6 points in the area (that is, two square 6 vertices, because l the right area of two points between the minimum distance is δ). Therefore, for each point in array B, you only need to determine the distance from the next 6 points.
Why is the six points after the judgment instead of the other side corresponding to the top three points and the following three points? This is because the distance from the left side of the point to the right and the point on the right of the L is the same distance from the point on the left (some rap ...). )。 Or to give a concrete example, see the left side of the figure, the P-point and the right Q point, when the P point and the top right of the Q point of the distance, it is equivalent to calculate the Q point and the lower left of the P-point distance, so in the judgment Q Point is not necessary and its lower point to compare. This is why the left and right side of the point on the order of the reasons, if divided, then it is to determine the area of the side of the region of the area of the upper three points and the following three points, but this needs to find the corresponding 6 points, even if the two points of efficiency is not as high as the previous method.

The code is as follows:
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath&
Gt
#include <algorithm> using namespace std;
#define INF 1e10 const int MAXN = 100005;
int n;
Double ans;
int A[MAXN]; struct point {double x, y;}

POINTS[MAXN]; 
    int cmpx (const point &a,const point &b) {return a.x < b.x;} int cmpy (const int &a,const int &b) {
return POINTS[A].Y < Points[b].y;  } double distances (int a,int b) {return sqrt ((points[a].x-points[b].x) * (points[a].x-points[b].x) + (points[a].y
-POINTS[B].Y) * (POINTS[A].Y-POINTS[B].Y));
    } double Closet (int l,int r) {if (L = = r) return INF;
    if (l + 1 = = r)//two points return distances (l,r);
    int mid = (L + r) >> 1;
    Double D1 = Closet (l,mid);
    Double D2 = Closet (mid + 1,r); Double d = D1 < D2?
    D1:D2; the int num = 0;//record and the midpoint of the middle point are less than the D point for (int i = L;i <= r;i++) {if (Fabs (points[mid].x-points[i).x) < D) {A[num] = i;
        num++; }} sort (A,a + num,cmpy);//Sort by ordinate for (int i = 0;i < num-1;i++) {for (int j = i + 1;j <= i
            + 6 && J < num;j++) {if (points[a[j]].y-points[a[i]].y >= d) break; D = d < distances (A[i],a[j])?
        D:distances (A[i],a[j]);
}} return D;
    } void Init () {for (int i = 0;i < n;i++) {scanf ("%lf%lf", &points[i].x,&points[i].y);
} sort (points,points + n,cmpx);
    } void Solve () {ans = closet (0,n-1)/2;
printf ("%.2lf\n", ans);
        } int main () {while (scanf ("%d", &n) && n! = 0) {init ();
    Solve ();
} return 0; }



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.