You can see the problem here.
Every two circles touch in at most one point (in particular no circle can be contained in a different circle).
Does anyone have some ideas about the problem?
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 166 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
You can see the problem here.
Every two circles touch in at most one point (in particular no circle can be contained in a different circle).
Does anyone have some ideas about the problem?
Name |
---|
Well, you coul build a Voronoi diagram of the set of centers of circles, and then check every adjacent (by edges) pair of circles in the diagram (O(n)), just check that the sum of radious is the same as the distance between the center, if radii are integer such a check can even be made in integers.
Now it appears to me that no circle Y con be ok for a circle X if it isn't its neighbour, without violating the property of only one point of intersection with some neighbour of X.
Of course writing a voronoi working in time for 500000 points may prove challenging, so if you do that, you let me see your code after that, I've never implemented O(nlogn) Voronoi myself :)
Sorry in advance if there is any mistake with this solution, and perhaps there is a simpler solution.
Thanks for sharing your ideas.
You are welcome
It is a quite standard sweep line problem.
Sweep with a vertical line from left to right. There are 2 types of events: a circle began, a circle ended.
Maintain a set of circles that the line currently intersects (began, but not ended). In this set, maintain them sorted by Y coordinate of their center. Then each time you add a circle, you only need to check at most 2 of it's neighbors (for having a common point with it). The same when you delete a circle, there could be at most one new pair of neighbors formed that you need to check.
What you have to be careful with:
Wow, Thanks a lot.