forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCut.html
More file actions
19 lines (19 loc) · 4.29 KB
/
Copy pathCut.html
File metadata and controls
19 lines (19 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<html><body bgcolor="#cccccc" text="#000000"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td>Fox Ciel wants to eat eels as a celebration of this year's end.
<p></p>
Initially, Ciel has some eels of various lengths. She only likes to eat eels of length exactly 10, no more, no less.
Before she eats, she may cut the eels to prepare pieces of desired length. However, she only has the time to make at most <b>maxCuts</b> cuts. A single cut looks as follows:
<ol>
<li>Fox Ciel chooses one of the eels. Let its length be x. She can only choose an eel of length greater than 1.</li>
<li>She chooses an integer y such that 0 < y < x.</li>
<li>She cuts the eel into two pieces so that one of them measures exactly y.
In other words, instead of one eel of length x she now has two eels of lengths y and (x-y), respectively.</li>
</ol>
<p></p>
You are given a vector <int> <b>eelLengths</b>. Each element of <b>eelLengths</b> is the length of one of the eels Ciel has at the beginning.
You are also given the int <b>maxCuts</b>.
Return the maximum number of eels of length exactly 10 she can produce.</td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>Cut</td></tr><tr><td>Method:</td><td>getMaximum</td></tr><tr><td>Parameters:</td><td>vector <int>, int</td></tr><tr><td>Returns:</td><td>int</td></tr><tr><td>Method signature:</td><td>int getMaximum(vector <int> eelLengths, int maxCuts)</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>eelLengths</b> will contain between 1 and 50 elements, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>Each element of <b>eelLengths</b> will be between 1 and 1,000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>maxCuts</b> will be between 1 and 1,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>{13, 20, 13}</pre></td></tr><tr><td><pre>2</pre></td></tr></table></td></tr><tr><td><pre>Returns: 3</pre></td></tr><tr><td><table><tr><td colspan="2">One optimal solution looks as follows:
<p></p>
First, cut eel 0 into two pieces of lengths 10 and 3. Next, cut eel 1 into two equal parts of length 10 each. This produces a total of 3 eels whose length is 10.
<p></p>
<img src="http://community.topcoder.com/contest/problem/Cut/eels0.png"></img></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>{5, 5, 5, 5}</pre></td></tr><tr><td><pre>2</pre></td></tr></table></td></tr><tr><td><pre>Returns: 0</pre></td></tr><tr><td><table><tr><td colspan="2">There are four eels whose length is 5.
As you cannot combine eels, it is impossible to make an eel of length 10.</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>{34, 10, 48}</pre></td></tr><tr><td><pre>4</pre></td></tr></table></td></tr><tr><td><pre>Returns: 5</pre></td></tr><tr><td><table><tr><td colspan="2">She already has one eel of length 10. By cutting the other two eels she can produce four more eels of the desired length.</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>{30, 50, 30, 50}</pre></td></tr><tr><td><pre>350</pre></td></tr></table></td></tr><tr><td><pre>Returns: 16</pre></td></tr><tr><td><table><tr><td colspan="2">She may cut eels at most 350 times, but in this case she doesn't have to cut them so many times.</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>