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.
2 0 0 1 1 2 1 1 1 1 3 -1.5 0 0 0 0 1.5 0
0.71 0.00 0.75
#include <iostream>
#include<Cmath>
using namespace std;
struct Node
{
float x;
float y;
};
int main ()
{
long N;
int i;
float R,min;
while((cin>>N)&&N!=0)
{//题目的关键是求出这些点两两之间的距离,再求出距离的最小值
//所求的半径便是最小值的一半
float *r=new float [N*(N-1)/2]; //用来存储两两点间的距离
long k=0; //记录存入r[]中数的个数
Node *p=new Node[N];
for(i=0;i<N;i++)
{
cin>>p[i].x>>p[i].y;
}
for (i=0;i<N-1;i++)
{
for (int j=i+1;j<N;j++)
{
R=sqrt((p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y));
r[k]=R;
k+=1;
}
}
min=r[0];
for (k=1;k<(N*(N-1)/2);k++)
{
if(min>r[k])
min=r[k];
}
R=float (min/2.0);
printf("%.2lf\n",R);
delete [] p;
delete [] r;
}
return 0;
}