hdu1007
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.
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.
ring required by the Cyberground manager, accurate up to 2 decimal places.
0
首先,假设点是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了。
#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的更多相关文章
- 【代码笔记】iOS-标题2个图标,点击的时候,页面跳转
一,效果图. 二,工程图. 三,代码 RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- HDU1007最近点对(分治)
http://acm.hdu.edu.cn/showproblem.php?pid=1007 直接见代码吧.不过这个是N*logN*logN的 尽管如此,我怎么感觉我的比他们的还快??? #inclu ...
- HDU-1007 Quoit Design 平面最近点对
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 简单裸题,测测模板,G++速度快了不少,应该是编译的时候对比C++优化了不少.. //STATU ...
- HDU1007 Quoit Design 【分治】
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- ACM-计算几何之Quoit Design——hdu1007 zoj2107
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU1007.Quoit Design
-- 点我 -- 题目大意 :给你一堆点,求一个最小圆能够覆盖两个点的半径(最近两点距离的一半): 最多100000个点,暴力即O(n^2)会超时,考虑二分,先求左边最短距离dl,右边dr, 和一个点 ...
- 最近点对HDU1007
利用二分的方法来计算,应该是说利用分治的方法吧! 刚开始感觉时间会爆 后来发现嘎嘎居然没有 ,嗨自己算错了时间: #include <iostream> #include<cstdi ...
- Quoit Design(hdu1007)最近点对问题。模版哦!
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU1007(最近点对)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
随机推荐
- CLOB和BLOB的区别
BLOB和CLOB都是大字段类型,BLOB是按二进制来存储的,而CLOB是可以直接存储文字的.其实两个是可以互换的的,或者可以直接用LOB字段代替这两个.但是为了更好的管理ORACLE数据库,通常像图 ...
- Creating Icon Overlay Handlers / 创建图标标记 Handlers (翻译自MSDN) / VC++, Windows, DLL, ATL, COM
创建图标标记 Handlers Creating Icon Overlay Handlers 图标标记是放在代表着某个 Shell 对象的图标之左下角的小图像.它们通常被加在一个对象的图标的身上来提供 ...
- JavaScript 变量克隆和判断变量类型
一.变量克隆 在js中经常会遇到将一个变量赋值给一个新的变量这种情况,这对于基本类型很容易去实现,直接通过等号赋值就可以了,对于引用类型就不能这样了.(注:像函数,正则也可以直接通过等号赋值) 这里我 ...
- Flash图表控件FusionCharts如何自定义图表上的垂直线
什么是垂直分割线 垂直(或条形图中的水平)分隔线是用来帮助用户分隔数据块的.可以被放置在任何两个数据点,即使是不规则的间隔也可以. <chart caption='Monthly Revenue ...
- Exercises - Kangaroo
Write a definition for a class named Kangaroo with the following methods: An __init__ method that in ...
- jar包程序 读取properties文件
String proFilePath = System.getProperty("user.dir") + "\\Mysettings.properties"; ...
- 洛谷P2734 游戏 A Game
P2734 游戏 A Game 27通过 60提交 题目提供者该用户不存在 标签USACO 难度普及+/提高 提交 讨论 题解 最新讨论 暂时没有讨论 题目背景 有如下一个双人游戏:N(2 < ...
- ios如何获取位置权限
获取当前位置需要改plist文件 在plist文件加入 NSLocationWhenInUseUsageDescription 字段 /** 初始化一个管理器对象 */ locationMan ...
- HDOJ1010(BFS)
//为什么bfs不行呢,想不通 #include<cstdio>#include<cstring>#include<queue>using namespace st ...
- JS 和 CSS 的位置对其他资源加载顺序的影响
JS 和 CSS 在页面中的位置,会影响其他资源(指 img 等非 js 和 css 资源)的加载顺序,究其原因,有三个值得注意的点: JS 有可能会修改 DOM. 典型的,可能会有 document ...