forked from keshavnandan/Topcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStripePainter.html
28 lines (26 loc) · 4.44 KB
/
StripePainter.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<html><body bgcolor="#000000" text="#ffffff"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td><p>
Karel is a frustrated painter who works by day in an electrical repair
shop. Inspired by the color-coded bands on resistors, he is painting
a series of long, narrow canvases with bold colored stripes. However,
Karel is lazy and wants to minimize the number of brush strokes it takes
to paint each canvas.
</p>
<p>
Abbreviating each color to a single uppercase letter, Karel would
write the stripe pattern red-green-blue-green-red as <tt>"RGBGR"</tt>
(quotes added for clarity). It would take him three brush strokes to
paint this pattern.
The first stroke would cover the entire canvas in red (<tt>RRRRR</tt>).
The second stroke would leave a band of red on either side and fill
in the rest with green (<tt>RGGGR</tt>).
The final brush stroke would fill in the blue stripe in the center
(<tt>RGBGR</tt>).
</p>
<p>
Given a stripe pattern <b>stripes</b> as a string, calculate the minimum number of
brush strokes required to paint that pattern.
</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.
Suppose you tried to paint both red stripes in one stroke, followed by both green stripes
in one stroke. Then the green stroke would cover up the second red stripe. If you tried
to paint both green stripes first, followed the red stripes, then the red stroke would
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>