#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<stack>
#include<string>
#include<queue>
using namespace std;
const int maxn = ;
const long long INF = 0xfffffff;
struct Point
{
double x, y;
}P[maxn], Temp[maxn];
bool cmp(Point a, Point b)
{
if(a.x != b.x)
return a.x < b.x;
return a.y < b.y;
}
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 Colosest(int L,int R)
{
if(L == R)
return INF;
if(L + == R)
return dis(P[L],P[R]);
int Mid = (L + R) / ;
double d1 = Colosest(L, Mid);
double d2 = Colosest(Mid + , R);
double d = min(d1, d2);
//递归找左右两侧的点,最小距离
int k = ; for(int i = Mid; i >= L; i--)
{
if( P[Mid].x - P[i].x < d )
Temp[k++] = P[i];
else
break;
} for(int j = Mid + ; j <= R; j++)
{
if(P[j].x - P[Mid].x < d)
Temp[k++] = P[j];
else
break;
}
//找出在中间点的可能点对 然后排序
sort(Temp,Temp+k,cmpy); for(int i=; i<k; i++)
{
/*需要一个 Temp[j].y - Temp[i].y < d 优化, 不然会超时*/
for(int j=i+; j < k && Temp[j].y - Temp[i].y < d ; j++)
{
double d3 = dis(Temp[j], Temp[i]);
if(d3 < d)
d = d3;
}
}
return d;
}
int main()
{
int n;
while(scanf("%d",&n) ,n)
{
for(int i=; i<n; i++)
scanf("%lf%lf",&P[i].x,&P[i].y);
sort(P,P+n,cmp);//先排序
printf("%.2lf\n", Colosest(,n-)/ );
}
return ;
}

最近点对问题 HDU Quoit Design 1007 分治法的更多相关文章

  1. HDU 1007 Quoit Design(经典最近点对问题)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1007 Quoit Design Time Limit: 10000/5000 MS (Java/Oth ...

  2. hdu 1007 Quoit Design (最近点对问题)

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

  3. HDU 1007 Quoit Design【计算几何/分治/最近点对】

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

  4. hdu 1007 Quoit Design 分治求最近点对

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

  5. HDU 1007 Quoit Design(计算几何の最近点对)

    Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings ...

  6. HDU ACM 1007 Quoit Design 分而治之的方法,最近点

    意甲冠军:给n坐标点.半一对点之间的距离所需的距离最近. 分析:分而治之的方法,最近点. #include<iostream> #include<algorithm> #inc ...

  7. HDU 1007 Quoit Design(二分+浮点数精度控制)

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

  8. 杭电OJ——1007 Quoit Design(最近点对问题)

    Quoit Design Problem Description Have you ever played quoit in a playground? Quoit is a game in whic ...

  9. 最近点对问题 POJ 3714 Raid && HDOJ 1007 Quoit Design

    题意:有n个点,问其中某一对点的距离最小是多少 分析:分治法解决问题:先按照x坐标排序,求解(left, mid)和(mid+1, right)范围的最小值,然后类似区间合并,分离mid左右的点也求最 ...

随机推荐

  1. weblogic数据源配置的问题,weblogic密码破解

    weblogic 报错 please increase XXX,得知是连接池出了问题,查看weblogic配置,发现没有设置超时 查看oracle 当前session,可以看到连接的机器,用户,当前执 ...

  2. python一些技巧

    1. 使用目录管理 sys.path.append(sys.argv[0][:sys.argv[0].rfind('com'+os.sep+'abc')]) from com.abc.libs imp ...

  3. [转] 学习HTML/JavaScript/PHP 三者的关系以及各自的作用

    1.What is HTML? When you write a normal document using a word processor like Microsoft Word/Office, ...

  4. Protobuf的自动反射消息类型的方法

    1. 每个消息头部中带上type name,作为消息的类型标识 2. 通过type name可以找到描述符Descriptor*, FindMessageTypeByName 3. 通过描述符Desc ...

  5. Exception in thread "main" brut.androlib.err.UndefinedResObject: resource spec: 0x01030200(转)

    反编译时遇到标题中的异常,根据描述,原因是找不到资源文件,最有可能的原因是apk中使用了系统资源. 解决办法如下: 从手机中导出framework-res.apk文件,该文件在/system/fram ...

  6. Python之路,Day13-----暂无正在更新中

    Python之路,Day13-----暂无正在更新中

  7. Linq101-Quantifiers

    using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Quantif ...

  8. 探究Activity的各回调方法

    刚毕业那会儿,一心想朝着java web的方向进军,却岂料实习的时候阴差阳错地踏入了Android的大门,自此人生跌宕起伏.坎坎坷坷,在一家外企参与了几个需要越过GFW才能使用的有关于体育赛事的项目, ...

  9. $(document).ready(function(){}),$().ready(function(){})和$(function(){})三个有区别么

    三者都是一样的,最完整的写法是:$(document).ready(function(){})ready() 函数仅能用于当前文档,因此无需选择器.所以document选择器可以不要,那么就可以写成: ...

  10. Css3中的响应式布局的应用

    Media Queries直译过来就是“媒体查询”,在我们平时的Web页面中head部分常看到这样的一段代码: <link href="css/reset.css" rel= ...