【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 ...
随机推荐
- UVA 12169 Disgruntled Judge【扩展欧几里德】
题意:随机选取x1,a,b,根据公式xi=(a*xi-1+b)%10001得到一个长度为2*n的序列,奇数项作为输入,求偶数项,若有多种,随机输出一组答案. 思路:a和b均未知,可以考虑枚举a和b,时 ...
- POJ1523 SPF[无向图割点]
SPF Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8139 Accepted: 3723 Description C ...
- java 22 - 19 多线程之生产者和消费者的代码优化
在之前,是把生产者录入数据和消费者获取数据的所有代码都分别写在各自的类中. 这样不大好 这次把生产者和消费者部分关键代码都写入资源类中: package zl_Thread; public class ...
- 12个JQuery小贴士
返回顶部 使用JQuery的 animate 和 scrollTop 方法可以创建简单地返回顶部的动画: // Back to top $('a.top').click(function (e) { ...
- cocoapod
更新代码: sudo gem install -n /usr/local/bin cocoapods --pre ex: The dependency `` is not used in any co ...
- removeNode is not defined removeNode is not a function
在javascript操作dom树的时候可能会经常遇到增加,删除节点的事情,比如一个输入框后一个增加按钮,一个删除按钮,点击增加就增加 个输入框,点击删除就删除对应的输入框.在一些js框架,如Prot ...
- js区分鼠标单双击 阻止事件冒泡
function clickOrDblClick(obj) { count++; if (obj != undefined) { var rowStr = $.trim($(obj).find(&qu ...
- Linux虚拟机突然不能上网了
之前是可以的,然后这次打开突然不能上网了. 更改配置后就好了: 配置如下: 我的问题是打开打开之后变成了OFF不是ON了.然后不管怎么改变O都失败了. 改为: 这样虚拟机这边就好了. 我们看下wind ...
- AR 不同 继承映射的问题总结
在使用AR(Nhibernate) 做ORM时,使用类的继承体系时,它有不同的映射方式,解决的问题不同,带来的问题差异也很大. 1.所有数据 存储在一张表,不同的类使用 DiscriminatorCo ...
- mybatis 3.x 缓存Cache的使用
mybatis 3.x 已经支持cache功能了,使用很简单,在mappper的xml文件里添加以下节点: <mapper namespace="com.cnblogs.yjmyzz. ...