Given N rectangles which may or may not intersect. Report a random point Inside any rectangle. (probability of every point chosen must be equal). How to solve this problem?
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Given N rectangles which may or may not intersect. Report a random point Inside any rectangle. (probability of every point chosen must be equal). How to solve this problem?
Name |
---|
Points that appear in more that one rectangle have more probability or not?
No, every point should have same probability of being chosen irrespective of numbers of rectangles it appears in.
One more question :)...
Could a rectangle have two or more of these N points in it?
There are N rectangles, you have to report random points inside any of these rectangles. Sorry if I was unclear, See image you need to report any random point from blue region. Image
Partition the rectangle union into area-disjoint rectangles, choose a rectangle randomly accordingly to ratio of its area to sum of areas. Choose random (x,y) coordinate inside.
Looks good to me. Can you tell how can I "Partition the rectangle union into area-disjoint rectangles"? (algorithm)
If coordinates are not big, you can get any random point until you get one which is inside one of the rectangles. That will still give you a uniform distribution although at a time complexity cost.