HDU1007(最近点对)
Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 54667 Accepted Submission(s): 14401
Problem Description
In the field of Cyberground, the position of each toy is fixed, and the ring is carefully designed so it can only encircle one toy at a time. On the other hand, to make the game look more attractive, the ring is designed to have the largest radius. Given a configuration of the field, you are supposed to find the radius of such a ring.
Assume that all the toys are points on a plane. A point is encircled by the ring if the distance between the point and the center of the ring is strictly less than the radius of the ring. If two toys are placed at the same point, the radius of the ring is considered to be 0.
Input
Output
Sample Input
0 0
1 1
2
1 1
1 1
3
-1.5 0
0 0
0 1.5
0
Sample Output
0.00
0.75
Author
Source
//2017-08-09
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#define mid ((l+r)>>1) using namespace std; const int N = ;
struct Point{
double x, y;
}P[N], p1[N], p2[N];
int n; bool cmp_x(Point a, Point b){
return a.x < b.x;
} bool cmp_y(Point a, Point b){
return a.y < b.y;
} double distance(Point *a, Point *b){
return sqrt((a->x - b->x)*(a->x - b->x) + (a->y - b->y)*(a->y - b->y));
} //分治,solve(l, r)表示区间[l, r]内的最近点对,solve(l, r) = min(solve(l, mid), solve(mid+1, r), 跨左右子区间的最近点对)
double solve(int l, int r){
if(l >= r)return ;
if(r - l == )return distance(&P[l], &P[r]);
if(r - l == )return min(distance(&P[l], &P[l+]), distance(&P[l+], &P[r]));
double ans = min(solve(l, mid), solve(mid+, r));
//暴力x坐标与mid的x坐标相差不超过当前最优解ans的点
int m = ;
for(int i = l; i <= r; i++){
if(fabs(P[mid].x - P[i].x) <= ans){
p1[m++] = P[i];
}
}
sort(p1, p1+m, cmp_y);
for(int i = ; i < m; i++){
for(int j = i+; j < m; j++){
if(p1[j].y - p1[i].y > ans)break;
ans = min(ans, distance(&p1[i], &p1[j]));
}
}
return ans;
} int main()
{
//freopen("dataIn.txt", "r", stdin);
while(scanf("%d", &n)!=EOF && n){
for(int i = ; i < n; i++)
scanf("%lf%lf", &P[i].x, &P[i].y);
sort(P, P+n, cmp_x);
printf("%.2lf\n", solve(, n-)/);
} return ;
}
HDU1007(最近点对)的更多相关文章
- Quoit Design(hdu1007)最近点对问题。模版哦!
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- 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 ...
- 【hdu1007】最近点对
http://acm.hdu.edu.cn/showproblem.php?pid=1007 分治法的经典应用,复杂度可以证明为nlognlogn #include <iostream> ...
- 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)个点的坐标,然后找到两个点使得他们之间的距离最小 ...
随机推荐
- Windows 出现了回声 & 微软账号无法登陆
Windows 出现了回声,第一反应是杜比音效偷偷背着我开启了客厅模式(后面看了下并没有这个模式,后话了...). 再我尝试打开它发现提示网络无法连接,于是我就直接卸载了,但回声依能没有解决. 后面我 ...
- Swift 里 Array (四) Accessing Elements
根据下标取值 关键代码如下: func _getElement( _ index: Int, wasNativeTypeChecked: Bool, matchingSubscriptCheck: _ ...
- 题解 P2146 【[NOI2015]软件包管理器】
题目大意 给你一棵树, 求一点到根的路径上有多少个未标记点并全标记, 和询问一个点的子树内有多少已标记点和撤销标记 解题方法 1: install 操作 这个操作是求一点到根的路径上有多少个未 ...
- oralce11g RAC 启动后 CRS-0184: Cannot communicate with the CRS daemon.
很奇怪的一个问题! ORACLE数据库服务器,系统启动之后,查看集群状态,发现CRS实例不可用,然后网上查找资料: 隔了几分钟之后,再次查询相关集群服务状态,发现正常了!!! 暂时得出的结论:操作系统 ...
- Strom的trident单词计数代码
/** * 单词计数 */ public class LocalTridentCount { public static class MyBatchSpout implements IBatchSpo ...
- (转)pathlib路径库使用详解
原文:https://xin053.github.io/2016/07/03/pathlib%E8%B7%AF%E5%BE%84%E5%BA%93%E4%BD%BF%E7%94%A8%E8%AF%A6 ...
- c++处理类型与自定义数据结构
1.typedef 类型别名 有时我们在阅读c++程序时,发现一些未见过的类型,这实际上就是typedef导致的,使用很简单,如下: typedef int wayne; wayne a = , b ...
- Hadoop(三)搭建Hadoop全分布式集群
原文地址:http://www.cnblogs.com/zhangyinhua/p/7652686.html 阅读目录(Content) 一.搭建Hadoop全分布式集群前提 1.1.网络 1.2.安 ...
- JVM(四)JVM的双亲委派模型
1.两种不同的类加载器 从JAVA虚拟机的角度来讲,只存在两种不同的类加载器:一种是启动类加载器(Bootstrap ClassLoader),这个类加载器使用C++语言实现,是虚拟机自身的一部分:另 ...
- Windows下的Jdk 1.8*安装并配置(图文详解)
不多说,直接上干货! 简单说下,jdk1.8*的下载,见http://www.cnblogs.com/zlslch/p/5658383.html 双击jdk-8u60-windows-x64.exe运 ...