【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 ...
随机推荐
- ssh多主机
#node1 HOST node1 HostName 10.10.10.10 Port 21 User ubuntu UseKeychain yes AddKeysToAgent yes #node2 ...
- oracle数据库子查询的结果需要使用多次解决办法
with c as (select a.trandt,sum(a.tranam) tranam from tran a group by a.trandt )--将子查询抽取出来,以后可以直接用.该方 ...
- layer实现窗口抖动效果
function showMsg(msg, icon){ layer.msg(msg, { //1:正确:2:错误:3:询问:4:锁定:5:失败:6:成功:7:警告:16:加载 icon : icon ...
- 软件工程师需要了解的网络知识:从铜线到HTTP(一)—— 前言
转自:https://lvwenhan.com/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/485.html?hmsr=toutiao.io&utm_medium ...
- [angular2]解决安装 angular-cli 报错:Cannot find module 'github-url-from-git'
1.运行:sudo rm -rf /usr/local/lib/node_modules/npm 2.重新安装最新版本的node,最新版本的node已经集成了npm,所以无需另外安装. 3.运行:su ...
- Linux 中设置 MySQL 字符集为 UTF-8
(1)查看 MySQL 字符集 登录 mysql:mysql -u root -p 查询 mysql 字符集:mysql> show variables like 'chara%'; 说明:将 ...
- 关于ISIS协议 CSNP报文的周期更新理解
为何ISIS协议的CSNP报文在MA网络环境中是以周期更新然而在P2P网络环境中只更新一次? 个人通过视频及资料学习理解: 我们知道ISIS的CSNP报文类似OSPF中的DBD报文,作用就是用来确认彼 ...
- 【模板】网络流-最大流 Dinic
洛谷 3376 #include<cstdio> #include<algorithm> #include<cstring> #define N 10010 #de ...
- [bzoj2242][SDOI2011][计算器] (Baby-Step-Giant-Step+快速幂+exgcd)
Description 你被要求设计一个计算器完成以下三项任务: 1.给定y,z,p,计算Y^Z Mod P 的值: 2.给定y,z,p,计算满足xy≡ Z ( mod P )的最小非负整数: 3.给 ...
- [bzoj2461][BeiJing2011][符环] (括号配对+记忆化搜索+高维dp)
Description 在可以炼制魔力强大的法杖的同时,Magic Land 上的人们渐渐意识到,魔力强大并不一定能给人们带来好处——反而,由此产生的破坏性的高魔力释放,给整个大陆蒙上了恐怖的阴影. ...