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/hellobabygogo3/article/details/8042650
 

首先,假设点是n个,编号为1到n。我们要分治求,则找一个中间的编号mid,先求出1到mid点的最近距离设为d1,还有mid+1到n的最近距离设为d2。这里的点需要按x坐标的顺序排好,并且假设这些点中,没有2点在同一个位置。(若有,则直接最小距离为0了)。

然后,令d为d1, d2中较小的那个点。如果说最近点对中的两点都在1-mid集合中,或者mid+1到n集合中,则d就是最小距离了。但是还有可能的是最近点对中的两点分属这两个集合,所以我们必须先检测一下这种情况是否会存在,若存在,则把这个最近点对的距离记录下来,去更新d。这样我们就可以得道最小的距离d了。

 
关键是要去检测最近点对,理论上每个点都要和对面集合的点匹配一次,那效率还是不能满足我们的要求。所以这里要优化。怎么优化呢?考虑一下,假如以我们所选的分割点mid为界,如果某一点的横坐标到点mid的横坐标的绝对值超过d1并且超过d2,那么这个点到mid点的距离必然超过d1和d2中的小者,所以这个点到对方集合的任意点的距离必然不是所有点中最小的。
 
  所以我们先把在mid为界左右一个范围内的点全部筛选出来,放到一个集合里。筛选好以后,当然可以把这些点两两求距离去更新d了,不过这样还是很慢,万一满足条件的点很多呢。这里还得继续优化。首先把这些点按y坐标排序。假设排序好以后有cnt个点,编号为0到cnt-1。那么我们用0号去和1到cnt-1号的点求一下距离,然后1号和2到cnt-1号的点求一下距离。。。如果某两个点y轴距离已经超过了d,这次循环就可以直接break了,开始从下一个点查找了.
 
 
代码如下:
 
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
struct point
{
double x,y;
}; int n,flag[];
point p[]; bool cmpx(point a,point b)
{
return a.x<b.x;
} bool cmpy(int a,int b)
{
return p[a].y <p[b].y;
} double bijiao(double a,double b)
{
return a<b?a:b;
} double juli(point a,point b)
{ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} double close(int l,int r)
{
double ans;
if(l+==r)
return juli(p[l],p[r]);
if(l+==r)
return bijiao(bijiao(juli(p[l],p[r]),juli(p[l+],p[r])),juli(p[l],p[l+]));
int mid=(r+l)/;
ans=bijiao(close(mid+,r),close(l,mid));
int cnt=;
for(int i=l;i<=r;i++)
{
if(p[i].x<=p[mid].x+ans&&p[i].x>=p[mid].x-ans)
flag[cnt++]=i;
}
sort(flag,flag+cnt,cmpy);
for(int i=; i<cnt; i++)
{
for(int j=i+; j<cnt; j++)
{
if(p[flag[j]].y-p[flag[i]].y>=ans)
break;
ans=bijiao(juli(p[flag[i]],p[flag[j]]),ans);
}
}
return ans;
} int main()
{
while(scanf("%d",&n)&&n)
{
for(int i=; i<n; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
sort(p,p+n,cmpx);
printf("%.2lf\n",close(,n-)/);
}
return ;
}

hdu1007的更多相关文章

  1. 【代码笔记】iOS-标题2个图标,点击的时候,页面跳转

    一,效果图. 二,工程图. 三,代码 RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  2. HDU1007最近点对(分治)

    http://acm.hdu.edu.cn/showproblem.php?pid=1007 直接见代码吧.不过这个是N*logN*logN的 尽管如此,我怎么感觉我的比他们的还快??? #inclu ...

  3. HDU-1007 Quoit Design 平面最近点对

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 简单裸题,测测模板,G++速度快了不少,应该是编译的时候对比C++优化了不少.. //STATU ...

  4. HDU1007 Quoit Design 【分治】

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. ACM-计算几何之Quoit Design——hdu1007 zoj2107

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  6. HDU1007.Quoit Design

    -- 点我 -- 题目大意 :给你一堆点,求一个最小圆能够覆盖两个点的半径(最近两点距离的一半): 最多100000个点,暴力即O(n^2)会超时,考虑二分,先求左边最短距离dl,右边dr, 和一个点 ...

  7. 最近点对HDU1007

    利用二分的方法来计算,应该是说利用分治的方法吧! 刚开始感觉时间会爆 后来发现嘎嘎居然没有 ,嗨自己算错了时间: #include <iostream> #include<cstdi ...

  8. Quoit Design(hdu1007)最近点对问题。模版哦!

    Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...

  9. HDU1007(最近点对)

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

随机推荐

  1. jmeter测试手机app

    具体步骤:1.电脑启动jmeter2.jmeter在测试计划新建线程组,在工作台新建http代理服务器3.设置IE代理到本地4.手机wifi设置代理连接到PC5.[启动]jmeter代理服务器6.现在 ...

  2. 让EntityFramework6支持SQLite

    最近给朋友的小孩做了一个毕业设计.用的是asp.net MVC5 + EntityFramework6 + SQL Server 2008. 结果做好后,朋友说能不能不要数据库,直接运行?顿时让我很纠 ...

  3. 业务gis 搭建一个skyline 的js模板 (一)

    刚刚我们说的是二维的系统,如果要展示三维,我们是不是也需要这样,答案是必须的,是一定要,如果你是基于skyline做三维开发,业务开发人员要去搞那套api估计要吐血,所以我们必须得封装起来,这里不介绍 ...

  4. 慕课网-安卓工程师初养成-1-5 使用Eclipse开发Java程序

    来源: http://www.imooc.com/video/1412 eclipse --- IDE 集成开发环境(IDE)是一类软件 将程序开发环境和程序调试环境集合在一起,提高开发效率 其他ID ...

  5. Django中级篇(下)

    中间件 django 中的中间件(middleware),在django中,中间件其实就是一个类,在请求到来和结束后,django会根据自己的规则在合适的时机执行中间件中相应的方法. MIDDLEWA ...

  6. 解决在 使用 AjaxFileUploder 插件时,不能获取返回的 json 结果数据

    在MVC  项目 中使用 AjaxFileUploader 这个插件时,在上传图片或文件时,在控制器中返回的是 json数据,可是在 ie,或 googleChrome 浏览器中却出现 返回的json ...

  7. ASP.NET知识集

    ASP.NET知识集 编辑删除转载2015-06-23 16:31:55 标签:it //删除指定行数据时,弹出询问对话框 ((LinkButton)(e.Row.Cell[7].Controls[0 ...

  8. ASPxCallback控件

    ASPxCallback控件简单来的来说是一个数据回调控件,即不刷新事个页面来展现数据,主要是通过注册客户端事件与服务器端的事件来相互通信完成任务. 如何使用ASPXCallback: 向页面添加Ca ...

  9. 【MySQL】MySQL事务回滚脚本

    MySQL自己的 mysqlbinlog | mysql 回滚不好用,自己写个简单脚本试试: 想法是用mysqlbinlog把需要回滚的事务区域从mysql-bin.file中找到,然后通过脚本再插入 ...

  10. verilog中符号位的扩展问题

    以下内容转自 艾米电子 - 使用有符号数,Verilog(http://www.cnblogs.com/yuphone/archive/2010/12/12/1903647.html) Verilog ...