1. 套圈

该博客讨论了如何在Cyberground游戏中设计一个能够包围玩具的环的最大学习问题。介绍了输入输出格式,解释了如何计算最近点对距离,并提出了分治策略来解决这个问题。博主分享了在处理TLE问题时的经验,包括使用输入函数,提前分配数组等技巧。此外,还详细说明了分治法的边界条件和递归步骤,以及在不使用快速排序的情况下合并数组的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目描述:

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.


测试用例:

输入:

4
0 3
3 2
4 0
7 1
0

输出:

1.12

解析:

原题是HDU1007 Quoit Design,一道最近点对问题。大意是给n个点的坐标,求这些点中最近两点距离,并输出这最短距离的一半。
先提一下TLE问题:
1. 输入使用scanf函数,比直接用cin快些;
2. 提前开固定大小的数组,我开始是用new Point[N]的,后来想想临时创建、销毁会耽误不少时间。

好了,进入正题:
因为老师说了要用分治思想,那就先只考虑分治法了。
对于分治,我们先看边界条件。本题N>=2,故首先应该考虑2点的距离,这个好判断,我们直接求这两点的距离就行了。再看如果加1个点的情况,这个也很好判断,我们就两次判断即可。再看再加1个点的情况,此时我们会发现问题可以被划分成更小的子问题了,即我们可以取个中线,对在左边界和中线内的点求最近点对是一个子问题,对右边界和中线内的点求最近点对是一个子问题,但还有一种情况不能忽略,就是可能存在最近点对是跨越中线的,即一个点在左区域,另一个点在右区域,所以这个还需要单独考虑。
我们想看前两种子问题情况,这个基本思想是没有问题的,但老师说要进行算法可行性证明,要证明证明!!! 好像没毛病!
我们看跨中线部分,这个需要从左边界到右边界依次判断各点与中线点的水平距离,水平距离必须小于之前递归得到的极小距离,否则舍弃,满足条件的点

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值