×

ASTRD - Editorial

Author: Pavel Sheftlevitch
Tester: Antoniuk Vasyl and Misha Chorniy
Editorialist: Praveen Dhinwa

hard

PREREQUISITES:

3D geometry, intersection of two circles in 3D

PROBLEM:

Given a sphere of radius $R$ and center at $(0, 0, 0)$. You are given $n$ astroids lying outside the sphere. An asteroid can be observed from a point if it's at least $10^{-3}$ above the horizon line at the place of the observation. You need to find out minimum possible number of asteroids you can observe from some point on the suface of the sphere.

EXPLANATION:

Let us solve 2D version first
Assume that we want to solve the same problem for 2D version. So, sphere will be replaced by a circle. Let us say that we want to check number of observable astroids from a point $p$ on the circle. Tangent at point $p$ divides the space into two half planes, one of them is visible by p and other is not. An astroid will be said to be visible if distance between it and the tangent plane at p is at least $10^{-3}$. So, now we can count the number of astroids visible from a point on the circle (i.e. number of points in the visible halfplane of tanget at point $p$).

Now, for finding the minimum number of visible astroids, we need to search over all possible points on the surface (perimeter) of the circle. As number of points on the circle are not finite, so our search space is infinite. So, we need to make some observations in order to reduce our search space to a finite set of points on circle.

Let us think in reverse, i.e. instead of asking what are the set of points on the circle visible by an astroid located at point p? We can draw two tangents from point p on the circle. The visibile part will be the arc subtended by this point whose endpoints are intersection of tangent and circle.

For each pair of points, we check whether their arcs intersect with each other or not. We include the intersection points in our search space. Other than those, for each astroid, we include the endpoints of arcs also in the search space.

So, total number of points in search space can be $O(n^2)$. Checking for each point in search space will take another $O(n)$ time making it an $O(n^3)$ algorithm.

Extend it to 3D version
Similar to above, tangent at a point on the plane will divide the space into two halfs : visible and non-visible.

Now the visible surface by an astroid on the surface of planet will be a circle.

For finding search space, we can take each pair of these circles and include their intersection points in the search space.

If a circle does not intersect with any other, we can choose any two points on the surface in the search space.

We will need to make use of 3D geometry to find the intersection points of two circles in 3D. You can learn it from here.

Finally, overall time complexity of the algorithm is $O(n^3)$ same as the 2D case.

SAMPLE SOLUTIONS:

This question is marked "community wiki".

2.5k53137170
accept rate: 20%

19.8k350498541

 2 I did it in a simpler way. I just considered all planes tangent to planet and passing through 2 asteroids. It can be seen that we can move the plane which has minimum number of asteroids on its side to arrive at this state. So its just O(n^2) planes to consider. We can check how many asteroids are visible in linear time for each case. answered 11 Jan '16, 20:28 51●3 accept rate: 0% 1 I did it in the same way :P But was getting WA for a long time, just because of the fact that multiple asteriods can be present at the same point. (11 Jan '16, 22:47) How you took that particular plane? I did the same but had to use binary search type thing, thus making my Complexity reach O(n^3 logn) (13 Jan '16, 09:59) uhateme5★
 2 For each pair of points, we check whether their arcs intersect with each other or not. We include the intersection points in our search space. If two arcs,which are on a circle, intersect at a point then that point is the endpoint of an arc. The other way they can intersect is have an overlap. But in this case points of intersection are infinite. Please explain. answered 04 Feb '16, 09:54 5★foraml 21●1 accept rate: 0%
 0 Solved it in O(N^2) time per case. Main part of solution is same, as in editorial, but when found arcs intersecting with current circle, you can do sort of scanline on this circle. First we sort start and end points' angles (from -PI to PI) of arcs. Starting from -PI with initial counter set as number of arcs crossing -PI point, we increase counter when at start point and decrease when we at end point. Here is my AC solution https://www.codechef.com/viewsolution/9134966 answered 11 Jan '16, 15:56 6★noxwell 1●1 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,852
×1,359
×647
×106

question asked: 11 Jan '16, 09:52

question was seen: 2,664 times

last updated: 04 Feb '16, 09:54