Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 20332 Accepted Submission (s): 5216
Problem Description
Have 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.
Input
The 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.
Output
For 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
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
Classic most recent point problem // similar topic POJ 3714 Raid (not done)
Refer to introduction to algorithms and computer algorithm design and analysis (Wang Xiaodong)
It is to be understood that at most 8 points in P may be in the d x 2d rectangle area.
Code:
[Cpp]
# Include <cmath>
# Include <cstdio>
# Include <cstdlib>
# Include <algorithm>
# Define N 100002
# Define INF 0x3f3f3f
Using namespace std;
Struct NODE {double x, y ;};
NODE edge [N], B [N];
Int cmp_x (const void * a, const void * B)
{
NODE * aa = (NODE *);
NODE * bb = (NODE *) B;
Return aa-> x> bb-> x? 1:-1;
}
Int cmp_y (const void * a, const void * B)
{
NODE * aa = (NODE *);
NODE * bb = (NODE *) B;
Return aa-> y> bb-> y? 1:-1;
}
Inline double dis (NODE a, NODE B)
{
Double xx = a. x-B. x, yy = a. y-B. y;
Return sqrt (xx * xx + yy * yy );
}
Double find (int l, int r) // open interval after pre-closing
{
If (r-l = 1) return INF;
If (r-l = 2) return dis (edge [l], edge [r-1]);
Int I, j, k;
Double dm, tmp;
Int m = (l + r)/2;
Double d1 = find (l, m );
Double d2 = find (m, r );
Dm = d1 <d2? D1: d2;
For (I = l, k = 0; I <r; I ++)
If (fabs (edge [m]. x-edge [I]. x) <= dm)
B [k ++] = edge [I];
Qsort (B, k, sizeof (B [0]), cmp_y );
For (I = 0; I <k; I ++)
For (j = I + 1; j <k; j ++)
{
Tmp = dis (B [I], B [j]);
If (tmp <dm) dm = tmp;
}
Return dm;
}
Int main ()
{
Int n, I;
While (scanf ("% d", & n), n)
{
For (I = 0; I <n; I ++)
// #1 scanf ("% lf", & edge [I]. x, & edge [I]. y );
/* #2 */scanf ("% lf", & edge [I]. y, & edge [I]. x );
Qsort (edge, n, sizeof (edge [0]), cmp_x );
Double d = find (0, n );
Printf ("%. 2lf \ n", d/2 );
}
Return 0;
}
/*
#1 sort by X axis decisive TLE Time Limit Exceeded 1007 5000 MS 1812 K
#2 sort AC Accepted by Y axis 1007 1125 MS 1840 K
*/
# Include <cmath>
# Include <cstdio>
# Include <cstdlib>
# Include <algorithm>
# Define N 100002
# Define INF 0x3f3f3f
Using namespace std;
Struct NODE {double x, y ;};
NODE edge [N], B [N];
Int cmp_x (const void * a, const void * B)
{
NODE * aa = (NODE *);
NODE * bb = (NODE *) B;
Return aa-> x> bb-> x? 1:-1;
}
Int cmp_y (const void * a, const void * B)
{
NODE * aa = (NODE *);
NODE * bb = (NODE *) B;
Return aa-> y> bb-> y? 1:-1;
}
Inline double dis (NODE a, NODE B)
{
Double xx = a. x-B. x, yy = a. y-B. y;
Return sqrt (xx * xx + yy * yy );
}
Double find (int l, int r) // open interval after pre-closing
{
If (r-l = 1) return INF;
If (r-l = 2) return dis (edge [l], edge [r-1]);
Int I, j, k;
Double dm, tmp;
Int m = (l + r)/2;
Double d1 = find (l, m );
Double d2 = find (m, r );
Dm = d1 <d2? D1: d2;
For (I = l, k = 0; I <r; I ++)
If (fabs (edge [m]. x-edge [I]. x) <= dm)
B [k ++] = edge [I];
Qsort (B, k, sizeof (B [0]), cmp_y );
For (I = 0; I <k; I ++)
For (j = I + 1; j <k; j ++)
{
Tmp = dis (B [I], B [j]);
If (tmp <dm) dm = tmp;
}
Return dm;
}
Int main ()
{
Int n, I;
While (scanf ("% d", & n), n)
{
For (I = 0; I <n; I ++)
// #1 scanf ("% lf", & edge [I]. x, & edge [I]. y );
/* #2 */scanf ("% lf", & edge [I]. y, & edge [I]. x );
Qsort (edge, n, sizeof (edge [0]), cmp_x );
Double d = find (0, n );
Printf ("%. 2lf \ n", d/2 );
}
Return 0;
}
/*
#1 sort by X axis decisive TLE Time Limit Exceeded 1007 5000 MS 1812 K
#2 sort AC Accepted by Y axis 1007 1125 MS 1840 K
*/