hdu 1007 Quoit Design 分治求最近点对
Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 29344 Accepted Submission(s): 7688
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.
0
0
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std; const int maxn=;
int N,f[maxn];
struct Point
{
double x,y;
}p[maxn]; double min(double a,double b){ return a<b?a:b;}
bool cmpx(const Point &a,const Point &b)
{
return a.x<b.x;
}
bool cmpy(const int a,const int b)
{
return p[a].y<p[b].y;
}
double dist(int a,int b)
{
return sqrt((p[a].x-p[b].x)*(p[a].x-p[b].x)+(p[a].y-p[b].y)*(p[a].y-p[b].y));
}
double BinarySearch(int l,int r)
{
if(l+==r)
{
return dist(l,r);
}
if(l+==r)
{
return min(min(dist(l,l+),dist(l+,l+)),dist(l,l+));
}
int mid=(l+r)>>;
double ans=min(BinarySearch(l,mid),BinarySearch(mid+,r));
int i,j,cnt=;
for(i=l;i<=r;i++)
{
if(fabs(p[i].x-p[mid].x)<=ans)
f[cnt++]=i;
}
sort(f,f+cnt,cmpy);
for(i=;i<cnt;i++)
{
for(j=i+;j<cnt;j++)
{
if(p[f[j]].y-p[f[i]].y>=ans) break;
ans=min(ans,dist(f[i],f[j]));
}
}
return ans;
}
int main()
{
while(scanf("%d",&N),N)
{
for(int i=;i<N;i++)
scanf("%lf %lf",&p[i].x,&p[i].y);
sort(p,p+N,cmpx);
printf("%.2lf\n",BinarySearch(,N-)/);
}
return ;
}
hdu 1007 Quoit Design 分治求最近点对的更多相关文章
- HDU 1007 Quoit Design(经典最近点对问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1007 Quoit Design Time Limit: 10000/5000 MS (Java/Oth ...
- HDU 1007 Quoit Design 平面内最近点对
http://acm.hdu.edu.cn/showproblem.php?pid=1007 上半年在人人上看到过这个题,当时就知道用分治但是没有仔细想... 今年多校又出了这个...于是学习了一下平 ...
- HDU 1007 Quoit Design(计算几何の最近点对)
Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings ...
- hdu 1007 Quoit Design(平面最近点对)
题意:求平面最近点对之间的距离 解:首先可以想到枚举的方法,枚举i,枚举j算点i和点j之间的距离,时间复杂度O(n2). 如果采用分治的思想,如果我们知道左半边点对答案d1,和右半边点的答案d2,如何 ...
- HDU 1007 Quoit Design【计算几何/分治/最近点对】
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 1007 Quoit Design(分治法求最近点对)
大致题意:给N个点,求最近点对的距离 d :输出:r = d/2. // Time 2093 ms; Memory 1812 K #include<iostream> #include&l ...
- hdu 1007 Quoit Design (最近点对问题)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1007 Quoit Design(二分+浮点数精度控制)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- (hdu1007)Quoit Design,求最近点对
Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings ...
随机推荐
- Python——流程控制语句
if语句 条件进行判断,满足,则执行里面 的内容:不满足,则执行if循环下面的语句 基本语法: if 判断条件: 满足后执行语句 1 如果:女人的年龄>30岁,那么:叫阿姨 age_of_gir ...
- Sorted Union-freecodecamp算法题目
Sorted Union 1.要求 写一个 function,传入两个或两个以上的数组,返回一个以给定的原始数组排序的不包含重复值的新数组. 换句话说,所有数组中的所有值都应该以原始顺序被包含在内,但 ...
- 【转】浅谈对主成分分析(PCA)算法的理解
以前对PCA算法有过一段时间的研究,但没整理成文章,最近项目又打算用到PCA算法,故趁热打铁整理下PCA算法的知识.本文观点旨在抛砖引玉,不是权威,更不能尽信,只是本人的一点体会. 主成分分析(PCA ...
- [vijos]P1642 班长的任务
背景 十八居士的毕业典礼(1) 描述 福州时代中学2009届十班同学毕业了,于是班长PRT开始筹办毕业晚会,但是由于条件有限,可能每个同学不能都去,但每个人都有一个权值,PRT希望来的同学们的权值总和 ...
- LeetCode_6
问题: 6. Z字形变换 链接:https://leetcode-cn.com/problems/zigzag-conversion/description/ 分析: A 仿真方法 直接模拟整个过程, ...
- 基于Centos7.2搭建Cobbler自动化批量部署操作系统服务
1 Cobbler服务器端系统环境配置 1.1 系统基本环境准备 [root@cobbler-server ~]# cat /etc/redhat-release CentOS L ...
- 科学计算库Numpy——概述
Numpy主要用于数组的各种计算. 导入Numpy import numpy as np 数组类型 Numpy的数组类型为numpy.ndarray. array=np.array([1,2,3,4, ...
- Linux学习-核心与核心模块
谈完了整个开机的流程,您应该会知道,在整个开机的过程当中,是否能够成功的驱动我们主机的硬 件配备, 是核心 (kernel) 的工作!而核心一般都是压缩文件,因此在使用核心之前,就得要将他解 压缩后, ...
- [转] 重定向 CORS 跨域请求
非简单请求不可重定向,包括第一个preflight请求和第二个真正的请求都不行. 简单请求可以重定向任意多次,但如需兼容多数浏览器,只可进行一次重定向. 中间服务器应当同样配置相关 CORS 响应头. ...
- base64转图片
y一个简单的工具类,附上: /** * @param imgStr 图片的base64 * @param path 将要生成的地址 * @return */ public static boolean ...