(Hdu 7.1.8) Quoit Design (least point: locate the minimum distance between two points in n points), hduquoit

Source: Internet
Author: User

(Hdu 7.1.8) Quoit Design (least point: locate the minimum distance between two points in n points), hduquoit

Question:

Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 136 Accepted Submission (s): 77
 
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 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.
 
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


Question Analysis:

Least point problem. The so-called least point problem is to find the shortest distance between two points in n points. There are two ways to solve this problem:

1) direct violence. Let's take a look at the data size. n is around 100000. The O (n ^ 2) algorithm will not be surprised. It will be TLE.

2) divide and conquer. This question uses the template of Jilin University. Just set it in.


The question of the least point corresponds to the question of the maximum point. (I don't know if there is any such term. If there is no such term, I will make a mistake. In my definition, we find the maximum distance between two vertices in n vertices ). The two points that can produce the maximum distance must be on the convex hull. In this case, we only need to enumerate any two points on the convex hull. In fact, in addition to blind enumeration, there is also a better algorithm to solve this problem-the rotary jamming algorithm.




The Code is as follows:

# Include <iostream> # include <cstdio> # include <cmath> # include <cstring> using namespace std;/*** calculates n vertices, the shortest distance between two points. * 1) direct violence. Certainly TLE * 2) use the template of Jilin University */const int N = 100005; const double MAX = 10e100, eps = 0.00001; struct Point {double x, y; int index;}; Point a [N], B [N], c [N]; double closest (Point *, int, int ); double dis (Point, Point); int cmp_x (const void *, const void *); int cmp_y (const void *, const void *); int merge (Point *, point *, int); inline double min (double, double); int main () {int n; while (scan F ("% d", & n )! = EOF, n) {int I; for (I = 0; I <n; ++ I) {scanf ("% lf", & a [I]. x, & a [I]. y);} qsort (a, n, sizeof (a [0]), cmp_x); for (I = 0; I <n; ++ I) {a [I]. index = I;}/*** memcpy (target address, starting address, n Bytes) * function: Copy n Bytes from the starting address to the target address * header file: try to introduce <cstring> **/memcpy (B, a, n * sizeof (a [0]); qsort (B, n, sizeof (B [0]), cmp_y); double ans = closest (a, B, c, 0, n-1); printf ("%. 2lf \ n ", ans/2);} return 0;} double closest (Point a [], Point B [], Point c [], int p, Int q) {if (q-p = 1) {return dis (a [p], a [q]);} if (q-p = 2) {double x1 = dis (a [p], a [q]); double x2 = dis (a [p + 1], a [q]); double x3 = dis (a [p], a [p + 1]); if (x1 <x2 & x1 <x3) {return x1 ;} else if (x2 <x3) {return x2;} else {return x3 ;}} int I, j, k, m = (p + q)/2; double d1, d2; for (I = p, j = p, k = m + 1; I <= q; I ++) {if (B [I]. index <= m) {c [j ++] = B [I];} // the left half of array c is saved, and the left vertex is ordered to y. else {c [k ++] = B [I] ;}} d1 = closest (a, c, B, p, m); d2 = closest (a, c, B, m + 1, q); double dm = min (d1, d2); // The Left and Right Parts of array c are sorted by y coordinate and merged to B. merge (B, c, p, m, q); for (I = p, k = p; I <= q; I ++) {if (fabs (B [I]. x-B [m]. x) <dm) {c [k ++] = B [I] ;}// locate the part of the Division baseline that does not exceed dm, and the y coordinate is still ordered. for (I = p; I <k; I ++) {for (j = I + 1; j <k & c [j]. y-c [I]. y <dm; j ++) {double temp = dis (c [I], c [j]); if (temp <dm) {dm = temp ;}} re Turn dm;} double dis (Point p, Point q) {double x1 = p. x-q. x, y1 = p. y-q. y; return sqrt (x1 * x1 + y1 * y1);} int merge (Point p [], Point q [], int s, int m, int t) {int I, j, k; for (I = s, j = m + 1, k = s; I <= m & j <= t ;) {if (q [I]. y> q [j]. y) {p [k ++] = q [j], j ++;} else {p [k ++] = q [I], I ++ ;}} while (I <= m) {p [k ++] = q [I ++];} while (j <= t) {p [k ++] = q [j ++];} memcpy (q + s, p + s, (t-s + 1) * sizeof (p [0]); return 0;} int cmp_x (const void * p, const void * q) {double temp = (Point *) p) -> x-(Point *) q)-> x; if (temp> 0) {return 1;} else if (fabs (temp) <eps) {return 0;} else {return-1 ;}} int cmp_y (const void * p, const void * q) {double temp = (Point *) p) -> y-(Point *) q)-> y; if (temp> 0) {return 1;} else if (fabs (temp) <eps) {return 0;} else {return-1 ;}} inline double min (double p, double q) {return (p> Q )? (Q): (p );}






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.