主要想弄出一个最近点对的模板出来。。。
主要运用分治思想。。思路大概是这样的:
先把点按x排序,然后按x进行分治。。。分当然简单。。难点就在合并了。。
怎么合并?先找出中点,然后以已经求得的局部最短距离d为基准,将与中点的x距离不超过d的加入集合,然后按y对该点集进行排序,然后枚举点i,再枚举点j,维护最短距离d,如果y距离超过d便不再枚举。。
语文不好。。。如果流程不清楚可以看代码或其他blog。。。
然后关键是这个时间复杂度据说是nlogn。。本人并不是很承认这个复杂度。。我感觉应该是nlognlogn。。下面进行证明。。
参考:http://blog.csdn.net/lu1012123053/article/details/9825175
主要关注这个文章的鸽巢原理,它证明了在d*2d范围内最多存在6点,那么同理在2d*d中最多也只存在6点。我们可以得知,在代码 53行起的2层循环中,j最多循环6次,那么,这个看似是O(n^2)的复杂度实际上已经降到了O(n)
那么主要复杂度就来源于排序了。。。引文就直接说该算法的复杂度是nlogn实在是无法认同,因为还得将那6个点给挑出来。。怎么挑?只能排序。。
所以每次合并的时间为nlogn,那么合起来就是O(nlognlogn)了。。
然而。。上面是考虑了最坏的情况,即每次合并时,都将所有点都包含进来了,实际中只有部分点会包含进来,所以实际复杂度可能并没有达到O(nlognlogn)。。
而且在特定情况下我们还可以尽可能将合并时的点集减少,这个可以参考我以前的文章:
Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 58976 Accepted Submission(s): 15632
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
2 0 0 1 1 2 1 1 1 1 3 -1.5 0 0 0 0 1.5 0
Sample Output
0.71 0.00 0.75
Author
CHEN, Yue
Source
Recommend
JGShining | We have carefully selected several similar problems for you: 1006 1009 1005 1008 1004
Statistic |
Submit |
Discuss |
Note