Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 57575 Accepted Submission(s): 15242
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<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int MAX = 1<<30;
int p[100010];
struct po
{
double p_x;
double p_y;
}point[100010];
bool compare(po p1,po p2)
{
if(p1.p_x == p2.p_x)
{
return p1.p_y<p2.p_y;
}
return p1.p_x<p2.p_x;
}
bool com_y(int a,int b)
{
return point[a].p_y<point[b].p_y;
}
double pos(po p1,po p2)
{
return sqrt((p1.p_x-p2.p_x)*(p1.p_x-p2.p_x)+(p1.p_y-p2.p_y)*(p1.p_y-p2.p_y));
}
double start(int left,int right)
{
if(left == right)
{
return MAX;
}
if(left == right-1)
{
return pos(point[left],point[right]);
}
int mid = abs(left + right)>>1;
double dl = start(left,mid);
double dr = start(mid+1,right);
dl = min(dl,dr);
int k = 0;
for(int i = left;i < right;++i)
{
if(fabs(point[i].p_x-point[i+1].p_x) < dl)
{
p[k++] = i;
}
}
sort(p,p+k,com_y);
for(int i = 0;i < k;++i)
{
for(int j = i+1;j<k && point[p[j]].p_y-point[p[i]].p_y< dl;++j)
{
dl = min(pos(point[p[j]],point[p[i]]),dl);
}
}
return dl;
}
int main()
{
int n;
while(scanf("%d",&n) && n)
{
for(int i = 0;i < n;++i)
{
scanf("%lf%lf",&point[i].p_x,&point[i].p_y);
}
sort(point,point+n,compare);
double r = start(0,n-1)/2;
printf("%.2lf\n",r);
}
return 0;
}
1008



被折叠的 条评论
为什么被折叠?



