You are not logged in. Please login at www.codechef.com to post your questions!

×

ASTRD - Editorial

PROBLEM LINK:

Practice
Contest

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

DIFFICULTY:

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:

Author
Tester
Editorialist

This question is marked "community wiki".

asked 11 Jan '16, 09:52

dpraveen's gravatar image

4★dpraveen ♦♦
2.5k53137170
accept rate: 20%

edited 11 Jan '16, 15:13

admin's gravatar image

0★admin ♦♦
19.8k350498541


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.

link

answered 11 Jan '16, 20:28

evil999man's gravatar image

7★evil999man
513
accept rate: 0%

edited 11 Jan '16, 21:54

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) gvaibhav217★

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★

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.

link

answered 04 Feb '16, 09:54

foraml's gravatar image

5★foraml
211
accept rate: 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

link

answered 11 Jan '16, 15:56

noxwell's gravatar image

6★noxwell
11
accept rate: 0%

edited 11 Jan '16, 15:58

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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