点击打开链接

Quoit Design

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 61473    Accepted Submission(s): 16298

Problem Description
Have you ever played quoit in a playground? Quoit is a game in which flat rings are pitched at some toys, with all the toys encircled awarded.
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
The input consists of several test cases. For each case, the first line contains an integer N (2 <= N <= 100,000), the total number of toys in the field. Then N lines follow, each contains a pair of (x, y) which are the coordinates of a toy. The input is terminated by N = 0.
Output
For each test case, print in one line the radius of the ring required by the Cyberground manager, accurate up to 2 decimal places.
Sample Input
20 01 121 11 13-1.5 00 00 1.50
Sample Output
0.71
0.00
0.75
Author
CHEN, Yue
Source
ZJCPC2004
Recommend
JGShining   |   We have carefully selected several similar problems for you:  1006 1009 1005 1008 1004

HDU1007分治+递归

题意:

给n个点的坐标,求距离最近的一对点之间距离的一半

思路:

其实就是求最近点对的距离,主要思想就是分治
先把n个点按x坐标排序,然后求左边n/2个和右边n/2个的最近距离
然后合并;重点也是合并:

首先,假设点是n个,编号为0到n-1。我们要分治求,则找一个中间的编号mid,
先求出1到mid点的最近距离设为d1,还有mid+1到n的最近距离设为d2。
这里的点需要按x坐标的顺序排好,并且假设这些点中,没有2点在同一个位置。
(若有,则直接最小距离为0了)。

然后,令ans为d1, d2中较小的那个点。
如果说最近点对中的两点都在1-mid集合中,或者mid+1到n集合中,则d就是最小距离了。
但是还有可能的是最近点对中的两点分属这两个集合,所以我们必须先检测一下这种情况是否会存在,
若存在,则把这个最近点对的距离记录下来,去更新ans。这样我们就可以得道最小的距离ans了。

关键是要去检测最近点对,理论上每个点都要和对面集合的点匹配一次,那效率还是不能满足我们的要求。
所以这里要优化。怎么优化呢?考虑一下,假如以我们所选的分割点mid为界,
如果某一点的横坐标到点mid的横坐标的绝对值超过d1并且超过d2,
那么这个点到mid点的距离必然超过d1和d2中的小者,所以这个点到对方集合的任意点的距离必然不是所有点中最小的。

所以我们先把在mid为界左右一个范围内的点全部筛选出来,放到一个集合里。
筛选好以后,当然可以把这些点两两求距离去更新d了,不过这样还是很慢,
万一满足条件的点很多呢。这里还得继续优化。首先把这些点按y坐标排序。
假设排序好以后有cnt个点,编号为0到cnt-1。那么我们用0号去和1到cnt-1号的点求一下距离,
然后1号和2到cnt-1号的点求一下距离。

