quoit design(hdoj p1007)

时间:2023-03-09 15:22:23
quoit design(hdoj p1007)
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
Sample Output
0.71
0.00
0.75
 #include<stdio.h>/*此题坐标按照y升序排列,然后进行计算比较*/
#include<math.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
typedef struct
{
double x,y;
}node;
node a[];
int cmp(node p,node q)/*对结构体排序*/
{
return p.y<q.y;
}
int main()
{
int T;
while(scanf("%d",&T)==)
{
if(!T)
break;
else
{
int i,j;
double min1=99999999.0,min;
double d;
for(i=;i<T;i++)
scanf("%lf%lf",&a[i].x,&a[i].y);
sort(a,a+T,cmp);
for(i=;i<T-;i++)
{
d=pow(a[i+].x-a[i].x,)+pow(a[i+].y-a[i].y,);
min1=d<min1?d:min1;
}
printf("%.2lf\n",sqrt(min1)/);/*最后在开方,节省时间*/
}
}
}
#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[];
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)==)
{
if(!T)
break;
else
{
int i,j;
double min1=99999999.0,min2=99999999.0,min;
double d;
for(i=;i<T;i++)
scanf("%lf%lf",&a[i].x,&a[i].y);
sort(a,a+T,cmp1);
for(i=;i<T-;i++)
{
d=pow(a[i+].x-a[i].x,)+pow(a[i+].y-a[i].y,);
min1=d<min1?d:min1;
}
sort(a,a+T,cmp2);
for(i=;i<T-;i++)
{
d=pow(a[i+].x-a[i].x,)+pow(a[i+].y-a[i].y,);
min2=d<min2?d:min2;
}
min=sqrt(min1>min2?min2:min1)/;
printf("%.2lf\n",min);
}
}
}