由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
CS版 - 问一个算法
相关主题
请教:格式化硬盘冲撞系统也不能干掉的trojan--崩溃了 (转载)A Graphics Question
求复杂度分析的一个递归式的解做题作题
Please help me prove SUM(logi) is Omega(nlogn)answer Re: EE challenge CS
请问已知3个圆的圆心和半径,求相交部分的重心怎么求?CLRS problem 7-4 tail recursion 求教。
算法题目请教 (转载)包子求解c++ 程序
【包子求助】20M*20M的loop怎么搞? (转载)Transportation problem
几道算法题求教Please help, an algorithem question
有没有这样的算法一个算法时间复杂度问题
相关话题的讨论汇总
话题: point话题: do话题: mbr话题: range话题: counter
进入CS版参与讨论
1 (共1页)
u****h
发帖数: 2193
1
N个圆, 给出坐标和半径, 半径各自不同. 最小16, 最大128. 问其中有多少对相交?
另外, 地图长宽都是400 * sqrt(n)
一对圆相交iff半径和大于圆心距离.
u****h
发帖数: 2193
2
当然, 我们expect
s*****g
发帖数: 5159
3
你要多少复杂度?N^2很容易,
counter =0;
For i =1 to n
for j = 1 to n and j!=i
if i intersect j
counter++;
end for
end for
return counter/2.

【在 u****h 的大作中提到】
: N个圆, 给出坐标和半径, 半径各自不同. 最小16, 最大128. 问其中有多少对相交?
: 另外, 地图长宽都是400 * sqrt(n)
: 一对圆相交iff半径和大于圆心距离.

s*****g
发帖数: 5159
4
我觉得这个像vector classification的问题,如果想知道精确的数目(而不是大致数
目),我觉得还得N^2,容我再想想。

【在 u****h 的大作中提到】
: 当然, 我们expect
s*****g
发帖数: 5159
5
可以用类似k-dimensional tree的方法。
1. Randomly select a point (a center of a circle).
2. Draw a line in throw the point, and divide the circles into to partitons,
one at a side and one at the other size, the those circles crossed by the
line, they belongs to neither (counter saparately).
3. The above two disjoint circle sets will not intersect either other at all
since they are separated by the line.
4. recursively do the same thing on the subset.
5. When return from the recursion, count those circles

【在 u****h 的大作中提到】
: 当然, 我们expect
c****r
发帖数: 185
6
Build a spatial index and then do range queries.
1. Find the bounding box of all points
2. Split the bounding box into 4 sub-boxes.You can split either on the
middle point (kd-tree) or median point (R-tree). Do this recursively.
3. For each point, do a range query where the range is the radius.
The time complexity is O(n*logn).
s*****n
发帖数: 5488
7
such thing is called q-tree. so you can google.

【在 c****r 的大作中提到】
: Build a spatial index and then do range queries.
: 1. Find the bounding box of all points
: 2. Split the bounding box into 4 sub-boxes.You can split either on the
: middle point (kd-tree) or median point (R-tree). Do this recursively.
: 3. For each point, do a range query where the range is the radius.
: The time complexity is O(n*logn).

s*****g
发帖数: 5159
8

When does the recursion stop?
What's the query in a binary answer question?

【在 c****r 的大作中提到】
: Build a spatial index and then do range queries.
: 1. Find the bounding box of all points
: 2. Split the bounding box into 4 sub-boxes.You can split either on the
: middle point (kd-tree) or median point (R-tree). Do this recursively.
: 3. For each point, do a range query where the range is the radius.
: The time complexity is O(n*logn).

u****h
发帖数: 2193
9
不好意思没理解, 最后一步, do the range query where the range is the radius,
是怎么通过这一步来计算相交园个数的阿?
不知道跟这个有没有关系, 不过半径可能不同...
不过半径的range是给出来的, 最小16, 最大128

【在 c****r 的大作中提到】
: Build a spatial index and then do range queries.
: 1. Find the bounding box of all points
: 2. Split the bounding box into 4 sub-boxes.You can split either on the
: middle point (kd-tree) or median point (R-tree). Do this recursively.
: 3. For each point, do a range query where the range is the radius.
: The time complexity is O(n*logn).

c****r
发帖数: 185
10
quad-tree?

