HDU1007 Quoit Design (平面最近点对)
来源:互联网 发布:淘宝设置发货地址 编辑:程序博客网 时间:2024/05/16 08:19
Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 46735 Accepted Submission(s): 12198
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.
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
这道题就是经典的平面分治法的使用。
感觉我的代码写的好丑,为什么同样的代码我写出来就是900+ms,别人的就是700+ms啊,伤心……
网上也有很多讲解,我也不罗嗦了。
#include<bits/stdc++.h>using namespace std;const int maxn=1e5+5;const double eps=1e-7;struct note { double x,y;} a[maxn];int me[maxn];inline double MIN(double min1,double min2) { return min1<min2?min1:min2;}inline double DIS(struct note aa,struct note bb) { return sqrt((aa.x-bb.x)*(aa.x-bb.x)+(aa.y-bb.y)*(aa.y-bb.y));}bool cmp_x(struct note aa,struct note bb) { return aa.x<bb.x;}bool cmp_y(int aa,int bb) { return a[aa].y<a[bb].y;}double Close_Pair(int l,int r) { if(l==r-1) { return DIS(a[l],a[r]); } else if(l==r-2) { return MIN(DIS(a[l],a[l+1]),MIN(DIS(a[l],a[l+2]),DIS(a[l+1],a[l+2]))); } else { int top=0; int mid=(l+r)>>1; double tans=MIN(Close_Pair(l,mid),Close_Pair(mid+1,r)); if(tans<=eps)return tans; for(int i=l; i<=r; ++i) { if(a[mid].x+tans>=a[i].x&&a[i].x>=a[mid].x-tans) { me[top++]=i; } } sort(me,me+top,cmp_y); for(int i=0; i<top; ++i) { for(int j=i+1; j<top; ++j) { double td=DIS(a[me[i]],a[me[j]]); if(td<tans) { tans=td; } else break; } } return tans; }}int main() { int n; while(~scanf("%d",&n)&&n) { for(int i=0; i<n; ++i) { scanf("%lf%lf",&a[i].x,&a[i].y); } sort(a,a+n,cmp_x); printf("%.2lf\n",Close_Pair(0,n-1)/2.00); } return 0;}
0 0
- HDU1007 Quoit Design (平面最近点对)
- hdu1007 Quoit Design 平面最近点对(分治)
- hdu1007 Quoit Design【平面最近点对+分治】
- hdu1007 Quoit Design(最近点对)
- hdu1007 Quoit Design (最近点对)
- (hdu1007)Quoit Design,求最近点对
- HDU1007 Quoit Design(最近点对问题)
- 传说中的hdu1007。Quoit Design,求最近点对~~
- Quoit Design(hdu1007)最近点对问题。模版哦!
- hdu1007 Quoit Design(最近点对模板题)
- HDU1007-Quoit Design&POJ3714-Raid(最近点对问题)
- hdu1007 平面最近点对
- HDU1007 平面最近点对
- zoj 2107 Quoit Design(平面最近点对)
- [ZJU 2107]Quoit Design(平面最近点对)
- hdu 1007 Quoit Design(平面最近点对)
- HDU 1007 Quoit Design(计算几何 平面最近点对)
- hdu 1007 Quoit Design 平面最近点对
- Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds. If the server require
- mysql中表的复制备份
- Codeforces-465A-inc ARG
- JMeter学习(十七)JMeter测试Java
- android系统源码目录system/framework下各个jar包的用途
- HDU1007 Quoit Design (平面最近点对)
- Android将地理位置存储到图片扩展信息EXIF
- Mybatis框架开发-Maven创建web项目
- Android Studio NDK开发
- hdoj1319
- listview中子条目的适配方式
- eclipse修改默认编码为UTF-8
- 2016_08_01日志
- 虚函数表(vtbl)与虚函数表指针(vptr)