Quoit design (hdu1007) recent issues. Template!

Source: Internet
Author: User
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 descriptionhave 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.

 

Inputthe 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.

 

Outputfor each test case, print in one line the radius of the ring required by the cyberground manager, accurate up to 2 decimal places.

 

Sample input20 01 121 11 13-1.5 00 00 1.50

 

Sample output0.710.000.75 Question: Find the output with the shortest distance between any two points !!! Method: Template question, recent point. I have an additional template.
#include <stdio.h>#include <math.h>#include <stdlib.h>#define Max(x,y) (x)>(y)?(x):(y)struct Q{    double x, y;} q[100001], sl[10], sr[10];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 -1;    else if (a1->x==a2->x)return 0;    else return 1;}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+1==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)>>1, i, j;    MinDis(l,mid);    MinDis(mid+1,r);    lm=mid+1-5;    if (lm<l) lm=l;    rm=mid+5;    if (rm>r) rm=r;    cntl=cntr=0;    for (i=mid; i>=lm; i--)    {        if (q[mid+1].x-q[i].x>=ans)break;        sl[++cntl]=q[i];    }    for (i=mid+1; i<=rm; i++)    {        if (q[i].x-q[mid].x>=ans)break;        sr[++cntr]=q[i];    }    for (i=1; i<=cntl; i++)        for (j=1; 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)==1&&n)    {        for (i=1; i<=n; i++)            scanf("%lf%lf", &q[i].x,&q[i].y);        qsort(q+1,n,sizeof(struct Q),cmp);        ans=CalDis(q[1].x,q[1].y,q[2].x,q[2].y);        MinDis(1,n);        printf("%.2lf\n",ans/2.0);    }    return 0;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.