|
| 1 | +<html><body bgcolor="#000000" text="#ffffff"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td><p> |
| 2 | +Karel is a frustrated painter who works by day in an electrical repair |
| 3 | +shop. Inspired by the color-coded bands on resistors, he is painting |
| 4 | +a series of long, narrow canvases with bold colored stripes. However, |
| 5 | +Karel is lazy and wants to minimize the number of brush strokes it takes |
| 6 | +to paint each canvas. |
| 7 | +</p> |
| 8 | + |
| 9 | +<p> |
| 10 | +Abbreviating each color to a single uppercase letter, Karel would |
| 11 | +write the stripe pattern red-green-blue-green-red as <tt>"RGBGR"</tt> |
| 12 | +(quotes added for clarity). It would take him three brush strokes to |
| 13 | +paint this pattern. |
| 14 | +The first stroke would cover the entire canvas in red (<tt>RRRRR</tt>). |
| 15 | +The second stroke would leave a band of red on either side and fill |
| 16 | +in the rest with green (<tt>RGGGR</tt>). |
| 17 | +The final brush stroke would fill in the blue stripe in the center |
| 18 | +(<tt>RGBGR</tt>). |
| 19 | +</p> |
| 20 | + |
| 21 | +<p> |
| 22 | +Given a stripe pattern <b>stripes</b> as a string, calculate the minimum number of |
| 23 | +brush strokes required to paint that pattern. |
| 24 | +</p></td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>StripePainter</td></tr><tr><td>Method:</td><td>minStrokes</td></tr><tr><td>Parameters:</td><td>string</td></tr><tr><td>Returns:</td><td>int</td></tr><tr><td>Method signature:</td><td>int minStrokes(string stripes)</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>64</td></tr></table></td></tr><tr><td colspan="2"><h3>Notes</h3></td></tr><tr><td align="center" valign="top">-</td><td>The blank canvas is an ugly color and must not show through.</td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>stripes</b> will contain only uppercase letters ('A'-'Z', inclusive).</td></tr><tr><td align="center" valign="top">-</td><td><b>stripes</b> will contain between 1 and 50 characters, 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>"RGBGR"</pre></td></tr></table></td></tr><tr><td><pre>Returns: 3</pre></td></tr><tr><td><table><tr><td colspan="2">Example from introduction.</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>"RGRG"</pre></td></tr></table></td></tr><tr><td><pre>Returns: 3</pre></td></tr><tr><td><table><tr><td colspan="2">This example cannot be done in two strokes, even though there are only two colors. |
| 25 | +Suppose you tried to paint both red stripes in one stroke, followed by both green stripes |
| 26 | +in one stroke. Then the green stroke would cover up the second red stripe. If you tried |
| 27 | +to paint both green stripes first, followed the red stripes, then the red stroke would |
| 28 | +cover up the first green stripe.</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>"ABACADA"</pre></td></tr></table></td></tr><tr><td><pre>Returns: 4</pre></td></tr><tr><td><table><tr><td colspan="2">One long stroke in color 'A', followed by one stroke each in colors 'B', 'C', and 'D'.</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>"AABBCCDDCCBBAABBCCDD"</pre></td></tr></table></td></tr><tr><td><pre>Returns: 7</pre></td></tr><tr><td></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>"BECBBDDEEBABDCADEAAEABCACBDBEECDEDEACACCBEDABEDADD"</pre></td></tr></table></td></tr><tr><td><pre>Returns: 26</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> |
0 commit comments