【在 s*****n 的大作中提到】
: such thing is called q-tree. so you can google.
相关主题
【包子求助】20M*20M的loop怎么搞? (转载)A Graphics Question
几道算法题求教做题作题
有没有这样的算法answer Re: EE challenge CS
进入CS版参与讨论
c****r
发帖数: 185
11
Range query:
For each MBR (minimum bounding box), you can compute the minimum and maximum
distance from a given point P.
1. If max_distance <= P.radius, then all points inside MBR are answers
2. If min_distance > P.radius, then the MBR can be pruned
3. If min < P.radius <= max, then trace down to sub-MBRs.
Do this recursively then you can get all answers of a given point, O(logN).
Do it for every point, O(NlogN)

,

【在 u****h 的大作中提到】
: 不好意思没理解, 最后一步, do the range query where the range is the radius,
: 是怎么通过这一步来计算相交园个数的阿?
: 不知道跟这个有没有关系, 不过半径可能不同...
: 不过半径的range是给出来的, 最小16, 最大128

u****h
发帖数: 2193
12
我觉得这个算法做的只是多少个点落在圆内, 并不是真正的相交园. 圆心可能在外面,
但是相交了 .
当然, 因为半径的最大范围是给出来的, 所以可以把当前园的半径virtually增大, 但
是即使如此, 还是要检查每个园是否真正相交. 这个复杂度似乎就不能保证nlogn了
不过, 这个算法还是in a very good shape....
或者我还有地方没理解, 您能仔细讲讲?

maximum

【在 c****r 的大作中提到】
: Range query:
: For each MBR (minimum bounding box), you can compute the minimum and maximum
: distance from a given point P.
: 1. If max_distance <= P.radius, then all points inside MBR are answers
: 2. If min_distance > P.radius, then the MBR can be pruned
: 3. If min < P.radius <= max, then trace down to sub-MBRs.
: Do this recursively then you can get all answers of a given point, O(logN).
: Do it for every point, O(NlogN)
:
: ,

c****r
发帖数: 185
13
Oops, I forgot that you are finding intersecting circles.
Well, you can represent each point as a single MBR from the beginning.
When you build the spatial index, the leaf nodes are no longer points, but
their MBRs.
The max/min conditions still hold.

【在 u****h 的大作中提到】
: 我觉得这个算法做的只是多少个点落在圆内, 并不是真正的相交园. 圆心可能在外面,
: 但是相交了 .
: 当然, 因为半径的最大范围是给出来的, 所以可以把当前园的半径virtually增大, 但
: 是即使如此, 还是要检查每个园是否真正相交. 这个复杂度似乎就不能保证nlogn了
: 不过, 这个算法还是in a very good shape....
: 或者我还有地方没理解, 您能仔细讲讲?
:
: maximum

u****h
发帖数: 2193
14
我还是没有理解, 外切正方形相交不一定保证园相交把...

【在 c****r 的大作中提到】
: Oops, I forgot that you are finding intersecting circles.
: Well, you can represent each point as a single MBR from the beginning.
: When you build the spatial index, the leaf nodes are no longer points, but
: their MBRs.
: The max/min conditions still hold.

y***u
发帖数: 101
15

maximum
This is not O(log n).

【在 c****r 的大作中提到】
: Range query:
: For each MBR (minimum bounding box), you can compute the minimum and maximum
: distance from a given point P.
: 1. If max_distance <= P.radius, then all points inside MBR are answers
: 2. If min_distance > P.radius, then the MBR can be pruned
: 3. If min < P.radius <= max, then trace down to sub-MBRs.
: Do this recursively then you can get all answers of a given point, O(logN).
: Do it for every point, O(NlogN)
:
: ,

1 (共1页)
进入CS版参与讨论
相关主题
一个算法时间复杂度问题算法题目请教 (转载)
[合集] How to sort a singly linked list in O(n) time?【包子求助】20M*20M的loop怎么搞? (转载)
请教:K-Nearest neighbor search 有现成算法吗?几道算法题求教
About testing of uniform distribution有没有这样的算法
请教:格式化硬盘冲撞系统也不能干掉的trojan--崩溃了 (转载)A Graphics Question
求复杂度分析的一个递归式的解做题作题
Please help me prove SUM(logi) is Omega(nlogn)answer Re: EE challenge CS
请问已知3个圆的圆心和半径,求相交部分的重心怎么求?CLRS problem 7-4 tail recursion 求教。
相关话题的讨论汇总
话题: point话题: do话题: mbr话题: range话题: counter