hdu1007 Quoit Design(最近点对模板题)

来源:互联网 发布:黑龙江科技大学网络课 编辑:程序博客网 时间:2024/05/17 23:57

Quoit Design

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


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
20 01 121 11 13-1.5 00 00 1.50
 

Sample Output
0.710.000.75

最近点对模板题,做了这题才学习到,具体的证明不好意思转载别人的了= =,各位可以自行网上学习,给出我的AC模板:
#include<cstdio>#include<cstdlib>#include<iostream>#include<stack>#include<queue>#include<algorithm>#include<string>#include<cstring>#include<cmath>#include<vector>#include<map>#include<set>#define eps 1e-8#define zero(x) (((x>0?(x):-(x))-eps)#define mem(a,b) memset(a,b,sizeof(a))#define memmax(a) memset(a,0x3f,sizeof(a))#define pfn printf("\n")#define ll __int64#define ull unsigned long long#define sf(a) scanf("%d",&a)#define sf64(a) scanf("%I64d",&a)#define sf264(a,b) scanf("%I64d%I64d",&a,&b)#define sf364(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)#define sf2(a,b) scanf("%d%d",&a,&b)#define sf3(a,b,c) scanf("%d%d%d",&a,&b,&c)#define sf4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)#define sff(a) scanf("%f",&a)#define sfs(a) scanf("%s",a)#define sfs2(a,b) scanf("%s%s",a,b)#define sfs3(a,b,c) scanf("%s%s%s",a,b,c)#define sfd(a) scanf("%lf",&a)#define sfd2(a,b) scanf("%lf%lf",&a,&b)#define sfd3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)#define sfd4(a,b,c,d) scanf("%lf%lf%lf%lf",&a,&b,&c,&d)#define sfc(a) scanf("%c",&a)#define ull unsigned long long#define debug printf("***\n")const double PI = acos(-1.0);const double e = exp(1.0);const int INF = 2<<20;template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }template<class T> inline T Min(T a, T b) { return a < b ? a : b; }template<class T> inline T Max(T a, T b) { return a > b ? a : b; }bool cmpbig(int a, int b){ return a>b; }bool cmpsmall(int a, int b){ return a<b; }using namespace std;#define MAX 100010#define pp pair<double,double>pp node[MAX];int flag_node[MAX];bool cmpx(pp a,pp b){    return a.first<b.first;}bool cmpy(int x,int y){    return node[x].second<node[y].second;}double distances(int x,int y){    return sqrt((node[x].first-node[y].first)*(node[x].first-node[y].first)+(node[x].second-node[y].second)*(node[x].second-node[y].second));}double closer_pair(int left,int right){    double d=INF;    if(left==right)        return d;    if(left+1==right)        return distances(left,right);    int mid=(left+right)>>1;    double d1=closer_pair(left,mid);    double d2=closer_pair(mid+1,right);    d=min(d1,d2);    int i,j,k=0;    for(i=left;i<=right;i++)    {        if(fabs(node[i].first-node[mid].first)<d)            flag_node[k++]=i;    }    sort(flag_node,flag_node+k,cmpy);    for(i=0;i<k;i++)    {        for(j=i+1;j<k&&node[flag_node[j]].second-node[flag_node[i]].second<d;j++)        {            double d3=distances(flag_node[i],flag_node[j]);            d=min(d,d3);        }    }    return d;}int main(){    //freopen("data.in","r",stdin);    int n;    while(~sf(n)&&n)    {        int i;        for(i=0;i<n;i++)        {            double x,y;            sfd2(x,y);            node[i]=make_pair(x,y);        }        sort(node,node+n,cmpx);        printf("%.2f\n",closer_pair(0,n-1)/2);    }    return 0;}

0 0
原创粉丝点击