【hdu1007】最近点对
http://acm.hdu.edu.cn/showproblem.php?pid=1007
分治法的经典应用,复杂度可以证明为nlognlogn
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <string>
#include <ctime>
#include <queue>
#define mem0(a) memset(a, 0, sizeof(a))
#define mem(a, b) memset(a, b, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define eps 0.0000001
#define lowbit(x) ((x) & -(x))
#define memc(a, b) memcpy(a, b, sizeof(b))
#define x_x(a) ((a) * (a))
using namespace std;
#define LL __int64
#define DB double
#define pi 3.14159265359
#define MD 10000007
#define INF (int)1e9
struct Point {
double x, y;
Point(double x = , double y = ):x(x), y(y) {}
void inp() {
scanf("%lf%lf", &x, &y);
}
bool operator < (const Point &a) const {
return x < a.x || x == a.x && y < a.y;
}
} pn[], tmp[];
int cmpy(Point i, Point j)
{
return i.y < j.y;
}
double dist(Point a, Point b)
{
return sqrt(x_x(a.x - b.x) + x_x(a.y - b.y));
}
double solve(int l, int r)
{
if(l == r) return INF;
int m = (l + r) >> ;
double d1 = solve(l, m), d2 = solve(m + , r), d = min(d1, d2);
int nn = ;
for(int i = l; i <= r; i++) {
if(dist(pn[i], pn[m]) <= d) {
tmp[++nn] = pn[i];
}
}
sort(tmp + , tmp + nn, cmpy);
for(int i = ; i < nn; i++) {
double mind = INF;
for(int j = i + ; j <= nn && tmp[j].y - tmp[i].y <= d; j++) {
mind = min(mind, dist(tmp[i], tmp[j]));
}
d = min(d, mind);
}
return d;
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n;
while(cin>> n, n) {
for(int i = ; i <= n; i++) pn[i].inp();
sort(pn + , pn + + n);
double t = solve(, n);
printf("%.2f\n", t / );
}
return ;
}
【hdu1007】最近点对的更多相关文章
- Quoit Design(hdu1007)最近点对问题。模版哦!
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU1007(最近点对)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU1007最近点对(分治)
http://acm.hdu.edu.cn/showproblem.php?pid=1007 直接见代码吧.不过这个是N*logN*logN的 尽管如此,我怎么感觉我的比他们的还快??? #inclu ...
- (hdu1007)Quoit Design,求最近点对
Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings ...
- hdu1007 平面最近点对(暴力+双线程优化)
突发奇想,用双线程似乎可以优化一些暴力 比如说平面最近点对这个题目,把点复制成2份 一份按照x排序,一份按照y排序 然后双线程暴力处理,一份处理x,一份处理y 如果数据利用x递减来卡,那么由于双线程, ...
- HDU-1007 Quoit Design 平面最近点对
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 简单裸题,测测模板,G++速度快了不少,应该是编译的时候对比C++优化了不少.. //STATU ...
- 最近点对HDU1007
利用二分的方法来计算,应该是说利用分治的方法吧! 刚开始感觉时间会爆 后来发现嘎嘎居然没有 ,嗨自己算错了时间: #include <iostream> #include<cstdi ...
- ICP算法(Iterative Closest Point迭代最近点算法)
标签: 图像匹配ICP算法机器视觉 2015-12-01 21:09 2217人阅读 评论(0) 收藏 举报 分类: Computer Vision(27) 版权声明:本文为博主原创文章,未经博主允许 ...
- Quoit Design---hdu1007(最近点对问题 分治法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 题意:给你n(2<=n<=10^6)个点的坐标,然后找到两个点使得他们之间的距离最小 ...
随机推荐
- 《闲扯Redis五》List数据类型底层之quicklist
一.前言 Redis 提供了5种数据类型:String(字符串).Hash(哈希).List(列表).Set(集合).Zset(有序集合),理解每种数据类型的特点对于redis的开发和运维非常重要. ...
- MySQL笔记总结-DDL语言
DDL语言 数据类型 一.数值型 1.整型 tinyint.smallint.mediumint.int/integer.bigint 1 2 3 4 8 特点: ①都可以设置无符号和有符号,默认有符 ...
- SQL Server 之T-SQL基本语句 (3)
继续来用例子总结sql基本语句用法. 在这里在建一个表:课 课程名 上课时间 数学 周一 数学 周二 数学 周三 语文 周一 语文 周二 英语 周一 数据分组:GROUP BY select 课程 ...
- 分析PE
PE文件是Windows平台下可执行文件标准格式,浓缩了微软工程师的设计精华,历经40年依旧保持着原有的设计.分析PE文件对于研究Windows操作系统有着重要的实践意义,对于逆向分析有着重要的指导作 ...
- fasttext的使用,预料格式,调用方法
数据格式:分词后的句子+\t__label__+标签 fasttext_model.py from fasttext import FastText import numpy as np def ge ...
- Java 网络编程 -- 基于TCP实现文件上传
Java TCP 操作基本流程 一.创建服务器 1.指定端口, 使用serverSocket创建服务器 2.阻塞式连接 accept 3.操作:输入流 输出流 4.释放资源 二.创建客户端 1.使用S ...
- Docker安装yapi
安装docker 1.安装依赖包: yum install -y yum-utils device-mapper-persistent-data lvm2 2.安装 Yum -y install do ...
- Zabbix备份数据文件
mysql自带的工具mysqldump,当数据量大了之后进行全备所花的时间比较长,这样将会造成数据库的锁读.从而zabbix服务的监控告警不断,想着做下配置文件的备份.刚好有这么个脚本.满足了需求. ...
- 怎么在java中关闭一个thread
怎么在java中关闭一个thread 我们经常需要在java中用到thread,我们知道thread有一个start()方法可以开启一个线程.那么怎么关闭这个线程呢? 有人会说可以用Thread.st ...
- 【高并发】又一个朋友面试栽在了Thread类的stop()方法和interrupt()方法上!
写在前面 新一轮的面试已经过去,可能是疫情的原因吧,很多童鞋纷纷留言说今年的面试题难度又提高了,尤其是对并发编程的知识.我细想了下,也许有那么点疫情的原因吧,但无论面试的套路怎么变,只要掌握了核心知识 ...