Quoit Design(hdu1007)最近点对问题。模版哦!

时间:2021-11-27 07:38:13

Quoit Design

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

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
 
Sample Output
0.71
0.00
0.75
 
 
题意:找任意两点之间距离最短的输出!!!
方法:模版题,最近点对问题。                            我又多了份模版。
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define Max(x,y) (x)>(y)?(x):(y)
struct Q
{
double x, y;
} q[], sl[], sr[]; int cntl, cntr, lm, rm; double ans;
int cmp(const void*p1, const void*p2)
{
struct Q*a1=(struct Q*)p1;
struct Q*a2=(struct Q*)p2;
if (a1->x<a2->x)return -;
else if (a1->x==a2->x)return ;
else return ;
}
double CalDis(double x1, double y1, double x2, double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
void MinDis(int l, int r)
{
if (l==r) return;
double dis;
if (l+==r)
{
dis=CalDis(q[l].x,q[l].y,q[r].x,q[r].y);
if (ans>dis) ans=dis;
return;
}
int mid=(l+r)>>, i, j;
MinDis(l,mid);
MinDis(mid+,r);
lm=mid+-;
if (lm<l) lm=l;
rm=mid+;
if (rm>r) rm=r;
cntl=cntr=;
for (i=mid; i>=lm; i--)
{
if (q[mid+].x-q[i].x>=ans)break;
sl[++cntl]=q[i];
}
for (i=mid+; i<=rm; i++)
{
if (q[i].x-q[mid].x>=ans)break; sr[++cntr]=q[i];
}
for (i=; i<=cntl; i++)
for (j=; j<=cntr; j++)
{
dis=CalDis(sl[i].x,sl[i].y,sr[j].x,sr[j].y);
if (dis<ans) ans=dis;
}
}
int main()
{
int n, i;
while (scanf("%d",&n)==&&n)
{
for (i=; i<=n; i++)
scanf("%lf%lf", &q[i].x,&q[i].y);
qsort(q+,n,sizeof(struct Q),cmp);
ans=CalDis(q[].x,q[].y,q[].x,q[].y);
MinDis(,n);
printf("%.2lf\n",ans/2.0);
}
return ;
}