题目链接: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. Ubuntu下Mongo的安装和笔记

    在linux下的安装 打开https://www.mongodb.com/download-center#community选择linux然后选择自己的Version复制DOWNLOAD旁边的链接 打 ...

  2. 基于zookeeper集群的云平台-配置中心的功能设计

    最近准备找工作面试,就研究了下基于zookeeper集群的配置中心. 下面是自己设想的关于开源的基于zookeeper集群的云平台-配置中心的功能设计.大家觉得哪里有问题,请提出宝贵的意见和建议,谢谢 ...

  3. Activity 使用详解

    极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以 ...

  4. 理解MySQL(一)--MySQL介绍

    一.Mysql逻辑架构: 1. 第一层:服务器层的服务,连接\线程处理. 2. 第二层:查询执行引擎,MySQL的核心服务功能,包括查询解析.分析.优化和缓存,所有跨存储引擎的功能都在这一层实现. 3 ...

  5. android——卡片式布局

    一.CardView <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk ...

  6. bootstrape select使用小结

    看看上面的效果是bootstrape使用的效果.虽然不是很好看,但是符合bootstrape的风格.来看看普通的select的样式 bootstrape下的select和普通select在bootst ...

  7. SonarQube系列三、Jenkins集成SonarQube(dotnetcore篇)

    [前言] 本系列主要讲述sonarqube的安装部署以及如何集成jenkins自动化分析.netcore项目.目录如下: SonarQube系列一.Linux安装与部署 SonarQube系列二.分析 ...

  8. python练习题-1

    1.输出正方形 x=input("请输入:") x=int(x) for i in range(0,x): if (i==0) or (i==x-1): print("* ...

  9. S3C2440 移植最新5.2linux内核

    基于 移植uboot后. 1. 移植linux内核 1.1 下载源码 打开 https://www.kernel.org/ 直接肝最新的 5.2.8 下载完后,在ubuntu里解压备用. 1.2 搭建 ...

  10. Mysql的B+ Tree索引

    为什么要使用索引? 最简单的方式实现数据查询:全表扫描,即将整张表的数据全部或者分批次加载进内存,由于存储的最小单位是块或者页,它们是由多行数据组成,然后逐块逐块或者逐页逐页地查找,这样查找的速度非常 ...