Upcoming SlideShare
×

# [ACM-ICPC] UVa-10245

1,377 views

Published on

Published in: Education
4 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
1,377
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
30
0
Likes
4
Embeds 0
No embeds

No notes for slide

### [ACM-ICPC] UVa-10245

1. 1. UVa - 10245 郭至軒（KuoE0） KuoE0.tw@gmail.com KuoE0.ch
2. 2. Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) http://creativecommons.org/licenses/by-sa/3.0/ Latest update: Feb 27, 2013
3. 3. The Closest Pair ProblemGiven a set of points in a two dimensional space, you will have to ﬁnd the distancebetween the closest two points. InputThe input ﬁle contains several sets of input. Each set of input starts with an integerN (0<=N<=10000), which denotes the number of points in this set. The next N linecontains the coordinates of N two-dimensional points. The ﬁrst of the two numbersdenotes the X-coordinate and the latter denotes the Y-coordinate. The input isterminated by a set whose N=0. This set should not be processed. The value of thecoordinates will be less than 40000 and non-negative.OutputFor each set of input produce a single line of output containing a ﬂoating pointnumber (with four digits after the decimal point) which denotes the distancebetween the closest two points. If there is no such two points in the input whosedistance is less than 10000, print the line INFINITY. link
4. 4. Sample I/Osample input sample output3 INFINITY0 0 36.221510000 1000020000 2000050 26 6743 7139 107189 1400
5. 5. How to Solve1. 對所有點依據 x 座標進行排序2. 每次點群對半分為兩堆3. 剩下小於等於三個點時，枚舉點對求最短距離4. 利用子問題求出的最短距離 d，從切割點向兩邊尋 找所有 x 座標與切割點 x 座標相差小於等於 d 的點5. 枚舉該範圍內的點對求最短距離，並與從子問題求 出的解做比較
6. 6. Sort by x-coordinateindex 0 1 2 3 4 5 6 7 8 9 x 7 6 2 9 10 6 1 8 13 11 y 7 8 5 9 5 1 2 8 11 13index 0 1 2 3 4 5 6 7 8 9 x 1 2 6 6 7 8 9 10 11 13 y 2 5 8 1 7 8 9 5 13 11
7. 7. Divide
8. 8. Divide
9. 9. Divide
10. 10. Divide
11. 11. Divide
12. 12. Divide
13. 13. Solve
14. 14. Solve
15. 15. Merge
16. 16. Merged
17. 17. Merged d d
18. 18. Merged d d
19. 19. Merged d d
20. 20. Merged d d
21. 21. Merged d d
22. 22. Merged d d
23. 23. Merged d d
24. 24. Merged d d
25. 25. Merged d Minimum d
26. 26. Cheer up!