(Hdu 7.1.8) Quoit Design (minimum point pair---find the minimum distance between two points in N points)

Source: Internet
Author: User

Topic:

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 be pitched at some toys, with all the toys encircled awarded.
in the field of Cyberground, the position of each toy are fixed, and the ring is a carefully designed so it can only Enci Rcle 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 the 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.
 
Inputthe 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.
Outputfor each test case, print on one line the radius of the ring required by the Cyberground manager, accurate up to 2 D Ecimal places.
Sample Input
20 01 121 11 13-1.5 00 00 1.50
Sample Output
0.710.000.75
Authorchen, Yue
SourceZJCPC2004
Recommendjgshining


Topic Analysis:

Minimum point pair problem. The so-called minimum point pair problem is finding the shortest distance between 2 points in N points. There are two ways of thinking about this problem:

1) Direct violence. Take a look at the data size, n are around 100000, O (n^2) algorithm, no accident, will tle.

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


The problem with the minimum point pair is the maximum point pair problem (I don't know if there's a noun, if it's not, I'll make it up.) The so-called maximum point pair problem, in my definition, is to find the maximum distance between two points in N points. The two points that can produce the maximum distance must be on the convex hull, when we enumerate any two points on the convex packet. In fact, in addition to blind enumeration, there is a better algorithm to solve this problem-rotation jam algorithm.




The code is as follows:

#include <iostream> #include <cstdio> #include <cmath> #include <cstring>using namespace std;/* * * To find the shortest distance between 2 points in N points. * 1) Direct violence. Certainly will 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];d ouble Closest (Point *, point *, point *, int, int.);d ouble Dis (point, point); int cmp_x (const void * , const void*), int cmp_y (const void *, const void*), int merge (point *, point *, int, int, int), inline double min (double, d ouble); int main () {int n;while (scanf ("%d", &n)!=eof,n) {int i;for (i = 0; i < n; ++i) {scanf ("%lf%lf", &a[i].x,&am P;A[I].Y);} Qsort (A,n,sizeof (a[0]), cmp_x); for (i = 0; i < n; ++i) {a[i].index = i;} /** * memcpy (destination address, starting address, n bytes) * Function: Copy n bytes from the starting address to the destination address * header file: Try to introduce <cstring> into * */memcpy (b,a,n*sizeof (a[0)); Qsort (b,n , sizeof (B[0]), cmp_y);d ouble ans = closest (a,b,c,0,n-1);p rintf ("%.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]);d ouble x2 = Dis (a[p + 1], a[q]);d ouble x3 = Dis (a[p], a[p + 1]); if (X1 < x 2 && 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 the array C holds the left-hand point, and the Y is ordered. else{c[k++] = B[i];}} D1 = Closest (A, C, B, p, m);d 2 = closest (A, C, B, M + 1, q);d ouble dm = min (d1, D2), and//the left and right parts of the array are ordered in Y coordinates, merging them into 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];}}  Find out the division of the baseline is not more than DM part, and still orderly y coordinate. 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;}}} return 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);}






(Hdu 7.1.8) Quoit Design (minimum point pair---find the minimum distance between two points in N points)

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.