如果某两个点y轴距离已经超过了ans,这次循环就可以直接break了,开始从下一个点查找了.

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
const int maxn=1e5+10;
struct point{
double x,y;
}p[maxn];
int a[maxn];
bool cmpx(point a,point b){return a.x<b.x;};
bool cmpy(int a,int b){return p[a].y<p[b].y;};
double dis(point a,point b)
{return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double find_min(int l,int r)
{if(l+1==r)  return dis(p[l],p[r]);//只有两个点if(l+2==r)  return min(dis(p[l],p[r]),min(dis(p[l],p[l+1]),dis(p[l+1],p[r])));//三个点int mid=(l+r)>>1;double ans=min(find_min(l,mid),find_min(mid+1,r));//检测最近点对中的两点分属这两个集合int i,j,cnt=0;for(i=l;i<=r;i++){//记录最近点对if(p[i].x>=p[mid].x-ans&&p[i].x<=p[mid].x+ans)a[cnt++]=i;}sort(a,a+cnt,cmpy);for(i=0;i<cnt;i++){for(j=i+1;j<cnt;j++){//如果某两个点y轴距离已经超过了ansif(p[a[j]].y-p[a[i]].y>=ans)    break;ans=min(ans,dis(p[a[i]],p[a[j]]));}}return ans;
}
int main()
{int n;while(scanf("%d",&n)&&n){for(int i=0;i<n;i++){scanf("%lf%lf",&p[i].x,&p[i].y);}sort(p,p+n,cmpx);printf("%.2lf\n",find_min(0,n-1)/2);}return 0;
}

HDU1007 Quoit Design 分治+递归相关推荐

  1. HDU1007(Quoit Design)

    Quoit Design 题目传送门 Problem Description Have you ever played quoit in a playground? Quoit is a game i ...

  2. HDU.1007 Quoit Design

    文章目录 一.题目解读 1.原题 2.分类 3.题意 4.输入输出格式 5.数据范围 二.题解参考 1.总体思路 2.思路② (1).分析 (2).AC代码 三.总结与后话 1.评价 2.后话 一.题 ...

  3. 顺序表应用7:最大子段和之分治递归法

    Description 给定n(1<=n<=50000)个整数(可能为负数)组成的序列a[1],a[2],a[3],-,a[n],求该序列如a[i]+a[i+1]+-+a[j]的子段和的最 ...

  4. c 最大子序列和_最大子序列和暴力法、分治+递归法、妙法

    你好,我是goldsunC 让我们一起进步吧! 最大子序列和 Question:给定整数(可能有负数),求的最大值(为方便起见,如果所有整数均为负数,则最大子序列和为0). 示例: IN : [-2, ...

  5. [Leetcode][第889题][JAVA][根据前序和后序遍历构造二叉树][分治][递归]

    [问题描述][中等] [解答思路] copyOfRange class Solution {public TreeNode constructFromPrePost(int[] pre, int[] ...

  6. [Leetcode][第106题][JAVA][ 从中序与后序遍历序列构造二叉树][分治][递归]

    [问题描述][中等] [解答思路] public class Solution {public TreeNode buildTree(int[] inorder, int[] postorder) { ...

  7. LeetCode 932. 漂亮数组(分治递归/循环)

    文章目录 1. 题目 2. 解题 2.1 分治递归 2.2 循环 1. 题目 对于某些固定的 N,如果数组 A 是整数 1, 2, -, N 组成的排列,使得: 对于每个 i < j,都不存在 ...

  8. 最大子段和之分治递归法

    最大子段和之分治递归法 Time Limit: 10 ms Memory Limit: 400 KiB Problem Description 给定n(1<=n<=50000)个整数(可能 ...

  9. 函数传参问题,桶排序去重,分治递归,摩尔投票求数组众数,数组中心下标求法

    TIPS 1. 我们都知道,地址,指针这两者是完全等价的概念,但是有微小的差别.地址的话是不能够修改的(比如说数组名++就是违法的),而指针的话可以++与--. 2. 以后一旦在代码里面看到字符cha ...

最新文章

  1. 上海交大研究人员使用非侵入性脑机接口和计算机视觉引导对机器人手臂进行共享控制...
  2. 攻防世界Reverse第二题insanity
  3. Linux下的压缩文件剖析
  4. c6011取消对null指针的引用_C++中的引用
  5. 小学生计算机舞蹈,最近“泼水成画”很火?舞蹈生VS体育生,看到计算机:你是来添乱的?...
  6. 在给定约束下可以使用a,b和c形成的字符串数
  7. JUnit5 @Tag注解示例
  8. Hadoop SequenceFile存储格式入门
  9. mysql 数据库隔离级别_彻底搞懂mysql数据库四种隔离级别,实验实战
  10. html变形金刚代码,百度变形金刚JS特效
  11. Glide导致的RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap
  12. 四位数中有几个七C语言,用4、0和7可以组成(    )个不同的三位数,其中最大的数是(    ),最小的数是(     )。——青夏教育精英家教网——...
  13. 广式粤语VS港式粤语
  14. 论文笔记-Understanding Convolution for Semantic Segmentation
  15. 【微服务|Sentinel】实时监控|RT|吞吐量|并发数|QPS
  16. PS中矢量形状图层的合并交叉等运算
  17. 腕能助手android9,篮球教学助手安卓版
  18. QKL123 | 区块链排行榜
  19. JZ3 从头到尾打印链表
  20. 百度云服务器网络检查,百度推出网站安全监测平台,为服务器提供安全漏洞扫描...

热门文章

  1. [luogu2148 SDOI2009] ED (博弈论)
  2. python 日期格式和字符串格式的转化
  3. JavaScript系列文章:谈谈let和const
  4. day10 in india
  5. centos 开机启动java_java程序在centos7里面开机自启动
  6. python read函数_Python read()函数:读入指定长度的文本
  7. 有限服务器延时计算_新建三座超级数据中心,增超百万台服务器 阿里云数据中心选址有何逻辑?...
  8. php三位不够前面加0,php 格式化数字 位数不足前面加0补足的实现方法
  9. tp3.2php开启事务,Thinkphp 3.2.3 开启调试模式
  10. Java中byte[]与十六进制之间的转化