【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 ...
随机推荐
- centos 搭建pptp
很多朋友不会在CENTOS 在安装vpn,因为对于菜鸟来说安装VPN的确是个头晕的事情,特别是安装openvpn,不过安装pptp就稍微简单一点,国内网上有很多安装pptp的教程,但是都很繁杂,我在国 ...
- Kattis - missinggnomesD Missing Gnomes (思路题)
题目: 题意: 给出已经去除了几个数的一个序列,任务是将去除的数字插回去补全这个序列,输出字典序排在第一的那个补全的序列. 例如: 样例输入: 5 3 1 4 2 样例输出: 1 3 4 2 5 思路 ...
- Python学习-算术运算符,赋值运算符和复合运算符
算术运算符 常见的算术运算符有 : + 加法运算符 print(1 + 2); // 3 print('1' + '2'); //12 不仅可以进行2个数字的相加,还可以连接2个字符串 - ...
- Python面向对象类的特殊成员方法
类的特殊成员方法:1.__doc__ : 打印类下面的注释 2.__module__和__class__:from lib.aa import C输出类被导出的模块名lib.aa,输出类的模块名和类名 ...
- linux基础常用语句--新手
查询:ls查看全部内容:ls -n删除:rm -rf 文件名创建目录: mkdir解压:rpm -验证是否安装:rpm -p 文件名rpm -ivh --nodeps 不需要前置条件的安装查询当前路径 ...
- led1,1s取反,led2计数10次取反
1 //利用定时器0 1s,led1取反,利用计数器1,跳10,取反 #include<reg52.h> #define uchar unsigned char #define uint ...
- Uva 10730 Antiarithmetic?
uva 10730 题意:给出一列数字,如果其中存在长度大于等于3的等差数列,输出no,不存在就输出yes 这道题标定了数列长度n,而且这n个数数据范围是从0到n-1,没有相同的数,这就给我们枚举提供 ...
- Ajax_数据格式_XML
[XML] 优点: --XML是一种通用的数据格式. --不必把数据强加到已经定义好的格式中,而是要为数据自定义合适的标记. --利用DOM可以完全掌控文档. 缺点: --如果文档来自于服务器,就必须 ...
- 【11】AngularJS HTML DOM
AngularJS HTML DOM AngularJS 为 HTML DOM 元素的属性提供了绑定应用数据的指令. ng-disabled 指令 ng-disabled 指令直接绑定应用程序数据到 ...
- gif & tools
gif & tools https://www.cockos.com/licecap/ https://www.cockos.com/licecap/licecap128-install.ex ...