【HDU 1007】 Quoit Design
【题目链接】
http://acm.hdu.edu.cn/showproblem.php?pid=1007
【算法】
答案为平面最近点对距离除以2
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 100010
const double INF = 1e10; struct info
{
double x,y;
} a[MAXN]; int n,i; inline bool cmpx(info a,info b)
{
return a.x < b.x;
}
inline bool cmpy(info a,info b)
{
return a.y < b.y;
}
inline double dist(info p,info q)
{
return sqrt(abs(p.x - q.x) * abs(p.x - q.x) + abs(p.y - q.y) * abs(p.y - q.y));
}
inline double Closest_Pair(int l,int r)
{
int i,j,mid,len = ;
static info s[MAXN];
double d;
if (l == r) return INF;
if (l + == r) return dist(a[l],a[r]);
mid = (l + r) >> ;
d = min(Closest_Pair(l,mid),Closest_Pair(mid+,r));
for (i = l; i <= r; i++)
{
if (abs(a[mid].x - a[i].x) <= d) s[++len] = a[i];
}
sort(s+,s+len+,cmpy);
for (i = ; i <= len; i++)
{
for (j = i + ; j <= len && s[j].y - s[i].y <= d; j++)
{
d = min(d,dist(s[i],s[j]));
}
}
return d;
} int main()
{ while (scanf("%d",&n) && n)
{
for (i = ; i <= n; i++) scanf("%lf%lf",&a[i].x,&a[i].y);
sort(a+,a+n+,cmpx);
printf("%.2lf\n",Closest_Pair(,n) / 2.0);
} return ; }
【HDU 1007】 Quoit Design的更多相关文章
- 【HDU 1007】Quoit Design
http://acm.hdu.edu.cn/showproblem.php?pid=1007 最近欧式距离模板题. 用分治大法(分治的函数名用cdq纯属个人习惯_(:з」∠)_) 一开始狂M. 后来判 ...
- 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 ...
随机推荐
- 梦想CAD控件安卓文字样式
增加文字样式 用户可以增加文字样式到数据库,并设置其字体等属性,具体实现代码如下: // 增加文字样式 //getCurrentDatabase()返回当前数据库对象 //getTextstyle() ...
- java_IO_2
1.字节流 InputStream(抽象类) package ioStudy; import java.io.File; import java.io.FileInputStream; import ...
- Redis系列(三)--消息队列、排行榜等
Redis命令执行生命周期: 发送命令--->排队(单线程)--->执行命令--->返回结果 慢查询: 只是针对命令执行阶段 慢查询日志通过一个固定长度的FIFO queue,这个q ...
- ThinkPHP---案例2--职员管理功能
[一]准备工作 (1)创建菜单,修改跳转路径 <li> <a href="javascript:;" class="workerManage" ...
- 13jsp、javaWeb开发模式
13jsp.javaWeb开发模式-2018/07/25 1.jsp jsp实际上就是servlet.jsp=html+java,为用户提供动态内容 不适合编写Java逻辑 2.JSP原理 翻译(生成 ...
- [Python数据结构] 使用 Circular List实现Queue
[Python数据结构] 使用 Circular List实现Queue 1. Queue队列,又称为伫列(queue),是先进先出(FIFO, First-In-First-Out)的线性表.在具体 ...
- 【Codeforces 1037D】Valid BFS?
[链接] 我是链接,点我呀:) [题意] 让你判断一个序列是否可能为一个bfs的序列 [题解] 先dfs出来每一层有多少个点,以及每个点是属于哪一层的. 每一层的bfs如果有先后顺序的话,下一层的节点 ...
- Sliding Window(滑动窗口)
Time Limit: 12000MS Memory Limit: 65536K Total Submissions: 58002 Accepted: 16616 Case Time Limi ...
- Ubuntu 16.04安装NASM汇编IDE-SASM
在Linux下,尤其是Ubuntu,SASM工具应该是用来开发汇编最好用的IDE,小巧且支持调试.支持的编译器有:NASM, MASM, GAS, FASM. 安装步骤: 下载: http://dow ...
- [转]SQL Server编程:SMO介绍
转自:周公 最近在项目中用到了有关SQL Server管理任务方面的编程实现,有了一些自己的心得体会,想在此跟大家分享一下,在工作中用到了SMO/SQL CLR/SSIS等方面的知识,在国内这方面的文 ...