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 ...
随机推荐
- JS事件类型--1
滚轮事件其实就是一个mousewheel事件,这个事件跟踪鼠标滚轮,类似Mac的触屏版. 一.客户区坐标位置 鼠标事件都是在浏览器视口的特定位置上发生的.这个位置信息保存在事件对象的clientX和c ...
- PMD 编译 语法分析 词法分析 抽象语法树
编译原理 163 课堂 http://mooc.study.163.com/learn/-1000002001?tid=1000003000#/learn/content?type=detail&am ...
- Linux运维笔记--第四部
第四部 3. Linux扩展正则表达式实战 扩展的正则表达式:ERE(主要用于egrep或grep -E) + 重复一个或一个以上前面的字符. (*是0或多个) ? 重复0个或一个 ...
- 计算机应用第三次作业:自动开机自动关机 常用DOS命令 关于文件文件夹
一.自动开机 台式机启动时按住DEL键 进入一个蓝色的界面,界面上是英文提示 这个界面是BIOS ,是在机器的ROM中存储 二.自动关机 自动重启 方法一在120秒钟后自动关机 win+r (RUN ...
- 在Scrollview中使用AutoLayout
AutoLayout 与 UIScrollView的相遇是一个不可避免的场景,像UITableView.UIWebView这些都是继承于UIScrollView的,关于它们的autolayout布局大 ...
- 【动态规划】bzoj1939: [Croatian2010] Zuma
隐约记得类似的一道JSOI祖玛……然后好像这题不能够把珠子合并成一段?或许是因为这里珠子碰在一起之后可以不消除? Description 有一行 N 个弹子,每一个都有一个颜色.每次可以让超过 K 个 ...
- http 基础与通讯原理
目录 http 基础与通讯原理 Internet 与中国 1990年10月 注册CN顶级域名 1993年3月2日 接入第一根专线 1994年4月20日 实现与互联网的全功能连接 1994年5月21日 ...
- linux文件属性文文件类型知识
文件类型分别介绍: 1.普通文件:我们通过用ls -l来查看xxx.sql的属性,可以看到第一列内容为-rw-r--r--,值得注意的是第一个符号是-(英文字符减号),在Linux中,以这样的字符开 ...
- jQuery 淡入淡出有png图的时候 ie8下有黑色边框
jQuery fadeTo 时ie8 png图片有黑色边框 往带有png图的样式里加 filter:progid:DXImageTransform.Microsoft.AlphaImageLoader ...
- go语言结构体作为函数参数,采用的是值传递
经过验证,go语言结构体作为函数参数,采用的是值传递.所以对于大型结构体传参,考虑到值传递的性能损耗,最好能采用指针传递. 验证代码: package main import ( "fmt& ...