HDU 1007 quoit design (calculate the closest point of the geometric plane)

Source: Internet
Author: User

Quoit Design

Time Limit: 10000/5000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 22349 accepted submission (s): 5735


Problem descriptionhave 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
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.


Inputthe 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 lines follow, each contains a pair of (x, y) which are the coordinates of a toy. the input is terminated
By n = 0.


Outputfor each 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
 


Authorchen, Yue


Sourcezjcpc2004


Recommendjgshining: I first complained about this question. I want to cry when the timeout is exceeded, not because of incorrect algorithm ideas, qsort is used when the point is sorted from left to right by the X value, and then changed to sort to A. Sadly, it is better to study the differences between sort and qsort, let's introduce the algorithm idea of the latest point! The general idea is recursion and divide and conquer. First, sort the X values of points from left to right and divide them into two halves, find the nearest point on the left and the right, and then take the bottom, but here the problem arises. If the recent two points are both on the separate sides, then it's easy, however, if the two points are located in different regions, this is troublesome, the solution to this problem is that the key point of the algorithm's correctness and complexity is first located in the range of L and R where all vertices that may be the least vertex are located, then we will proceed with the processing. We will first meet all the conditions in the X axis direction, then sort by the Y axis size, and then start to select the smallest value when selecting by the X axis, the distance between the X axis from all to the center is smaller than the distance from the current smallest point on the left and right, and then sorted by the Y axis from small to large. Then there is a Pigeon nest principle here, which is actually very simple: (turn) D is the minimum distance between any two points in the Two Half Planes. Therefore, the distance between any two points in the same half plane cannot exceed D. We also require that the horizontal distance between P1 and P2 cannot exceed d, and the vertical distance cannot exceed D. In the small square of D * 2D, up to six vertices with a distance not less than D can be put down. Then it's gone!

# Include <stdio. h> # include <stdlib. h> # include <string. h> # include <algorithm> # include <math. h >#include <iostream> using namespace STD; # define INF 1e8struct point {Double X; Double Y;} node [100100]; int my_rec [100100]; int N; double DIS (point & A, point & B) {return SQRT (. x-b.x) * (. x-b.x) +. y-b.y) * (. the y-b.y);} int CMP (const point & A, const point & B) {return. x <B. x;} bool cmpy (const Int & A, const Int & B) {return node [A]. Y <node [B]. y;} double find_min (int l, int R) {int I, j, k; double TMP; If (L = r) return INF; If (L = R-1) return DIS (node [L], node [R]); double temp1 = min (find_min (L, (L + r)/2), find_min (L + r) /2, R); int mid = (L + r)/2; k = 0; for (I = L; I <= r; I ++) if (FABS (node [I]. x-node [Mid]. x) <temp1) my_rec [k ++] = I; sort (my_rec, my_rec + k, cmpy); for (I = 0; I <K-1; I ++) for (j = I + 1; j <K & J <I + 7/* node [my_rec [J]. y-node [my_rec [I]. Y <temp1 */; j ++) // use the above inference to scan only six points {TMP = DIS (node [my_rec [I], node [my_rec [J]); If (TMP <temp1) temp1 = TMP;} return temp1;} int main () {int I, J, K; while (scanf ("% d", & N), n) {for (I = 0; I <n; I ++) scanf ("% lf ", & node [I]. x, & node [I]. y); If (n = 1) {printf ("0.00 \ n"); continue;} If (n = 2) {printf ("%. 2lf \ n ", DIS (node [0], node [1])/2); continue;} Sort (node, node + N, CMP); printf (" %. 2lf \ n ", find_min (0, n-1)/2);} 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.