Quoit Design

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
 

 

Author
CHEN, Yue
 

 

Source
ZJCPC2004
 

 

Recommend
JGShining
 
答案:

#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#define SAFE_DELETE(p)   { if(p) { delete p; p = NULL; } }
#define eps  0.00001
struct Point
{
 double x;
 double y;
};
int cmpX(const void *p, const void *q)
{
 double temp = ((Point*)p)->x - ((Point*)q)->x;
    if (temp > 0)
        return 1;
    else if (fabs(temp) < eps)
        return 0;
    else
        return  - 1;
}
int cmpY(const void *p, const void *q)
{
 double temp = ((Point*)p)->y - ((Point*)q)->y;
    if (temp > 0)
        return 1;
    else if (fabs(temp) < eps)
        return 0;
    else
        return  - 1;
}
void setPoint(Point* p, Point* v)
{
 p->x = v->x;
 p->y = v->y;
}
double min(double x, double y, double z)
{
 if (x <= y && x<= z)
  return x;
 else if (y <= x && y<= z)
  return y;
 else
  return z;
}
double dis(Point* s, Point* e)
{
 return sqrtf(pow(s->x-e->x,2)+pow(s->y-e->y,2));
}
double QivotDone(Point* Pnt, int left, int right)
{
 if (left==right)
  return 0;
 else if (left+1 == right)
  return dis(&Pnt[left],&Pnt[right]);
 else if (left+2 == right)
  return min(dis(&Pnt[left],&Pnt[right]),dis(&Pnt[left+1],&Pnt[right]),dis(&Pnt[left],&Pnt[left+1]));
 else
 {
  int mid = (left+right)/2;
  double v = QivotDone(Pnt, left, mid);
  double v1 = QivotDone(Pnt, mid+1, right);
  if (v > v1)  v = v1;
  double vmin = v;
  int i = 0, n = 0, j; 
  Point* tmpPnt = new Point [right-left+1];
  for (i = mid; i >= left &&Pnt[mid+1].x-Pnt[i].x<vmin; --i)
   setPoint(&tmpPnt[n++], &Pnt[i]);
  for (i = mid+1; i <= right &&Pnt[i].x-Pnt[mid].x<vmin; ++i)
   setPoint(&tmpPnt[n++], &Pnt[i]);
  qsort(tmpPnt, n, sizeof(Point), cmpY);
  for (i = 0; i < n-1; ++i)
   for (j = i+1; j < n && j<=i+7 && tmpPnt[j].y-tmpPnt[i].y <vmin; ++j)
   {
    double tmp = dis(&tmpPnt[i],&tmpPnt[j]);
    if (vmin>tmp)
     vmin = tmp;
   }
   
   SAFE_DELETE(tmpPnt);
   return vmin;
 }
}
int main(int argc, char* argv[])
{
 int n, i;
 Point* Pnt = NULL;
 
 while (scanf("%d", &n)!=EOF)
 {
  if (n <= 1)
   break;
  Pnt = new Point [n];
  for (i = 0; i < n; ++i)
   scanf("%lf %lf", &(Pnt[i].x), &(Pnt[i].y));
  qsort(Pnt, n, sizeof(Point), cmpX);
  printf("%.2f/n", QivotDone(Pnt, 0, n-1)/2);
  SAFE_DELETE(Pnt);
 }
 return 0;
}
补充测试数据:

10
1 1
5 7
12 3
33 8
8 56
9 57
23 5
0 4
18 1
90 3

0
结果:
0.71
 

你可能感兴趣的:(manager,Integer,delete,input,each,distance)