【HDU 1007】Quoit Design
http://acm.hdu.edu.cn/showproblem.php?pid=1007
最近欧式距离模板题。
用分治大法(分治的函数名用cdq纯属个人习惯_(:з」∠)_)
一开始狂M。

后来判断n是否为0就不M了QwQ
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 100003;
struct Point {double x, y;} P[N];
int n, tot, id[N];
bool cmp_x(Point A, Point B) {return A.x < B.x;}
bool cmp_y(int A, int B) {return P[A].y < P[B].y;}
double sqr(double x) {return x * x;}
double dis(int x, int y) {return sqrt(sqr(P[x].x - P[y].x) + sqr(P[x].y - P[y].y));}
double cdq(int l, int r) {
if (r - l == 1) return dis(l, r);
if (r - l == 2) return min(dis(l, l + 1), min(dis(l, r), dis(l + 1, r)));
int mid = (l + r) >> 1;
double d = min(cdq(l, mid), cdq(mid + 1, r));
tot = 0; double left = P[mid].x - d, right = P[mid].x + d;
for(int i = l; i <= r; ++i)
if (left <= P[i].x && P[i].x <= right)
id[++tot] = i;
sort(id + 1, id + tot + 1, cmp_y);
for(int i = 1; i <= tot; ++i)
for(int j = i + 1; j <= tot; ++j) {
if (P[id[j]].y - P[id[i]].y > d) break;
d = min(d, dis(id[j], id[i]));
}
return d;
}
int main() {
while (~scanf("%d", &n)) {
if (n == 0) break;
for(int i = 1; i <= n; ++i)
scanf("%lf%lf", &P[i].x, &P[i].y);
sort(P + 1, P + n + 1, cmp_x);
printf("%.2lf\n", cdq(1, n) / 2);
}
return 0;
}
【HDU 1007】Quoit Design的更多相关文章
- 【HDU 1007】 Quoit Design
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=1007 [算法] 答案为平面最近点对距离除以2 [代码] #include <algorith ...
- HDU 1007:Quoit Design(分治求最近点对)
http://acm.hdu.edu.cn/showproblem.php?pid=1007 题意:平面上有n个点,问最近的两个点之间的距离的一半是多少. 思路:用分治做.把整体分为左右两个部分,那么 ...
- 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题
[HDU 3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...
- 【HDU 5647】DZY Loves Connecting(树DP)
pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...
- -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】
[把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...
- 【HDU 2196】 Computer(树的直径)
[HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...
- 【HDU 2196】 Computer (树形DP)
[HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...
- 【HDU 5145】 NPY and girls(组合+莫队)
pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...
- 【后台管理系统】—— Ant Design Pro入门学习&项目实践笔记(三)
前言:前一篇记录了[后台管理系统]目前进展开发中遇到的一些应用点,这一篇会梳理一些自己学习Ant Design Pro源码的功能点.附:Ant Design Pro 在线预览地址. Dashboard ...
随机推荐
- NOIP2014飞扬的小鸟[DP][WRONG]
坑人啊朴素的dp 75分 用了完全背包才是80分,结果普遍偏小 为什么啊啊啊啊啊 等以后再写一遍吧 #include<iostream> #include<cstdio> #i ...
- 第18章 图元文件_18.2 增强型图元文件(emf)(1)
18.2 增强型图元文件(emf) 18.2.1 创建并显示增强型图元文件的步骤 (1)创建:hdcEMF = CreateEnhMetaFile(hdcRef,szFilename,lpRect,l ...
- 斗地主(Noip2015Day1T3)
题目描述 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来进行的扑克牌游戏.在斗地主中,牌的大小关系根据牌的数码表示如下:3<4< ...
- jsonobject 遍历 org.json.JSONObject
import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public static ...
- 机器学习实战--logistic回归
#encoding:utf-8 from numpy import * def loadDataSet(): #加载数据 dataMat = []; labelMat = [] fr = open(' ...
- Nginx针对https站点的部署
一.Nginx安装(略)安装的时候需要注意加上 --with-http_ssl_module,因为http_ssl_module不属于Nginx的基本模块.Nginx安装方法:# ./configur ...
- 主机无法访问虚拟机Linux的apache
在虚拟机linux里安装了httpd,即appache,启动后,按正常情况在主机是可以用浏览器通过访问虚拟机linux的ip来访问的.如果出现无法访问的情况,解决办法可以参考如下: 这里我的虚拟机联网 ...
- Java 集合系列11之 Hashtable详细介绍(源码解析)和使用示例
概要 前一章,我们学习了HashMap.这一章,我们对Hashtable进行学习.我们先对Hashtable有个整体认识,然后再学习它的源码,最后再通过实例来学会使用Hashtable.第1部分 Ha ...
- Log4net在类库中的用法
app.config应当放置在解决方案的根目录下.具体流程如下: 第一步:应该下载log4net.dll并引入到你的项目中,下载见附件 第二步:需要配置相关的配置文件App.config或Web.co ...
- IE6/IE7/IE8/Firefox/Chrome/Safari的CSS hack兼容一览表
浏览器兼容问题一直是前段开发工程师比较头痛的问题,熟悉了里面的规则也就变得简单了,这里有一份资料可以分享给大家,大家平时开发过程中遵循这个规律的话,会变得轻松多了: 各浏览器CSS hack兼容表: ...