hdu 1007 Quoit Design(借鉴大神,求解平面对点)

Quoit Design

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 57575    Accepted Submission(s): 15242


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
 
也是非常奇葩了,借鉴大神分治,MLE了,贴出代码:
#include
#include
#include
#include
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}
return p1.p_x }


bool com_y(int a,int b)
{
return point[a].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{
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;
}
详细分析

你可能感兴趣的:(hdu 1007 Quoit Design(借鉴大神,求解平面对点))