Quoit Design

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 28373    Accepted Submission(s): 7417


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
 
几何+排序
 1 #include"iostream"
 2 #include"algorithm"
 3 #include"cmath"
 4 #include"cstdio"
 5 using namespace std;
 6 #define min(a,b) ((a)>(b))?(b):(a)
 7 struct point
 8 {
 9     double x,y;
10 }a[100003];
11 bool cmp(const point &a,const point &b)
12 {
13     if(a.x==b.x)
14       return a.y<b.y;
15     return a.x<b.x;  
16 }
17 double dis(point a,point b)
18 {
19     return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
20 }
21 double S(point a[],int n)
22 {
23     double m=0xffffff;
24     if(n==2)
25       return dis(a[0],a[1]);
26     for(int i=0;i<n-2;i++)
27     {
28         m=min(m,min(dis(a[i],a[i+1]),min(dis(a[i],a[i+2]),dis(a[i+1],a[i+2]))));
29     }  
30     return m;
31 }
32 int main()
33 {
34     int n;
35     while(scanf("%d",&n),n)
36     {
37         for(int i=0;i<n;i++)
38         {
39             scanf("%lf%lf",&a[i].x,&a[i].y);
40         }
41         sort(a,a+n,cmp);
42         printf("%.2lf\n",S(a,n)/2);
43     }
44     return 0;
45 }
View Code

 


 
posted @ 2014-04-29 21:50  daydaycode  阅读(195)  评论(2编辑  收藏  举报