forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEllysRivers.html
More file actions
20 lines (15 loc) · 7.98 KB
/
Copy pathEllysRivers.html
File metadata and controls
20 lines (15 loc) · 7.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<html><body bgcolor="#cccccc" text="#000000"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td>Shopping is by no means an easy task. Yes, sure, if you want to buy shoes or some clothes that's no problem at all. But what happens if you would like an extremely rare poison, found only in the mists of Amazonia? Now you see, Elly's life is not as easy as you would think. She has almost reached her final destination, but unfortunately she can only use boats and travel by foot for the final part.<p></p>
There are N+1 really long, but narrow parallel islands, going from South to North, numbered from 0 to N, inclusive. There are also N rivers between the islands, numbered from 0 to N-1, inclusive. River i is <b>width</b>[i] kilometers wide and flows between islands i and i+1. The speed of the current in each river is negligible. For river i, the maximum speed at which Elly can sail is <b>speed</b>[i] kilometers per hour, regardless of the direction in which she sails.<p></p>
All islands are <b>length</b> kilometers long. Starting from the southmost point, each one has boat docks one kilometer apart throughout its entire coastline. Thus, there are <b>length</b> + 1 docks on each island (at kilometer 0, 1, …, <b>length</b>). The islands are so narrow, that you can assume the same dock serves the boats on both sides of the island, and that walking horizontally from one side of the island to the other takes no time.<p></p>
For simplicity we can represent the islands as parallel vertical line segments, and the docks as points on the plane. Island 0 goes from point (0, 0) to (0, <b>length</b>), island 1 from (<b>width</b>[0], 0) to (<b>width</b>[0], <b>length</b>), island 2 from (<b>width</b>[0] + <b>width</b>[1], 0) to (<b>width</b>[0] + <b>width</b>[1], length), and so on, where <b>width</b>[i] gives the width of the i-th river. The docks on island 0 are with coordinates (0, 0), (0, 1), … (0, <b>length</b>); the ones on island 1 are with coordinates (<b>width</b>[0], 0), (<b>width</b>[0], 1), …, (<b>width</b>[0], <b>length</b>); these on island 2 are with coordinates (<b>width</b>[0] + <b>width</b>[1], 0), (<b>width</b>[0] + <b>width</b>[1], 1), …, (<b>width</b>[0] + <b>width</b>[1], <b>length</b>) and so on.<p></p>
Elly can only take boats from dock to dock (i.e. she can neither depart from nor arrive at non-integer coordinates). She can also walk (vertically) along any island with a constant speed of <b>walk</b> kilometers per hour. The girl is currently on the southmost point of the westmost island and wants to reach the northmost point of the eastmost island. Elly wonders what is the minimal time required to travel to her destination. Help her by writing a method that calculates this for her.<p></p>
You are given the length of the islands in the int <b>length</b> and the walking speed in the int <b>walk</b>. The widths of the rivers will be given in the vector <int> <b>width</b> and the maximal sailing speeds in the vector <int> <b>speed</b>. Return a double giving the shortest time in which she can reach her destination.</td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>EllysRivers</td></tr><tr><td>Method:</td><td>getMin</td></tr><tr><td>Parameters:</td><td>int, int, vector <int>, vector <int></td></tr><tr><td>Returns:</td><td>double</td></tr><tr><td>Method signature:</td><td>double getMin(int length, int walk, vector <int> width, vector <int> speed)</td></tr><tr><td colspan="2">(be sure your method is public)</td></tr></table></td></tr><tr><td>    </td></tr><tr><td></td></tr><tr><td colspan="2"><h3>Notes</h3></td></tr><tr><td align="center" valign="top">-</td><td>Your return value must have a relative or an absolute error of less than 1e-9.</td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>length</b> will be between 1 and 100,000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>walk</b> will be between 1 and 1,000,000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>width</b> will contain between 1 and 50 elements, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>speed</b> will contain between 1 and 50 elements, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>width</b> and <b>speed</b> will contain the same number of elements.</td></tr><tr><td align="center" valign="top">-</td><td>Each element of <b>width</b> will be between 1 and 1,000,000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>Each element of <b>speed</b> will be between 1 and 1,000,000, 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>10</pre></td></tr><tr><td><pre>3</pre></td></tr><tr><td><pre>{5, 2, 3}</pre></td></tr><tr><td><pre>{5, 2, 7}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 3.231651964071508</pre></td></tr><tr><td><table><tr><td colspan="2">Elly will not walk on any of the islands. She will sail four kilometers to the north in the first river,<br></br>
reaching the second island at point (5, 4). Then she sails another one kilometer to the north in the second river,<br></br>
going to (7, 5) on the third island. In the end she will sail to her destination at (10, 10).<br></br>
The required times for her journey are as follows:
<ul>
<li>(0, 0) -> (5, 4) = 6.403124237433 / 5 = 1.280624847487 hours</li>
<li>(5, 4) -> (7, 5) = 2.236067977499 / 2 = 1.118033988749 hours</li>
<li>(7, 5) -> (10, 10) = 5.830951894845 / 7 = 0.832993127835 hours</li>
</ul>
</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>10000</pre></td></tr><tr><td><pre>211</pre></td></tr><tr><td><pre>{911}</pre></td></tr><tr><td><pre>{207}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 48.24623664712219</pre></td></tr><tr><td><table><tr><td colspan="2">Don't forget that Elly can walk on the islands.</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>1337</pre></td></tr><tr><td><pre>2</pre></td></tr><tr><td><pre>{100, 200, 300, 400}</pre></td></tr><tr><td><pre>{11, 12, 13, 14}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 128.57830549575695</pre></td></tr><tr><td><table><tr><td colspan="2"></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>77</pre></td></tr><tr><td><pre>119</pre></td></tr><tr><td><pre>{11, 12, 13, 14}</pre></td></tr><tr><td><pre>{100, 200, 300, 400}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 0.3842077071089629</pre></td></tr><tr><td><table><tr><td colspan="2"></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>7134</pre></td></tr><tr><td><pre>1525</pre></td></tr><tr><td><pre>{11567, 19763, 11026, 10444, 24588, 22263, 17709, 11181, 15292, 28895, 15039, 18744, 19985, 13795, 26697, 18812, 25655, 13620, 28926, 12393}</pre></td></tr><tr><td><pre>{1620, 1477, 2837, 2590, 1692, 2270, 1655, 1078, 2683, 1475, 1383, 1153, 1862, 1770, 1671, 2318, 2197, 1768, 1979, 1057}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 214.6509731258811</pre></td></tr><tr><td><table><tr><td colspan="2">A large random example.</td></tr></table></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>