|
| 1 | +<html><body bgcolor="#000000" text="#ffffff"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td><p> |
| 2 | +Cat Taro jumps quite well. He decided to jump onto some rocks. |
| 3 | +</p> |
| 4 | +<p> |
| 5 | +</p> |
| 6 | +<p> |
| 7 | +There are N rocks on a straight line. For each i, rock i (0-based index) is at the coordinate <b>rocks</b>[i]. |
| 8 | +Taro starts his travel from a point with an integer coordinate. |
| 9 | +Each time Taro jumps, his coordinate increases. |
| 10 | +For each i, the length of his i-th jump (1-based count) is 2^(i-1). |
| 11 | +That is, his first jump has length 1, his second jump has length 2, his third jump has length 4, and so on. |
| 12 | +If he starts at the coordinate X, his jumps will take him to X+1, then X+3, then X+7, and so on. |
| 13 | +</p> |
| 14 | +<p> |
| 15 | +</p> |
| 16 | +<p> |
| 17 | +Taro wants to maximize the number of times he jumps onto a rock. |
| 18 | +He can start his jumping from any integer point between <b>A</b> and <b>B</b>, inclusive. |
| 19 | +You are given the vector <int> <b>rocks</b>, the int <b>A</b> and the int <b>B</b>. |
| 20 | +Return the maximum possible number of times Taro jumps onto a rock. |
| 21 | +</p></td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>TaroJumps</td></tr><tr><td>Method:</td><td>getNumber</td></tr><tr><td>Parameters:</td><td>vector <int>, int, int</td></tr><tr><td>Returns:</td><td>int</td></tr><tr><td>Method signature:</td><td>int getNumber(vector <int> rocks, int A, int B)</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>256</td></tr></table></td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>rocks</b> will contain between 1 and 50 elements, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>All elements of <b>rocks</b> will be distinct.</td></tr><tr><td align="center" valign="top">-</td><td>Each element of <b>rocks</b> will be between 0 and 1,000,000,000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>B</b> will be between 0 and 1,000,000,000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>A</b> will be between 0 and <b>B</b>, 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>{2, 6, 16}</pre></td></tr><tr><td><pre>0</pre></td></tr><tr><td><pre>1</pre></td></tr></table></td></tr><tr><td><pre>Returns: 2</pre></td></tr><tr><td><table><tr><td colspan="2">In this test case the valid starting points are 0 and 1. |
| 22 | +<p> |
| 23 | +</p> |
| 24 | +If Taro starts at coordinate 0, he will jump to 1, 3, 7, 15, and so on. |
| 25 | +In this case he will not jump onto any rock. |
| 26 | +<p> |
| 27 | +</p> |
| 28 | +If he starts at coordinate 1, he will jump to 2, 4, 8, 16, and so on. |
| 29 | +In this case, he will jump onto a rock twice: the first time at the coordinate 2, and then at the coordinate 16. |
| 30 | +<p> |
| 31 | +</p> |
| 32 | +Thus, the answer is 2.</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>{2, 4, 9}</pre></td></tr><tr><td><pre>0</pre></td></tr><tr><td><pre>0</pre></td></tr></table></td></tr><tr><td><pre>Returns: 0</pre></td></tr><tr><td><table><tr><td colspan="2"></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>{4, 10, 3, 6}</pre></td></tr><tr><td><pre>2</pre></td></tr><tr><td><pre>5</pre></td></tr></table></td></tr><tr><td><pre>Returns: 3</pre></td></tr><tr><td><table><tr><td colspan="2">Here the best starting coordinate is 3. Note that Taro does not jump onto his starting coordinate. If there is a rock at the coordinate where he starts, we do not count it. |
| 33 | +<p> |
| 34 | +</p> |
| 35 | +Also note that he can jump onto the rocks in any order.</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>{1, 1000000000}</pre></td></tr><tr><td><pre>0</pre></td></tr><tr><td><pre>10</pre></td></tr></table></td></tr><tr><td><pre>Returns: 1</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>{1, 47, 74, 1000000000}</pre></td></tr><tr><td><pre>0</pre></td></tr><tr><td><pre>1000000000</pre></td></tr></table></td></tr><tr><td><pre>Returns: 1</pre></td></tr><tr><td><table><tr><td colspan="2"></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> |
0 commit comments