forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackingBallsDiv1.html
More file actions
20 lines (20 loc) · 4.71 KB
/
Copy pathPackingBallsDiv1.html
File metadata and controls
20 lines (20 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<html><body bgcolor="#000000" text="#ffffff"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td>We have balls of <b>K</b> different colors.
The colors are numbered 0 through <b>K</b>-1, and the number of balls of color i is X[i].
We want to divide the balls into as few packages as possible.
Each package must contain between 1 and <b>K</b> balls, inclusive.
Additionally, each package must be either a "normal set" (all balls in the package have the same color), or a "variety set" (no two balls have the same color).
<br></br>
You are given the int <b>K</b>.
You are also given ints <b>A</b>, <b>B</b>, <b>C</b>, and <b>D</b>.
Use these to generate the array X using the following pseudocode:
<pre>
X[0] = A
for i = 1 to K-1:
X[i] = (X[i-1] * B + C) % D + 1
</pre>
<br></br>
Compute and return the smallest possible number of packages.</td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>PackingBallsDiv1</td></tr><tr><td>Method:</td><td>minPacks</td></tr><tr><td>Parameters:</td><td>int, int, int, int, int</td></tr><tr><td>Returns:</td><td>int</td></tr><tr><td>Method signature:</td><td>int minPacks(int K, int A, int B, int C, int D)</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>Notes</h3></td></tr><tr><td align="center" valign="top">-</td><td>You can assume that the answer will fit into a signed 32-bit integer.</td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>K</b> will be between 1 and 100,000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>B</b>, <b>C</b> and <b>D</b> will be between 1 and 1,000,000,000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>A</b> will be between 1 and <b>D</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>3</pre></td></tr><tr><td><pre>4</pre></td></tr><tr><td><pre>2</pre></td></tr><tr><td><pre>5</pre></td></tr><tr><td><pre>6</pre></td></tr></table></td></tr><tr><td><pre>Returns: 4</pre></td></tr><tr><td><table><tr><td colspan="2">There are three colors of balls.
Using the pseudocode in the problem statement, we can compute that X[0]=4, X[1]=2, and X[2]=4.
As there are 10 balls and we can only put at most 3 into each package, we need at least 4 packages.
One possible solution with 4 packages is {0,1,2}, {0,0}, {0,1}, and {2,2,2}.
(That is, the first package contains one ball of each color, the second package contains two balls of color 0, and so on.)</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</pre></td></tr><tr><td><pre>58</pre></td></tr><tr><td><pre>23</pre></td></tr><tr><td><pre>39</pre></td></tr><tr><td><pre>93</pre></td></tr></table></td></tr><tr><td><pre>Returns: 58</pre></td></tr><tr><td><table><tr><td colspan="2">All the balls have the same color, and each package can only contain one ball. Thus, the number of packages is the same as the number of balls.</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>23</pre></td></tr><tr><td><pre>10988</pre></td></tr><tr><td><pre>5573</pre></td></tr><tr><td><pre>4384</pre></td></tr><tr><td><pre>100007</pre></td></tr></table></td></tr><tr><td><pre>Returns: 47743</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>100000</pre></td></tr><tr><td><pre>123456789</pre></td></tr><tr><td><pre>234567890</pre></td></tr><tr><td><pre>345678901</pre></td></tr><tr><td><pre>1000000000</pre></td></tr></table></td></tr><tr><td><pre>Returns: 331988732</pre></td></tr><tr><td><table><tr><td colspan="2">Watch out for integer overflow when generating X.</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>