题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007

题意:给出n个点求最短的两点间距离除以2。

题解:简单的分治。

其实分治就和二分很像二分的写dfs然后复杂度就是log(n*log(n)*log(n))

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int M = 1e5 + ;
const double inf = 1e20;
struct TnT {
double x , y;
}T[M] , pp[M];
double get_dis(TnT x , TnT y) {
return sqrt((x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y));
}
bool cmpy(TnT x , TnT y) {
return x.y < y.y;
}
bool cmpx(TnT x , TnT y) {
return x.x < y.x;
}
double dfs(int l , int r) {
double d = inf;
if(l == r) {
return d;
}
if(l + == r) {
return get_dis(T[l] , T[r]);
}
int mid = (l + r) >> ;
double d1 = dfs(l , mid);
double d2 = dfs(mid + , r);
d = min(d1 , d2);
int cnt = ;
for(int i = l ; i <= r ; i++) {
if(abs(T[i].x - T[mid].x) <= d) {
pp[cnt++] = T[i];
}
}
sort(pp , pp + cnt , cmpy);
for(int i = ; i < cnt ; i++) {
for(int j = i + ; j < cnt ; j++) {
if(pp[j].y - pp[i].y > d) break;
double d3 = get_dis(pp[i] , pp[j]);
d = min(d , d3);
}
}
return d;
}
int main() {
int n;
while(scanf("%d" , &n) , n) {
for(int i = ; i <= n ; i++) {
scanf("%lf%lf" , &T[i].x , &T[i].y);
}
sort(T + , T + + n , cmpx);
printf("%.2lf\n" , dfs( , n) / );
}
return ;
}

hdu 1007 Quoit Design(分治)的更多相关文章

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

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

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

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

  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) To ...

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

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

  6. hdu 1007 Quoit Design (经典分治 求最近点对)

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

  7. HDU 1007 Quoit Design | 平面分治

    暂鸽 #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #d ...

  8. HDU 1007 Quoit Design 平面内最近点对

    http://acm.hdu.edu.cn/showproblem.php?pid=1007 上半年在人人上看到过这个题,当时就知道用分治但是没有仔细想... 今年多校又出了这个...于是学习了一下平 ...

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

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

随机推荐

  1. Java编程基础阶段笔记 day06 二维数组

    二维数组 笔记Notes 二维数组 二维数组声明 二维数组静态初始化与二位初始化 二维数组元素赋值与获取 二维数组遍历 二维数组内存解析 打印杨辉三角 Arrays工具类 数组中常见的异常 二维数组 ...

  2. IDEA 控制台输出日志无法grep

    不知从何时开始,我的IDEA控制台无法直接使用Grep插件来过滤输出日志了,这个插件真的挺好用的,不知道是升级后造成的还是我自己设置错误,反正在控制台右键无法打开grep来过滤: 在我开发过程中需要这 ...

  3. Python实现批量处理扫描特定目录

    ## 简述在渗透测试中遇到相同CMS站点时,搞定一个站点,相当于拿了一个站群的通用漏洞,所以我们首先需要标注站点的CMS类型,根据要求编写如下脚本 ## 要求1.访问特定目录,如:站点特定 /cmsa ...

  4. Golang版本的rocksdb-对gorocksdb的封装

    rocksdb的优秀特性不用多说,但是它是用c++语言写的,就是这一个特点就把很多人拦住了.虽然rocksdb官方也有Java版本,但是Golang的发展速度让人不容小觑,而且由于golang原生对高 ...

  5. Extjs的textfield的颜色设置和出现的问题笔记

    Ext.getCmp('alarmsLevelVal').setFieldStyle('background-color:#ff0000;background-p_w_picpath: none; ' ...

  6. abp(net core)+easyui+efcore实现仓储管理系统目录

    abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...

  7. L1063 能量项链

    1 #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i <= b ...

  8. gdb调试和编译后运行结果不一致

    今天在看代码时,遇到这么一段代码,我但是用g++编译了,运行发现有Segmentation fault. 然后就用gdb跟进去看看,可是gdb却正常执行了.不知道什么原因. #include < ...

  9. java虚拟机学习笔记(六)---垃圾收集算法

    主要讨论集中垃圾收集算法的思想及发展过程. 1.标记-清除法 最基础的收集算法是标记-清除法,算法分为标记和清除两个阶段:首先标记出所有需要回收的对象,在标记完成后统一回收所有被标记的对象,其标记过程 ...

  10. Axure 使用 简单入门

    1.Axure 简介 Axure是快速原型工具,简单来说就是把自己的web或app想法快速的展示出来的工具.具体信息百科:https://baike.baidu.com/item/axure%20rp ...