hdu1007 分治
来源:互联网 发布:串口检测软件 编辑:程序博客网 时间:2024/05/17 03:06
http://acm.hdu.edu.cn/showproblem.php?pid=1007
Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 39358 Accepted Submission(s): 10248
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
先说下题意,很简单,给n个点的坐标,求距离最近的一对点之间距离的一半。
第一行是一个数n表示有n个点,接下来n行是n个点的x坐标和y坐标。实数。
#include <iostream>#include <stdio.h>#include <algorithm>#include <cmath>#define MAX 100005using namespace std;struct node{ double x,y;};node point[MAX],px[MAX],py[MAX];bool cmpx(node a,node b){ return a.x<b.x;}bool cmpy(node a,node b){ return a.y<b.y;}double d(node a,node b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}double min(double a,double b){ return a<b?a:b;}///核心代码double closeset(int s,int e){ if(s+1==e)///当只有一条边时 return d(px[s],px[e]); if(s+2==e)///当只有两条边时 return min(d(px[s],px[e]),min(d(px[s+1],px[s]),d(px[s+1],px[e]))); int mid=(s+e)/2; double ans=min(closeset(s,mid),closeset(mid+1,e));///递归求解,一直减小范围 int cnt=0; for(int i=s;i<=e;i++) { if(px[i].x>=px[mid].x-ans&&px[i].x<=px[mid].x+ans) py[cnt++]=px[i]; } sort(py,py+cnt,cmpy); int i,j; for( i=0; i<cnt; i++) { for( j=i+1; j<cnt; j++) { if(py[j].y-py[i].y>=ans) break; ans=min(ans,d(py[i],py[j])); } } return ans;}int main(){ int t; while(scanf("%d",&t)!=EOF) { if(t==0) break; for(int i=0; i<t; i++) { scanf("%lf%lf",&point[i].x,&point[i].y); px[i].x=point[i].x; px[i].y=point[i].y; } sort(px,px+t,cmpx); double ans=closeset(0,t-1); printf("%.2lf\n",ans/2.0) ; } return 0;}
1 0
- hdu1007 分治
- HDU1007(分治)
- hdu1007分治法
- HDU1007 Quoit Design 【分治】
- HDU1007(分治算法)
- HDU1007 Quoit Design 分治
- hdu1007 Quoit Design 分治
- hdu1007之分治
- HDU1007:Quoit Design(分治)
- hdu1007分治法求最近点对
- hdu1007最近点对(分治)
- hdu1007求最近点对(分治法)
- HDU1007 Quoit Design(分治法)
- hdu1007.最近点对(分治法)
- hdu1007 Quoit Design 【计算几何+分治】
- hdu1007
- hdu1007
- HDU1007
- Hibernate-常用API简列
- Nuget发布与dll文件引用
- Android, 启动活动的最佳写法
- UIView
- 数据结构 线性结构中的数组
- hdu1007 分治
- 机器人书单与学习资源——控制篇
- 栈考点
- This function or variable may be unsafe
- Docker Runs on Windows Server 2016
- android 分辨率自适应
- uva 11383 Golden Tiger Claw 二分图完美匹配
- 欢迎使用CSDN-markdown编辑器
- Halcon学习之仿射变换3