forked from keshavnandan/Topcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrossroads.html
15 lines (15 loc) · 6.4 KB
/
Crossroads.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<html><body bgcolor="#000000" text="#ffffff"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td>You are watching a car race. Each car starts a different point on the x-axis, travels at the same speed, and starts at the same time. However, each car is travelling along a different road (which extends to infinity in one direction, and is stopped by the x-axis in the other direction), and each road has its own direction specified by an angle between 1 and 179, inclusive. An angle of 90 indicates that the road heads directly in the positive y direction, while an angle of 1 indicates that the road heads just a little bit north of the positive x direction. Note that cars never head in the negative y direction.<br></br>
<img src="http://www.topcoder.com/contest/problem/Crossings/cars.png"></img><br></br>
<br></br><br></br>
Sometimes, two or more roads intersect at some point. When this happens, the car that reaches the intersection first is able to block the intersection so that no other cars can pass through it. If two cars reach an intersection at the same time, the one with the lower index passes, while the other one is blocked.
<br></br><br></br>
<img src="http://www.topcoder.com/contest/problem/Crossings/cross2.png"></img><br></br>
In this picture, the cars following the red paths make it through all of the intersections, while the cars on the gray paths are blocked.<br></br>
You will be given a vector <int> <b>angles</b>, where the i<sup>th</sup> element of <b>angles</b> is the angle between the x-axis and the road that the i<sup>th</sup> car drives on, in degrees. The order of the elements of <b>angles</b> corresponds to the order of the cars along the x-axis (no two cars start at the exact same location), with the first element of <b>angles</b> corresponding to the car with the leftmost starting position on the x-axis.<br></br><br></br>
Your method should return a vector <int> containing the 0-based indices of all the cars that will pass all of the intersections along their roads. Your return should be sorted in ascending order.<br></br><br></br>
Note that the exact locations of the cars along the x-axis do not matter. All that matters is their order, and the directions in which they head.
</td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>Crossroads</td></tr><tr><td>Method:</td><td>getOut</td></tr><tr><td>Parameters:</td><td>vector <int></td></tr><tr><td>Returns:</td><td>vector <int></td></tr><tr><td>Method signature:</td><td>vector <int> getOut(vector <int> angles)</td></tr><tr><td colspan="2">(be sure your method is public)</td></tr></table></td></tr><tr><td colspan="2"><h3>Limits</h3></td></tr><tr><td>    </td><td><table><tr><td>Time limit (s):</td><td>2.000</td></tr><tr><td>Memory limit (MB):</td><td>64</td></tr></table></td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>angles</b> will contain between 1 and 50 elements, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>Each elemtent of <b>angles</b> will be between 1 and 179, inclusive.</td></tr><tr><td colspan="2"><h3>Examples</h3></td></tr><tr><td align="center" nowrap="true">0)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{105, 75, 25, 120, 35, 75}</pre></td></tr></table></td></tr><tr><td><pre>Returns: { 0, 1, 5 }</pre></td></tr><tr><td><table><tr><td colspan="2">The example from the problem statement.<br></br>
<img src="http://www.topcoder.com/contest/problem/Crossings/cross2.png"></img><br></br></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">1)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{1, 1, 1, 1, 1, 1}</pre></td></tr></table></td></tr><tr><td><pre>Returns: { 0, 1, 2, 3, 4, 5 }</pre></td></tr><tr><td><table><tr><td colspan="2">No two cars' paths will ever intersect, so they all pass all intersections.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">2)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{13}</pre></td></tr></table></td></tr><tr><td><pre>Returns: { 0 }</pre></td></tr><tr><td><table><tr><td colspan="2">Only one car.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">3)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{90, 123, 1, 23, 132, 11, 28, 179, 179, 77, 113, 91}</pre></td></tr></table></td></tr><tr><td><pre>Returns: { 0 }</pre></td></tr><tr><td><table><tr><td colspan="2">The first car passes all intersections. The last car will be stopped by the first car. All other cars are between those two, and will be stopped by one of them.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">4)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{179, 89, 90, 91, 1}</pre></td></tr></table></td></tr><tr><td><pre>Returns: { 0, 2, 4 }</pre></td></tr><tr><td><table><tr><td colspan="2">Neither the first nor the last car will intersect with any other car. Car 1 and car 3 will both be stopped by car 2.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">5)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{89, 91}</pre></td></tr></table></td></tr><tr><td><pre>Returns: { 0 }</pre></td></tr><tr><td><table><tr><td colspan="2">Both cars reach the intersection at the same time, and hence only the first one passes.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">6)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{140, 118, 54, 166, 151, 44, 90, 5, 14, 6,
64, 129, 74, 33, 134, 25, 11, 95, 65, 145,
29, 162, 24, 147, 45, 103, 63, 97, 120, 156,
167, 170, 19, 28, 100, 144, 161, 13, 157, 148}</pre></td></tr></table></td></tr><tr><td><pre>Returns: { 0, 1, 6 }</pre></td></tr><tr><td></td></tr></table></td></tr></table><p>This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved. </p></body></html>