zoj 2107&&hdu 1007最近点对问题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1107
Quoit Design
Time Limit: 5 Seconds Memory Limit: 32768 KB
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
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
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
参考了模板写的,确实不是很懂
来源:http://blog.csdn.net/cxiaokai/article/details/6661005
参考资料:http://blog.csdn.net/lishuhuakai/article/details/9133961
http://blog.csdn.net/hackbuteer1/article/details/7482232
尚待理解
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#define MAXX 100005
using namespace std; struct point
{
double x;
double y;
}p[MAXX],p1[MAXX],p2[MAXX]; bool cmpx(point a,point b)
{
return a.x < b.x;
}
bool cmpy(point a,point b)
{
return a.y < b.y;
}
double dis(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double minn(double a,double b)
{
return a > b ? b : a;
}
double closest(int l,int r)
{
if(l+ == r)return dis(p1[l],p1[r]);
if(l+ == r)
return minn(dis(p1[l],p1[l+]),minn(dis(p1[l],p1[r]),dis(p1[l+],p1[r])));
int mid=(l+r)>>;
double ans=minn(closest(l,mid),closest(mid+,r));
int cn=;
for(int i=l; i<=r; i++)
{
if(p1[i].x>=p1[mid].x-ans&&p1[i].x<=p1[mid].x+ans)
{
p2[cn++]=p1[i];
}
}
sort(p2,p2+cn,cmpy);
for(int i=; i<cn; i++)
{
for(int j=i+; j<cn; j++)
{
if(p2[j].y-p2[i].y>=ans)
break;
ans=minn(ans,dis(p2[i],p2[j]));
}
}
return ans;
} int main()
{ int n;
while(scanf("%d",&n)!=EOF&&n)
{
for(int i=; i<n; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
p1[i]=p[i];
}
sort(p1,p1+n,cmpx);
double dist=closest(,n-);
printf("%.2lf\n",dist/);
}
return ;
}
zoj 2107&&hdu 1007最近点对问题的更多相关文章
- hdu 1007最近点对问题
先说下题意,很简单,给n个点的坐标,求距离最近的一对点之间距离的一半.第一行是一个数n表示有n个点,接下来n行是n个点的x坐标和y坐标,实数. 这个题目其实就是求最近点对的距离.主要思想就是分治.先把 ...
- hdu 1007 最近点对问题(Splay解法)
为什么要写这个题..经典啊,当然,别以为我用分治做的,不过主要思想还是那神奇的六个点共存(一个h*2h的矩形中最多能放下多少个点使得两两距离不超过h) 其实我是在这里看到的 http://commun ...
- HDU 1007 Quoit Design(二分+浮点数精度控制)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU 1007 Quoit Design(经典最近点对问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1007 Quoit Design Time Limit: 10000/5000 MS (Java/Oth ...
- HDU 1007 Quoit Design 平面内最近点对
http://acm.hdu.edu.cn/showproblem.php?pid=1007 上半年在人人上看到过这个题,当时就知道用分治但是没有仔细想... 今年多校又出了这个...于是学习了一下平 ...
- HDU 1007:Quoit Design(分治求最近点对)
http://acm.hdu.edu.cn/showproblem.php?pid=1007 题意:平面上有n个点,问最近的两个点之间的距离的一半是多少. 思路:用分治做.把整体分为左右两个部分,那么 ...
- HDU 1007(套圈 最近点对距离)
题意是求出所给各点中最近点对的距离的一半(背景忽略). 用分治的思想,先根据各点的横坐标进行排序,以中间的点为界,分别求出左边点集的最小距离和右边点集的最小距离,然后开始合并,分别求左右点集中各点与中 ...
- hdu 1007 Quoit Design(分治法求最近点对)
大致题意:给N个点,求最近点对的距离 d :输出:r = d/2. // Time 2093 ms; Memory 1812 K #include<iostream> #include&l ...
- HDU 1007 Quoit Design(计算几何の最近点对)
Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings ...
随机推荐
- android 学习随笔二(读写文件)
在android读写文件 RAM:运行内存,相当于电脑的内存 ROM:内部存储空间,相当电脑硬盘,android手机必须有的 SD卡:外部存储空间,相当电脑的移动硬盘,不是必须的.手机如果内置16G存 ...
- oracle增删改查
=======================批量删除,只留前十条数据. delete from THIRD_PARTY_MERCHANT a where a.rowid in ( select ro ...
- 【python cookbook】【数据结构与算法】3.保存最后N个元素
问题:希望在迭代或是其他形式的处理过程中对最后几项记录做一个有限的历史记录统计 解决方案:选择collections.deque. 如下的代码对一系列文本行做简单的文本匹配操作,当发现有匹配时就输出当 ...
- 前端开发自动化工作流工具,JavaScript自动化构建工具grunt、gulp、webpack介绍
前端开发自动化工作流工具,JavaScript自动化构建工具grunt.gulp.webpack介绍 前端自动化,这样的一个名词听起来非常的有吸引力,向往力.当今时代,前端工程师需要维护的代码变得及为 ...
- 启动管理软件服务器时,提示midas.dll错误
首先确认系统以及管理软件目录内是否有midas.dll文件,如果没有,请复制或下载midas.dll到相应目录.系统默认路径为:'c:\windows\system32\' 然后依次打开“开始菜单”内 ...
- javascript || and &&
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- rtsp里面的音频类型,大部分都默认规定了样本大小的。
从src/audio_output/common.c里面的函数aout_BitsPerSample可知,rtsp里面的音频类型,大部分都默认规定了样本bit大小的.即是,一个音频编码类型,对应一个固定 ...
- 【转】Eclipse Console 加大显示的行数,禁止弹出
转载地址:http://blog.csdn.net/leidengyan/article/details/5686691 Eclipse Console 加大显示的行数: 在 Preferences- ...
- 计算机学院大学生程序设计竞赛(2015’12)The Country List
The Country List Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- MAVEN安装过程
maven 的压缩包地址: http://pan.baidu.com/s/1kT4ckGf 第三方资源jar包地址: http://pan.baidu.com/s/1i3vtgED