forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTheCardShufflingDivOne.html
More file actions
21 lines (21 loc) · 4.29 KB
/
Copy pathTheCardShufflingDivOne.html
File metadata and controls
21 lines (21 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<html><body bgcolor="#000000" text="#ffffff"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td><p>
John and Brus are training for a card game tournament.
John is practicing his shuffling technique.
John is using a deck of <b>n</b> cards, numbered 1 to <b>n</b> from top to bottom.
This initial deck is called the main deck.
There are three additional decks on the table, called the left, right and resulting decks.
These three decks are initially empty.
To shuffle the deck, John will repeat the following sequence of actions until the main deck contains less than two cards:
<ul>
<li>Move one card from the top of the main deck to the top of the left deck, then one card from the top of the main deck to the top of the right deck, then one card from top of the main deck to the top of the left deck, and so on, until the main deck is empty.</li>
<li>Repeat the following <b>left</b> times: Move one card from the top of the left deck to the bottom of the left deck.</li>
<li>Repeat the following <b>right</b> times: Move one card from the top of the right deck to the bottom of the right deck.</li>
<li>Move one card from the top of the left deck to the top of the resulting deck.</li>
<li>Move one card from the top of the right deck to the top of the resulting deck.</li>
<li>While the left deck is not empty, move one card from the top of the left deck to the top of the main deck.</li>
<li>While the right deck is not empty, move one card from the top of the right deck to the top of the main deck.</li>
</ul>
If there is one card left in the main deck, John will move it to the top of the resulting deck.
Return the number of the card at the top of the resulting deck after the shuffling is complete.
</p>
</td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>TheCardShufflingDivOne</td></tr><tr><td>Method:</td><td>shuffle</td></tr><tr><td>Parameters:</td><td>int, int, int</td></tr><tr><td>Returns:</td><td>int</td></tr><tr><td>Method signature:</td><td>int shuffle(int n, int left, int right)</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>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>n</b> will be between 1 and 1,000,000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>left</b> and <b>right</b> will each be between 0 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>3</pre></td></tr><tr><td><pre>0</pre></td></tr><tr><td><pre>0</pre></td></tr></table></td></tr><tr><td><pre>Returns: 1</pre></td></tr><tr><td><table><tr><td colspan="2">The resulting deck will contain cards in the same order as the main deck at the beginning.</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>3</pre></td></tr><tr><td><pre>1</pre></td></tr><tr><td><pre>1</pre></td></tr></table></td></tr><tr><td><pre>Returns: 3</pre></td></tr><tr><td><table><tr><td colspan="2">Here the order of cards in the resulting deck (from top to bottom) will be 3, 2, 1.</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>5</pre></td></tr><tr><td><pre>0</pre></td></tr><tr><td><pre>0</pre></td></tr></table></td></tr><tr><td><pre>Returns: 2</pre></td></tr><tr><td></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>17</pre></td></tr><tr><td><pre>12</pre></td></tr><tr><td><pre>21</pre></td></tr></table></td></tr><tr><td><pre>Returns: 17</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>