hud 1007 Quoit Design(分治求最小点对)
来源:互联网 发布:李铁军 李婧磁 知乎 编辑:程序博客网 时间:2024/05/22 03:10
hud 1007 Quoit Design(分治求最小点对)
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
20 01 121 11 13-1.5 00 00 1.50
Sample Output
0.710.000.75
题目链接:点击打开链接
代码:
#include<cstdio>#include<algorithm>#include<cmath>using namespace std;struct point{ double x; double y;};point p[100005];point m[100005];int cmp_x(point p1,point p2){ if(p1.x==p2.x) return p1.x<p2.x; return p1.y<p2.y;}int cmp_y(point p1,point p2){ return p1.y<p2.y;}double dis(point p1,point p2){ return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));}double findMinDis(int s,int e){ if(e-s==1) return dis(p[e],p[s]); int mid=(e+s)/2; double minz=findMinDis(s,mid); double miny=findMinDis(mid,e); double mini=min(minz,miny); int num=0; for(int i=s;i<=e;i++) { if(fabs(p[mid].x-p[i].x)<=mini) m[num++]=p[i]; } sort(p,p+num,cmp_y); for(int i=0;i<num;i++) { for(int j=i+1;j<num&&m[j].y-m[i].y<mini;j++) mini=min(mini,dis(m[i],m[j])); } return mini;}int main(){ int n; while(~scanf("%d",&n)) { if(n==0) break; for(int i=0;i<n;i++) scanf("%lf %lf",&p[i].x,&p[i].y); sort(p,p+n,cmp_x); printf("%.2lf\n",findMinDis(0,n-1)/2); } return 0;}
1 0
- hud 1007 Quoit Design(分治求最小点对)
- hdu-1007-Quoit Design-求最小点距离、分治思想
- hdu 1007 Quoit Design(分治法求最近点对)
- hdu 1007 Quoit Design(分治求最近点对)
- HDU 1007 Quoit Design 分治法求最近点对
- 分治 求点对最短距离 hdu 1007 Quoit Design
- 【分治 求最近点对】hdu 1007 Quoit Design
- hdu 1007 Quoit Design [sort+分治] 寻找最小距离点对
- hdu 1007 zoj 2107 Quoit Design 求平面最近点对 分治法
- HDU ACM 1007 Quoit Design 分治法求最近点对
- HDU 1007 Quoit Design(分治法求最近点对问题)
- hdu 1007 Quoit Design (最近点对、分治)
- Hdu 1007 - Quoit Design//分治,最近点对,计算几何
- hdu 1007 Quoit Design 最近点对(分治)
- HDU 1007 Quoit Design 最近点对 分治法
- HDU 1007 Quoit Design(最近点对问题:分治)
- hdu 1007 Quoit Design 最近点对(分治)
- HDOJ 1007 Quoit Design (最近点对+分治)
- 程序员的10条黄金法则,你懂?
- 使用JMeter进行FTP测试
- 最小生成树MST的Kruskal算法+并查集(链表实现)划分连通分量和集合,并查集可以保存多个集合
- 【资源】哪里找selenium的Example
- 实现稀疏矩阵相乘C/C++
- hud 1007 Quoit Design(分治求最小点对)
- lightoj 1246 - Colorful Board
- 【openjudge】网线主管 二分查找
- Python入门教程三:显示'Welcome to Python'五次
- c语言字符、字符串、指针
- [模板]最大流(Edmonds_Karp/Dinic算法(以poj1273为例
- vue.js 2.0父子组件学习入门套路
- 校招
- Most Common Solutions to FRM-41839 and .tmp Files Not Being Deleted