【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 ...
随机推荐
- POJ1985Cow Marathon[树的直径]
Cow Marathon Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 5117 Accepted: 2492 Case ...
- java中“@Deprecated”的意思
例如:Java内在的File类中有如下方法 @Deprecatedpublic URL toURL() throws MalformedURLException {return new URL(&qu ...
- Java中的ReentrantLock和synchronized两种锁定机制的对比
问题:多个访问线程将需要写入到文件中的数据先保存到一个队列里面,然后由专门的 写出线程负责从队列中取出数据并写入到文件中. http://blog.csdn.net/top_code/article/ ...
- Hibernate 和快照
8.Oracle中的数据类型 9.Oracle中的伪列 Rowid和RowNum Rowid Rownum:在内存中形成一个不断裂的自增列 --最重要的.就是Oracle分页 我想要emp中的第二页数 ...
- Android中如何设置RadioButton在文字的右边,图标在左边
from:http://blog.csdn.net/sunnyfans/article/details/7901592?utm_source=tuicool&utm_medium=referr ...
- Mysql备份系列(4)--lvm-snapshot备份mysql数据(全量+增量)操作记录
Mysql最常用的三种备份工具分别是mysqldump.Xtrabackup(innobackupex工具).lvm-snapshot快照.前面分别介绍了:Mysql备份系列(1)--备份方案总结性梳 ...
- js双层动画幻灯
js双层动画幻灯 点击下载
- h1/title,b/strong,i/em 的区别
< strong > 表示html页面上的强调(emphasized text), < em > 表示句子中的强调(即强调语义) 1.b和strong的区别 盲人朋友使用阅读设 ...
- codevs 1531 山峰
codevs 1531 山峰 题目描述 Description Rocky山脉有n个山峰,一字排开,从西向东依次编号为1, 2, 3, --, n.每个山峰的高度都是不一样的.编号为i的山峰高度为hi ...
- C#字符串默认值
using System; class MYTestX { class CT { } class CO { public CT ott; //默认是null public string strx;// ...