hdu 1007 Quoit Design (最近点对问题)
Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25335 Accepted Submission(s): 6716
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
1 1
2
1 1
1 1
3
-1.5 0
0 0
0 1.5
0
0.00
0.75
//1468MS 2288K 1378 B G++
/* 题意;
给出n个点,求最近的两个点的距离的一般 最近点对:
要用到分治的思想做,是时间复杂度为O(nlgn),直接求会超时
最近点对问题在很多算法书和资料上都有讲到,主要思想是分治。 注意一点: 用C的 qsort排序一直TLE,表示有点无力.. */
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#define N 100005
using namespace std;
struct node{
double x,y;
}p[N];
int a[N];
int n;
double cmpx(node a,node b)
{
return a.x<b.x;
}
double cmpy(int a,int b)
{
return p[a].y<p[b].y;
}
inline double Max(double a,double b)
{
return a>b?a:b;
}
inline double Min(double a,double b)
{
return a<b?a:b;
}
inline double Dis(node a,node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double find(int l,int r)
{
if(l==r) return 0x7ffffff;
if(r==l+) return Dis(p[l],p[r]);
if(r==l+) return Min(Dis(p[l],p[r]),Min(Dis(p[l],p[l+]),Dis(p[l+],p[r])));
int mid=(l+r)>>;
double d=Min(find(l,mid),find(mid+,r));
int cnt=;
for(int i=l;i<=r;i++){
if(p[i].x>=p[mid].x-d && p[i].x<=p[mid].x+d)
a[cnt++]=i;
}
sort(a,a+cnt,cmpy);
for(int i=;i<cnt;i++){
for(int j=i+;j<cnt;j++){
if(p[a[j]].y-p[a[i]].y>=d) break;
d=Min(d,Dis(p[a[i]],p[a[j]]));
}
}
return d;
}
int main(void)
{
while(scanf("%d",&n)!=EOF)
{
if(n==) break;
for(int i=;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
sort(p,p+n,cmpx);
printf("%.2lf\n",find(,n-)/);
}
return ;
}
hdu 1007 Quoit Design (最近点对问题)的更多相关文章
- HDU 1007 Quoit Design最近点对( 分治法)
题意: 给出平面上的n个点,问任意点对之间的最短距离是多少? 思路: 先将所有点按照x坐标排序,用二分法将n个点一分为二个部分,递归下去直到剩下两或一个点.对于一个部分,左右部分的答案分别都知道,那么 ...
- 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【计算几何/分治/最近点对】
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)Tot ...
- HDU 1007 Quoit Design(二分+浮点数精度控制)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- 杭电OJ——1007 Quoit Design(最近点对问题)
Quoit Design Problem Description Have you ever played quoit in a playground? Quoit is a game in whic ...
- 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(分治法求最近点对)
大致题意:给N个点,求最近点对的距离 d :输出:r = d/2. // Time 2093 ms; Memory 1812 K #include<iostream> #include&l ...
随机推荐
- 关于Vue 兄弟组件通信
最近项目中遇到希望在操作路由组件里面内容的时候可以影响共用组件Header组件(这个其实就是他的兄弟组件)的操作. 意思就是 router-view指向的router来影响Header组件的信息 首 ...
- mysql基础 反范式化
- 红帽CentOS7 密码破解
1.在启动的时候按住方向键停留在内核选项页面,在内核选项出按e键 2.进入到另一个页面后,寻找到以linux16开头的地方,按end到行后,输入空格,然后输入rd.break console=tty0 ...
- 用js控制单选框或者多选框问题
出现如图问题时,这时不能用attr方法添加checked属性了,改用$( "input" ).prop( "checked", true ),完美解决.
- 【word】html转doc的小研究
html转doc,页眉页脚丢失 html 转 doc,是全屏铺满(缩放级别很高)
- python爬虫-简单使用xpath下载图片
首先 1.为方便以下进行 谷歌浏览器里要安装xpath脚本 2.下载一个lmxl 命令:pip install lxml 3. 以下三张图是一个,当时爬的 <糗事百科>里的图片 值 ...
- 010---Django与Ajax
预备知识: 什么是Json? 定义:json是一种轻量级的数据交换格式. 如果我们要在不同的编程语言中传递对象,就必须把对象序列化为标准格式,比如XML,但那是以往的时代,现在大多数使用序列化为jso ...
- [Codeforces958E2]Guard Duty (medium)(区间DP)
Description 题目链接 Solution 可以把题目转化一下模型,将间隔取出来,转化为N-1个数,限制不能取相邻两个数,求取K个数的最小价值 设DP[i][j]表示前i个数取j个最大价值(第 ...
- CentOS下使用Mysql
安装过程百度,然后cd /etc->vi my.cnf修改配置文件,在mysqld下添加lower_case_table_name=1和character_set_server=utf8,保存退 ...
- Android 打印方法调用堆栈
RuntimeException here = new RuntimeException("here"); here.fillInStackTrace(); Log.w(" ...