码迷,mamicode.com
首页 > 其他好文 > 详细

quoit design(hdoj p1007)

时间:2015-05-12 01:18:42      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

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
1.5 0
0
 
Sample Output
0.71
0.00
0.75
 1 #include<stdio.h>/*此题坐标按照y升序排列,然后进行计算比较*/
 2 #include<math.h>
 3 #include<stdlib.h>
 4 #include<algorithm>
 5 using namespace std;
 6 typedef struct
 7 {
 8     double x,y;
 9 }node;
10 node a[100002];
11 int cmp(node p,node q)/*对结构体排序*/
12 {
13     return p.y<q.y;
14 }
15 int main()
16 {
17     int T;
18     while(scanf("%d",&T)==1)
19     {
20         if(!T)
21             break;
22         else
23         {
24             int i,j;
25             double min1=99999999.0,min;
26             double d;
27             for(i=0;i<T;i++)
28                 scanf("%lf%lf",&a[i].x,&a[i].y);
29             sort(a,a+T,cmp);
30             for(i=0;i<T-1;i++)
31             {
32                 d=pow(a[i+1].x-a[i].x,2)+pow(a[i+1].y-a[i].y,2);
33                 min1=d<min1?d:min1;
34             }
35             printf("%.2lf\n",sqrt(min1)/2);/*最后在开方,节省时间*/
36         }
37     }
38 }
#include<stdio.h>/*我先按照x升序排列,求最小距离,在按照y升序排列求最小,然后比较,结果还WA了,果断怀疑这题数据给的有问题,讨论组也这么喷!*/
#include<math.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
typedef struct
{
    double x,y;
}node;
node a[100002];
int cmp1(node p,node q)
{
    return p.x<q.x;
}
int cmp2(node p,node q)
{
    return p.y<q.y;
}
int main()
{
    int T;
    while(scanf("%d",&T)==1)
    {
        if(!T)
            break;
        else
        {
            int i,j;
            double min1=99999999.0,min2=99999999.0,min;
            double d;
            for(i=0;i<T;i++)
                scanf("%lf%lf",&a[i].x,&a[i].y);
            sort(a,a+T,cmp1);
            for(i=0;i<T-1;i++)
            {
                d=pow(a[i+1].x-a[i].x,2)+pow(a[i+1].y-a[i].y,2);
                min1=d<min1?d:min1;
            }
            sort(a,a+T,cmp2);
            for(i=0;i<T-1;i++)
            {
                d=pow(a[i+1].x-a[i].x,2)+pow(a[i+1].y-a[i].y,2);
                min2=d<min2?d:min2;
            }
            min=sqrt(min1>min2?min2:min1)/2;
            printf("%.2lf\n",min);
        }
    }
}

 

 

quoit design(hdoj p1007)

标签:

原文地址:http://www.cnblogs.com/a1225234/p/4496123.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!