﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-emu in blogjava-文章分类-google编程大赛模拟题及入围赛真题</title><link>http://www.blogjava.net/emu/category/2769.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 27 Feb 2007 11:32:39 GMT</lastBuildDate><pubDate>Tue, 27 Feb 2007 11:32:39 GMT</pubDate><ttl>60</ttl><item><title>1000分模拟题CraneWork </title><link>http://www.blogjava.net/emu/articles/67748.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 05 Sep 2006 02:21:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/67748.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/67748.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/67748.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/67748.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/67748.html</trackback:ping><description><![CDATA[
		<table>
				<tbody>
						<tr>
								<td colspan="2">
										<h3>Problem Statement </h3>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>There are three stacks of crates - two of them outside of the warehouse, and one inside the warehouse. We have a crane that can move one crate at a time, and we would like to move all of the crates to the stack inside the warehouse. A heavier crate can never be stacked on top of a lighter crate, and all three initial stacks obey that rule. 
<p>Create a class CraneWork that contains a method moves that is given int[]s <b>stack1</b>, <b>stack2</b>, and <b>warehouse</b> containing the initial three stacks, and returns the minimum number of moves required to move all the crates into the warehouse stack. The elements of stack1, stack2, and warehouse represent the weights of the crates and are given from top to bottom (and thus in non-decreasing order of weight). </p></td>
						</tr>
						<tr>
								<td colspan="2">
										<h3>Definition </h3>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>
										<table>
												<tbody>
														<tr>
																<td>Class: </td>
																<td>CraneWork </td>
														</tr>
														<tr>
																<td>Method: </td>
																<td>moves </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 moves(int[] stack1, int[] stack2, int[] warehouse) </td>
														</tr>
														<tr>
																<td colspan="2">(be sure your method is public) </td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
						<tr>
								<td>     </td>
						</tr>
						<tr>
								<td>
								</td>
						</tr>
						<tr>
								<td colspan="2">
										<h3>Constraints </h3>
								</td>
						</tr>
						<tr>
								<td valign="top" align="middle">- </td>
								<td>
										<b>stack1</b>, <b>stack2</b>, and <b>warehouse</b> will each contain between 0 and 20 elements, inclusive. </td>
						</tr>
						<tr>
								<td valign="top" align="middle">- </td>
								<td>The total number of elements in the three stacks will be between 1 and 20, inclusive. </td>
						</tr>
						<tr>
								<td valign="top" align="middle">- </td>
								<td>Each element in the three stacks will be between 1 and 200, inclusive. </td>
						</tr>
						<tr>
								<td valign="top" align="middle">- </td>
								<td>
										<b>stack1</b>, <b>stack2</b>, and <b>warehouse</b> will each be in non-decreasing order. </td>
						</tr>
						<tr>
								<td colspan="2">
										<h3>Examples </h3>
								</td>
						</tr>
						<tr>
								<td nowrap="" align="middle">0) </td>
								<td>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>
										<table>
												<tbody>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td>
																										<pre>{3,50}</pre>
																								</td>
																						</tr>
																						<tr>
																								<td>
																										<pre>{}</pre>
																								</td>
																						</tr>
																						<tr>
																								<td>
																										<pre>{1,2,50,50,50}</pre>
																								</td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
														<tr>
																<td>
																		<pre>Returns: 12</pre>
																</td>
														</tr>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td colspan="2">Move 3 to stack2, 1 to stack1, 2 to stack2, 1 to stack2, 50 to warehouse, 1 to warehouse, 2 to stack1, 1 to stack1, 3 to warehouse, 1 to stack2, 2 to warehouse, 1 to warehouse. </td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
						<tr>
								<td nowrap="" align="middle">1) </td>
								<td>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>
										<table>
												<tbody>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td>
																										<pre>{50}</pre>
																								</td>
																						</tr>
																						<tr>
																								<td>
																										<pre>{50}</pre>
																								</td>
																						</tr>
																						<tr>
																								<td>
																										<pre>{10,20,30}</pre>
																								</td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
														<tr>
																<td>
																		<pre>Returns: 17</pre>
																</td>
														</tr>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td colspan="2">Start by moving 50 from stack2 to stack1. It then takes 7 moves to transfer the 10,20,30 to stack 2, 2 moves to transfer the 2 50's to the warehouse, and 7 more to transfer the 10,20,30 to the warehouse. </td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
						<tr>
								<td nowrap="" align="middle">2) </td>
								<td>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>
										<table>
												<tbody>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td>
																										<pre>{}</pre>
																								</td>
																						</tr>
																						<tr>
																								<td>
																										<pre>{}</pre>
																								</td>
																						</tr>
																						<tr>
																								<td>
																										<pre>{2,5,6,7}</pre>
																								</td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
														<tr>
																<td>
																		<pre>Returns: 0</pre>
																</td>
														</tr>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td colspan="2">All the crates are already in the warehouse. </td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
						<tr>
								<td nowrap="" align="middle">3) </td>
								<td>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>
										<table>
												<tbody>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td>
																										<pre>{1,2,3}</pre>
																								</td>
																						</tr>
																						<tr>
																								<td>
																										<pre>{}</pre>
																								</td>
																						</tr>
																						<tr>
																								<td>
																										<pre>{}</pre>
																								</td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
														<tr>
																<td>
																		<pre>Returns: 7</pre>
																</td>
														</tr>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td colspan="2">Move 1 from stack1 to warehouse, 2 from stack1 to stack2, 1 from warehouse to stack2, 3 from stack1 to warehouse, 1 from stack2 to stack1, 2 from stack2 to warehouse, 1 from stack1 to warehouse. </td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</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>
<img src ="http://www.blogjava.net/emu/aggbug/67748.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/emu/" target="_blank">emu</a> 2006-09-05 10:21 <a href="http://www.blogjava.net/emu/articles/67748.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>500分模拟题 MaximalPalindromeSubstrings</title><link>http://www.blogjava.net/emu/articles/67745.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 05 Sep 2006 02:20:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/67745.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/67745.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/67745.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/67745.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/67745.html</trackback:ping><description><![CDATA[
		<table>
				<tbody>
						<tr>
								<td colspan="2">
										<h3>Problem Statement </h3>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>
										<p>A palindrome is a string that reads the same forward and backward. A palindrome substring is a contiguous sequence of characters taken from a string that form a palindrome. A palindrome substring of a string is maximal if we can't extend it to get a bigger palindrome substring. For example, string "acdadc" has 2 maximal palindrome substrings - "a" (the first one) and "cdadc". All other palindrome substrings (like "dad" or "c") can be extended to "cdadc", so they are not maximal. </p>
										<p>You will be given a String[] <b>str</b>. Concatenate the elements of <b>str</b> to form one long string, and return the number of maximal palindrome substrings contained in that string. </p>
								</td>
						</tr>
						<tr>
								<td colspan="2">
										<h3>Definition </h3>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>
										<table>
												<tbody>
														<tr>
																<td>Class: </td>
																<td>MaximalPalindromeSubstrings </td>
														</tr>
														<tr>
																<td>Method: </td>
																<td>countMaximalPalindromeSubstrings </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 countMaximalPalindromeSubstrings(String[] str) </td>
														</tr>
														<tr>
																<td colspan="2">(be sure your method is public) </td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
						<tr>
								<td>     </td>
						</tr>
						<tr>
								<td>
								</td>
						</tr>
						<tr>
								<td colspan="2">
										<h3>Constraints </h3>
								</td>
						</tr>
						<tr>
								<td valign="top" align="middle">- </td>
								<td>
										<b>str</b> will contain between 1 and 50 elements, inclusive. </td>
						</tr>
						<tr>
								<td valign="top" align="middle">- </td>
								<td>Each element of <b>str</b> will contain between 1 and 50 characters, inclusive. </td>
						</tr>
						<tr>
								<td valign="top" align="middle">- </td>
								<td>Each character of each element of <b>str</b> will be a lowercase letter ('a'-'z'). </td>
						</tr>
						<tr>
								<td colspan="2">
										<h3>Examples </h3>
								</td>
						</tr>
						<tr>
								<td nowrap="" align="middle">0) </td>
								<td>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>
										<table>
												<tbody>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td>
																										<pre>{"acdadc"}</pre>
																								</td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
														<tr>
																<td>
																		<pre>Returns: 2</pre>
																</td>
														</tr>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td colspan="2">The example from the problem statement. </td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
						<tr>
								<td nowrap="" align="middle">1) </td>
								<td>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>
										<table>
												<tbody>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td>
																										<pre>{"ababab"}</pre>
																								</td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
														<tr>
																<td>
																		<pre>Returns: 2</pre>
																</td>
														</tr>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td colspan="2">The two maximal palindrome substrings here are "ababa" and "babab". </td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
						<tr>
								<td nowrap="" align="middle">2) </td>
								<td>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>
										<table>
												<tbody>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td>
																										<pre>{"aaaa","bbb","axxx"}</pre>
																								</td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
														<tr>
																<td>
																		<pre>Returns: 3</pre>
																</td>
														</tr>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td colspan="2">Remember to use the whole input! </td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
						<tr>
								<td nowrap="" align="middle">3) </td>
								<td>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>
										<table>
												<tbody>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td>
																										<pre>{"abacabbacaacdbdcacxcbbbbcabababacccbazhhaahh"}</pre>
																								</td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
														<tr>
																<td>
																		<pre>Returns: 14</pre>
																</td>
														</tr>
														<tr>
																<td>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</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>
<img src ="http://www.blogjava.net/emu/aggbug/67745.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/emu/" target="_blank">emu</a> 2006-09-05 10:20 <a href="http://www.blogjava.net/emu/articles/67745.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>250分模拟题 SalesRouting</title><link>http://www.blogjava.net/emu/articles/67744.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 05 Sep 2006 02:19:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/67744.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/67744.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/67744.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/67744.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/67744.html</trackback:ping><description><![CDATA[
		<table>
				<tbody>
						<tr>
								<td colspan="2">
										<h3>Problem Statement </h3>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>You want to send a group of salespeople from location 0 to location 1, but no two of them can travel through the same location (other than 0 and 1). This removes the possibility of trying to sell a customer the same product twice. Character j of element i (both 0-based) of <b>adj</b> denotes whether locations i and j are connected by a symmetric link ('1' for connected, '0' otherwise). Return the greatest number of salespeople that can be sent. The constraints will guarantee that locations 0 and 1 do not share a link. </td>
						</tr>
						<tr>
								<td colspan="2">
										<h3>Definition </h3>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>
										<table>
												<tbody>
														<tr>
																<td>Class: </td>
																<td>SalesRouting </td>
														</tr>
														<tr>
																<td>Method: </td>
																<td>howMany </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 howMany(String[] adj) </td>
														</tr>
														<tr>
																<td colspan="2">(be sure your method is public) </td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
						<tr>
								<td>     </td>
						</tr>
						<tr>
								<td>
								</td>
						</tr>
						<tr>
								<td colspan="2">
										<h3>Constraints </h3>
								</td>
						</tr>
						<tr>
								<td valign="top" align="middle">- </td>
								<td>
										<b>adj</b> will contain between 3 and 12 elements, inclusive. </td>
						</tr>
						<tr>
								<td valign="top" align="middle">- </td>
								<td>Each element of <b>adj</b> will contain exactly N characters, where N is the number of elements in <b>adj</b>. </td>
						</tr>
						<tr>
								<td valign="top" align="middle">- </td>
								<td>Each character in <b>adj</b> will be '0' (zero) or '1' (one). </td>
						</tr>
						<tr>
								<td valign="top" align="middle">- </td>
								<td>Character i of element j of <b>adj</b> will be the same as character j of element i. </td>
						</tr>
						<tr>
								<td valign="top" align="middle">- </td>
								<td>Character i of element i of <b>adj</b> will be '0'. </td>
						</tr>
						<tr>
								<td valign="top" align="middle">- </td>
								<td>Character 1 of element 0 of <b>adj</b> will be '0'. </td>
						</tr>
						<tr>
								<td colspan="2">
										<h3>Examples </h3>
								</td>
						</tr>
						<tr>
								<td nowrap="" align="middle">0) </td>
								<td>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>
										<table>
												<tbody>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td>
																										<pre>{
"001",
"001",
"110"
}</pre>
																								</td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
														<tr>
																<td>
																		<pre>Returns: 1</pre>
																</td>
														</tr>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td colspan="2">We can send a single salesperson from location 0 to location 2, and finally to location 1. </td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
						<tr>
								<td nowrap="" align="middle">1) </td>
								<td>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>
										<table>
												<tbody>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td>
																										<pre>{
"0010",
"0010",
"1100",
"0000"
}</pre>
																								</td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
														<tr>
																<td>
																		<pre>Returns: 1</pre>
																</td>
														</tr>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td colspan="2">Same as before, but now there is an isolated location 3. </td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
						<tr>
								<td nowrap="" align="middle">2) </td>
								<td>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>
										<table>
												<tbody>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td>
																										<pre>{
"001100",
"000001",
"100010",
"100010",
"001101",
"010010"
}</pre>
																								</td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
														<tr>
																<td>
																		<pre>Returns: 1</pre>
																</td>
														</tr>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td colspan="2">The only location that is directly connected to location 1 is 5, so only 1 salesperson can be sent. </td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
						<tr>
								<td nowrap="" align="middle">3) </td>
								<td>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>
										<table>
												<tbody>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td>
																										<pre>{
"001111",
"001111",
"110000",
"110000",
"110000",
"110000"
}</pre>
																								</td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
														<tr>
																<td>
																		<pre>Returns: 4</pre>
																</td>
														</tr>
														<tr>
																<td>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
						<tr>
								<td nowrap="" align="middle">4) </td>
								<td>
								</td>
						</tr>
						<tr>
								<td>     </td>
								<td>
										<table>
												<tbody>
														<tr>
																<td>
																		<table>
																				<tbody>
																						<tr>
																								<td>
																										<pre>{
"00000",
"00000",
"00000",
"00000",
"00000"
}</pre>
																								</td>
																						</tr>
																				</tbody>
																		</table>
																</td>
														</tr>
														<tr>
																<td>
																		<pre>Returns: 0</pre>
																</td>
														</tr>
														<tr>
																<td>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</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>
<img src ="http://www.blogjava.net/emu/aggbug/67744.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/emu/" target="_blank">emu</a> 2006-09-05 10:19 <a href="http://www.blogjava.net/emu/articles/67744.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SecretSum (code jam china round2 500分真题)</title><link>http://www.blogjava.net/emu/articles/25171.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Fri, 23 Dec 2005 02:28:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/25171.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/25171.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/25171.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/25171.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/25171.html</trackback:ping><description><![CDATA[<TABLE>
<TBODY>
<TR>
<TD colSpan=2>
<H3>Problem Statement </H3></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<P>We can substitute each digit of a number with a unique letter from 'A' to 'Z'. This way we can write groups of numbers in a single representation. For example "ABA" can represent any of the following: 101, 151, 343, 767, 929. However, "ABA" cannot mean 555 because each letter must stand for a distinct digit. Furthermore, numbers cannot begin with 0 and thus 'A' cannot be replaced by 0. </P>
<P>Given two such representations <B>num1</B> and <B>num2</B> and the <B>result</B> of their summation return the total number of possible combinations of numbers for which the equation holds. If no combinations are possible then return 0. </P></TD></TR>
<TR>
<TD colSpan=2>
<H3>Definition </H3></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>Class: </TD>
<TD>SecretSum </TD></TR>
<TR>
<TD>Method: </TD>
<TD>countPossible </TD></TR>
<TR>
<TD>Parameters: </TD>
<TD>String, String, String </TD></TR>
<TR>
<TD>Returns: </TD>
<TD>int </TD></TR>
<TR>
<TD>Method signature: </TD>
<TD>int countPossible(String num1, String num2, String result) </TD></TR>
<TR>
<TD colSpan=2>(be sure your method is public) </TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD></TR>
<TR>
<TD></TD></TR>
<TR>
<TD colSpan=2>
<H3>Constraints </H3></TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD><B>num1</B>, <B>num2</B>, and <B>result</B> will each contain exactly 3 uppercase letters ('A' - 'Z'). </TD></TR>
<TR>
<TD colSpan=2>
<H3>Examples </H3></TD></TR>
<TR>
<TD noWrap align=middle>0) </TD>
<TD></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><PRE>"AAA"</PRE></TD></TR>
<TR>
<TD><PRE>"BBB"</PRE></TD></TR>
<TR>
<TD><PRE>"CCC"</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: 32</PRE></TD></TR>
<TR>
<TD></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD noWrap align=middle>1) </TD>
<TD></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><PRE>"ABB"</PRE></TD></TR>
<TR>
<TD><PRE>"DEE"</PRE></TD></TR>
<TR>
<TD><PRE>"TTT"</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: 112</PRE></TD></TR>
<TR>
<TD></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD noWrap align=middle>2) </TD>
<TD></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><PRE>"ABC"</PRE></TD></TR>
<TR>
<TD><PRE>"ABA"</PRE></TD></TR>
<TR>
<TD><PRE>"ACC"</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: 0</PRE></TD></TR>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD colSpan=2>Leading zeroes are not allowed. </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD noWrap align=middle>3) </TD>
<TD></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><PRE>"AAA"</PRE></TD></TR>
<TR>
<TD><PRE>"CDD"</PRE></TD></TR>
<TR>
<TD><PRE>"BAA"</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: 32</PRE></TD></TR>
<TR>
<TD></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD noWrap align=middle>4) </TD>
<TD></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><PRE>"TEF"</PRE></TD></TR>
<TR>
<TD><PRE>"FET"</PRE></TD></TR>
<TR>
<TD><PRE>"AAA"</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: 12</PRE></TD></TR>
<TR>
<TD></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD noWrap align=middle>5) </TD>
<TD></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><PRE>"ABC"</PRE></TD></TR>
<TR>
<TD><PRE>"ABC"</PRE></TD></TR>
<TR>
<TD><PRE>"BCE"</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: 5</PRE></TD></TR>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD colSpan=2>We can have the following 5 sums: <PRE>124 + 124 = 248
125 + 125 = 250
249 + 249 = 498
374 + 374 = 748
375 + 375 = 750</PRE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD noWrap align=middle>6) </TD>
<TD></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><PRE>"AAA"</PRE></TD></TR>
<TR>
<TD><PRE>"AAA"</PRE></TD></TR>
<TR>
<TD><PRE>"BBB"</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: 4</PRE></TD></TR>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD colSpan=2>We can have the following 4 sums: <PRE>111 + 111 = 222
222 + 222 = 444
333 + 333 = 666
444 + 444 = 888</PRE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<HR>

<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><img src ="http://www.blogjava.net/emu/aggbug/25171.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/emu/" target="_blank">emu</a> 2005-12-23 10:28 <a href="http://www.blogjava.net/emu/articles/25171.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>FactorialSystem (code jam china round2 300分真题)</title><link>http://www.blogjava.net/emu/articles/25170.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Fri, 23 Dec 2005 02:26:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/25170.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/25170.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/25170.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/25170.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/25170.html</trackback:ping><description><![CDATA[<TABLE>
<TBODY>
<TR>
<TD colSpan=2>
<H3>Problem Statement </H3></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<P>In the factorial number system the value of the first digit (from the right) is 1!, the value of the second digit is 2!, ..., and the value of the n-th digit is n!. This means that any decimal number d can be written in this system as: a<SUB>n</SUB>a<SUB>n-1</SUB>...a<SUB>2</SUB>a<SUB>1</SUB>, where </P>
<P>d = a<SUB>n</SUB> * n! + a<SUB>n-1</SUB> * (n-1)! + ... + a<SUB>2</SUB> * 2! + a<SUB>1</SUB> * 1! and 0 &lt;= a<SUB>i</SUB> &lt;= i for all i. </P>
<P>Given an int <B>num</B> in decimal, return its representation in the factorial number system. </P></TD></TR>
<TR>
<TD colSpan=2>
<H3>Definition </H3></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>Class: </TD>
<TD>FactorialSystem </TD></TR>
<TR>
<TD>Method: </TD>
<TD>convert </TD></TR>
<TR>
<TD>Parameters: </TD>
<TD>int </TD></TR>
<TR>
<TD>Returns: </TD>
<TD>int </TD></TR>
<TR>
<TD>Method signature: </TD>
<TD>int convert(int num) </TD></TR>
<TR>
<TD colSpan=2>(be sure your method is public) </TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD></TR>
<TR>
<TD></TD></TR>
<TR>
<TD colSpan=2>
<H3>Notes </H3></TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD>n! = 1 * 2 * ... * n </TD></TR>
<TR>
<TD colSpan=2>
<H3>Constraints </H3></TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD><B>num</B> will be between 1 and 3628799 (10!-1), inclusive. </TD></TR>
<TR>
<TD colSpan=2>
<H3>Examples </H3></TD></TR>
<TR>
<TD noWrap align=middle>0) </TD>
<TD></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><PRE>1</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: 1</PRE></TD></TR>
<TR>
<TD></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD noWrap align=middle>1) </TD>
<TD></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><PRE>24</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: 1000</PRE></TD></TR>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD colSpan=2>24 = 4! </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD noWrap align=middle>2) </TD>
<TD></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><PRE>153</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: 11111</PRE></TD></TR>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD colSpan=2>153 = 1! + 2! + 3! + 4! + 5!. </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD noWrap align=middle>3) </TD>
<TD></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><PRE>133</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: 10201</PRE></TD></TR>
<TR>
<TD></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD noWrap align=middle>4) </TD>
<TD></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><PRE>3628799</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: 987654321</PRE></TD></TR>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD colSpan=2>Largest possible input. </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<HR>

<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><img src ="http://www.blogjava.net/emu/aggbug/25170.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/emu/" target="_blank">emu</a> 2005-12-23 10:26 <a href="http://www.blogjava.net/emu/articles/25170.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RecurringNumbers (code jam china 1000分真题)</title><link>http://www.blogjava.net/emu/articles/25151.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Fri, 23 Dec 2005 01:30:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/25151.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/25151.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/25151.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/25151.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/25151.html</trackback:ping><description><![CDATA[<TABLE>
<TBODY>
<TR>
<TD colSpan=2>
<H3>Problem Statement </H3></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<P>A rational number is defined as a/b, where a and b are integers, and b is greater than 0. Furthermore, a rational number can be written as a decimal that has a group of digits that repeat indefinitely. A common method of writing groups of repeating digits is to place them inside parentheses like 2.85(23) = 2.852323 ... 23... </P>
<P>Given a decimal representation of a rational number in <B>decimalNumber</B>, convert it to a fraction formatted as "numerator/denominator", where both numerator and denominator are integers. The fraction must be reduced. In other words, the denominator must be as small as possible, but greater than zero. </P></TD></TR>
<TR>
<TD colSpan=2>
<H3>Definition </H3></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>Class: </TD>
<TD>RecurringNumbers </TD></TR>
<TR>
<TD>Method: </TD>
<TD>convertToFraction </TD></TR>
<TR>
<TD>Parameters: </TD>
<TD>String </TD></TR>
<TR>
<TD>Returns: </TD>
<TD>String </TD></TR>
<TR>
<TD>Method signature: </TD>
<TD>String convertToFraction(String decimalNumber) </TD></TR>
<TR>
<TD colSpan=2>(be sure your method is public) </TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD></TR>
<TR>
<TD></TD></TR>
<TR>
<TD colSpan=2>
<H3>Constraints </H3></TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD><B>decimalNumber</B> will have between 3 and 10 characters inclusive. </TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD><B>decimalNumber</B> will contain only characters '0' - '9', '.', '(' and ')'. </TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD>The second character in <B>decimalNumber</B> will always be '.'. </TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD>There will be at most one '(' and ')' in <B>decimalNumber</B>. </TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD>'(' in <B>decimalNumber</B> will be followed by one or more digits ('0' - '9'), followed by ')'. </TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD>')' in <B>decimalNumber</B> will not be followed by any other character. </TD></TR>
<TR>
<TD colSpan=2>
<H3>Examples </H3></TD></TR>
<TR>
<TD noWrap align=middle>0) </TD>
<TD></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><PRE>"0.(3)"</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: "1/3"</PRE></TD></TR>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD colSpan=2>0.(3) = 0.333... = 1/3 </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD noWrap align=middle>1) </TD>
<TD></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><PRE>"1.3125"</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: "21/16"</PRE></TD></TR>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD colSpan=2>Note there are no recurring digits here, although we could write it as 1.3125(0) or 1.3124(9). </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD noWrap align=middle>2) </TD>
<TD></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><PRE>"2.85(23)"</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: "14119/4950"</PRE></TD></TR>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD colSpan=2>2.85(23) = 2.852323... = 285/100 + 23/9900 = 28238/9900 = 14119/4950. Make sure to reduce the fraction, as shown in the final step. </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD noWrap align=middle>3) </TD>
<TD></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><PRE>"9.123(456)"</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: "3038111/333000"</PRE></TD></TR>
<TR>
<TD></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD noWrap align=middle>4) </TD>
<TD></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><PRE>"0.111(1)"</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: "1/9"</PRE></TD></TR>
<TR>
<TD></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD noWrap align=middle>5) </TD>
<TD></TD></TR>
<TR>
<TD>&nbsp;&nbsp;&nbsp;&nbsp; </TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><PRE>"3.(000)"</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: "3/1"</PRE></TD></TR>
<TR>
<TD></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<HR>

<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><img src ="http://www.blogjava.net/emu/aggbug/25151.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/emu/" target="_blank">emu</a> 2005-12-23 09:30 <a href="http://www.blogjava.net/emu/articles/25151.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>google中国编程挑战赛入围赛真题 -- HardDuplicateRemover(1000分) </title><link>http://www.blogjava.net/emu/articles/24723.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 20 Dec 2005 02:29:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/24723.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/24723.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/24723.html#Feedback</comments><slash:comments>8</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/24723.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/24723.html</trackback:ping><description><![CDATA[<P>Problem Statement<BR>????<BR>We have a sequence of integers, and we would like to remove all duplicate elements from this sequence. There may be multiple ways to perform this task. For example, given the sequence { 1, 2, 1, 3 }, we could end up with either { 1, 2, 3 } or { 2, 1, 3 } as the remaining sequence, depending on which duplicate 1 we remove from the original sequence. For this problem, we want to return the lexicographically first of of all possible remaining sequences. A sequence S1 comes before sequence S2 lexicographically if and only if S1 has a smaller value than S2 at the lowest index at which the two sequences differ (so, for example, { 1, 2, 3 } comes before { 2, 3, 1 }).<BR>You will be given a int[] sequence. Return a int[] containing the sequence after all the duplicates are removed. See the examples for further clarification.<BR>Definition<BR>????<BR>Class:<BR>HardDuplicateRemover<BR>Method:<BR>process<BR>Parameters:<BR>int[]<BR>Returns:<BR>int[]<BR>Method signature:<BR>int[] process(int[] sequence)<BR>(be sure your method is public)<BR>????</P>
<P>Constraints<BR>-<BR>sequence will have between 1 and 50 elements, inclusive.<BR>-<BR>Each element of sequence will be between 1 and 1000, inclusive.<BR>Examples<BR>0)</P>
<P>????<BR>{5, 6, 5, 1, 6, 5}<BR>Returns: {1, 6, 5 }<BR>There are six different ways to remove duplicates (remaining numbers are marked by '*'): <BR>{ *5, *6,&nbsp; 5, *1,&nbsp; 6,&nbsp; 5},<BR>{ *5,&nbsp; 6,&nbsp; 5, *1, *6,&nbsp; 5},<BR>{&nbsp; 5, *6, *5, *1,&nbsp; 6,&nbsp; 5},<BR>{&nbsp; 5,&nbsp; 6, *5, *1, *6,&nbsp; 5},<BR>{&nbsp; 5, *6,&nbsp; 5, *1,&nbsp; 6, *5},<BR>{&nbsp; 5,&nbsp; 6,&nbsp; 5, *1, *6, *5}.</P>
<P>The last variant is the lexicographically first.<BR>1)</P>
<P>????<BR>{3, 2, 4, 2, 4, 4}<BR>Returns: {3, 2, 4 }</P>
<P>2)</P>
<P>????<BR>{6, 6, 6, 6, 6, 6}<BR>Returns: {6 }</P>
<P>3)</P>
<P>????<BR>{1, 3, 2, 4, 2, 3}<BR>Returns: {1, 2, 4, 3 }</P>
<P>4)</P>
<P>????<BR>{5, 4, 1, 5}<BR>Returns: {4, 1, 5 }</P>
<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><img src ="http://www.blogjava.net/emu/aggbug/24723.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/emu/" target="_blank">emu</a> 2005-12-20 10:29 <a href="http://www.blogjava.net/emu/articles/24723.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>google中国编程挑战赛入围赛真题 -- BlockStructure(500分) </title><link>http://www.blogjava.net/emu/articles/24722.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 20 Dec 2005 02:28:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/24722.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/24722.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/24722.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/24722.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/24722.html</trackback:ping><description><![CDATA[<P>Problem Statement<BR>????<BR>A group of vertical blocks are placed densely one after another on the ground. The blocks each have a width of 1, but their heights may vary. For example, if the heights of the vertical blocks are given as {1,5,5,1,6,1}, the configuration would look like the following picture:<BR><BR><BR>　　　　<FONT style="BACKGROUND-COLOR: #ff0000">×</FONT><BR>　<FONT style="BACKGROUND-COLOR: #ff0000">××</FONT>　<FONT style="BACKGROUND-COLOR: #ff0000">×</FONT><BR>　<FONT style="BACKGROUND-COLOR: #ff0000">××</FONT>　<FONT style="BACKGROUND-COLOR: #ff0000">×</FONT><BR>　<FONT style="BACKGROUND-COLOR: #ff0000">××</FONT>　<FONT style="BACKGROUND-COLOR: #ff0000">×</FONT><BR>　<FONT style="BACKGROUND-COLOR: #ff0000">××</FONT>　<FONT style="BACKGROUND-COLOR: #ff0000">×</FONT><BR><FONT style="BACKGROUND-COLOR: #ff0000">××××××<BR></FONT>&nbsp;<BR>Your task is to reproduce the exact shape of this structure using some number of non-intersecting rectangles. You will be given a int[] heights representing the heights of the vertical blocks from left to right. Return the minimal number of rectangles necessary to perform this task with the given configuration of blocks.<BR>Definition<BR>????<BR>Class:<BR>BlockStructure<BR>Method:<BR>cover<BR>Parameters:<BR>int[]<BR>Returns:<BR>int<BR>Method signature:<BR>int cover(int[] heights)<BR>(be sure your method is public)<BR>????</P>
<P>Constraints<BR>-<BR>heights will have between 1 and 50 elements, inclusive.<BR>-<BR>Each element of heights will be between 1 and 1000, inclusive.<BR>Examples<BR>0)</P>
<P>????<BR>{1,5,5,1,6,1}<BR>Returns: 3<BR>&nbsp;<BR>We can use rectangles with sizes 6x1, 2x4 and 1x5.<BR><BR>　　　　<FONT style="BACKGROUND-COLOR: #ff0000"><FONT style="BACKGROUND-COLOR: #008000">×</FONT><BR></FONT>　<FONT style="BACKGROUND-COLOR: #ff0000">××</FONT>　<FONT style="BACKGROUND-COLOR: #008000">×</FONT><BR>　<FONT style="BACKGROUND-COLOR: #ff0000">××</FONT>　<FONT style="BACKGROUND-COLOR: #008000">×</FONT><BR>　<FONT style="BACKGROUND-COLOR: #ff0000">××</FONT>　<FONT style="BACKGROUND-COLOR: #008000">×</FONT><BR>　<FONT style="BACKGROUND-COLOR: #ff0000">××</FONT>　<FONT style="BACKGROUND-COLOR: #008000">×</FONT><BR><FONT style="BACKGROUND-COLOR: #0000ff">××××××</FONT><BR><BR>1)</P>
<P>????<BR>{2,2,2,4,4}<BR>Returns: 2<BR>&nbsp;<BR>We can use a 3x2 rectangle and a 2x4 rectangle.<BR><BR><FONT style="BACKGROUND-COLOR: #ff0000"><BR><FONT style="BACKGROUND-COLOR: #ffffff">　　　<FONT style="BACKGROUND-COLOR: #008000">××<BR><FONT style="BACKGROUND-COLOR: #ffffff">　　　</FONT><FONT style="BACKGROUND-COLOR: #008000">××<BR></FONT></FONT></FONT>×××<FONT style="BACKGROUND-COLOR: #008000">××<BR></FONT><FONT style="BACKGROUND-COLOR: #008000"><FONT style="BACKGROUND-COLOR: #ff0000">×××<FONT style="BACKGROUND-COLOR: #008000">××<BR></FONT></FONT></FONT></FONT><BR><BR>2)</P>
<P>????<BR>{6,6,6,6,6,6}<BR>Returns: 1<BR>The structure is a rectangle.<BR>3)<BR><BR><FONT style="BACKGROUND-COLOR: #ff0000">××××××<BR>××××××<BR>××××××<BR>××××××<BR>××××××<BR>××××××<BR><BR><BR></FONT>????<BR>{71,44,95,16,10,80,12,17,98,61}<BR>Returns: 10<BR>It's impossible to use less than 10 rectangles.<BR>4)</P>
<P>????<BR>{100,100,97,100,100,100,97,98,99,99}<BR>Returns: 5</P>
<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><img src ="http://www.blogjava.net/emu/aggbug/24722.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/emu/" target="_blank">emu</a> 2005-12-20 10:28 <a href="http://www.blogjava.net/emu/articles/24722.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>google中国编程挑战赛入围赛真题 -- TheaterVisit(250分) </title><link>http://www.blogjava.net/emu/articles/24721.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 20 Dec 2005 02:27:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/24721.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/24721.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/24721.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/24721.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/24721.html</trackback:ping><description><![CDATA[<P>Problem Statement<BR>????<BR>You want to buy two neighboring tickets in the first row of the theater so that one of the tickets is as far from the aisles as possible.<BR>You will be given a String describing the first row of the theater where '.' represents an empty seat and 'X' represents an occupied seat. Your task is to return the index (from 0) of the empty seat that is furthest from the aisles (the two ends of the String) and is also next to an empty seat. If there are multiple possible seats, return the one with the smallest index. Return -1 if there are no seats that satisfy your requirements.<BR>Definition<BR>????<BR>Class:<BR>TheaterVisit<BR>Method:<BR>chooseSeat<BR>Parameters:<BR>String<BR>Returns:<BR>int<BR>Method signature:<BR>int chooseSeat(String row)<BR>(be sure your method is public)<BR>????</P>
<P>Constraints<BR>-<BR>row will contain between 1 and 50 characters, inclusive.<BR>-<BR>Each character in row will be either '.' or 'X'.<BR>Examples<BR>0)</P>
<P>????<BR>"....."<BR>Returns: 2<BR>You can buy either tickets with indexes 1 and 2 or tickets with indexes 2 and 3.<BR>1)</P>
<P>????<BR>"......"<BR>Returns: 2</P>
<P>2)</P>
<P>????<BR>"..X..."<BR>Returns: 3<BR>You should buy tickets with indexes 3 and 4.<BR>3)</P>
<P>????<BR>".X.X..."<BR>Returns: 4</P>
<P>4)</P>
<P>????<BR>"X.XX.X"<BR>Returns: -1</P>
<P>5)</P>
<P>????<BR>".."<BR>Returns: 0</P>
<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><img src ="http://www.blogjava.net/emu/aggbug/24721.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/emu/" target="_blank">emu</a> 2005-12-20 10:27 <a href="http://www.blogjava.net/emu/articles/24721.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>google中国编程挑战赛资格赛真题 -- SkipStones  (朋友转过来的时候顺便给翻译了)</title><link>http://www.blogjava.net/emu/articles/23647.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 13 Dec 2005 05:39:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/23647.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/23647.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/23647.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/23647.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/23647.html</trackback:ping><description><![CDATA[<P>SkipStones&nbsp; <BR>Problem Statement 问题描述</P>
<P>When a stone is thrown across water, sometimes it will land on the water and bounce rather than falling in right away. Suppose that a stone is thrown a distance of n. On each successive bounce it will travel half the distance as the previous bounce (rounded down to the nearest integer). When it can not travel any further, it falls into the water. If, at any point, the stone lands on an obstruction rather than water, it will not bounce, but will simply deflect and fall into the water. Please look at the figure for further clarification (with black, red and green cells representing banks, obstructions and free water respectively). So, if the stone is thrown a distance 7, it will bounce and travel a distance of 3, then finally a distance of 1, having travelled a total distance of 11 (the green path in the figure). If a stone is thrown a distance of 8, it will reach the opposite bank, and if thrown at distances of 2 or 6 it will hit an obstruction during its travel. These are the three red paths in the figure.</P>
<P>You are given a String water. An ‘X’ represents an obstruction, while a ‘.’<BR>represents water free from obstruction. You are to return an int representing<BR>the maximum distance a stone can travel and finally fall in the water, without<BR>hitting any obstructions, and without reaching the opposite bank (going beyond<BR>the end of the string). You may choose any initial distance for the throw,<BR>which starts from the left side of the string. A distance of 1 is the first<BR>character of the string, etc. If no initial throw will result in the stone<BR>landing in the water without hitting an obstruction, return 0.</P>
<P>给予一个 String 输入：water. 其内’X'字符代表礁石，’.’ 代表无礁石水面。你的程序<BR>返回一个整数int，表示该石头在最终落入水中的情况下运行的总最大距离，触礁、撞岸的<BR>情形都必须排除。其中撞岸表征为 (字符串访问越上界). 你可以选择任何初始的投掷距离<BR>，出发点为字符串最左侧。距离为1则抵达字符串的第一个字符，依此类推。如果没有投掷<BR>距离，石头被当作直接入水，返回量为0。</P>
<P>定义：</P>
<P>Class:<BR>SkipStones<BR>Method:<BR>maxDistance<BR>Parameters:<BR>String<BR>Returns:<BR>int<BR>Method signature:<BR>int maxDistance(String water)<BR>(确保你的函数为公共类型 public)</P>
<P>注：<BR>礁石处在水面，所以不存在石头入水后撞礁的情形。</P>
<P>限制条件：-<BR>water 字符串包含1到50个元素[即礁石或水面]，1、50包含在内。<BR>water的每个元素包含1到50个字符, 1、50包含在内。<BR>water的每个元素的每个字符要么是’X'，要么是 ‘.’.</P>
<P>测试例子</P>
<P>0)</P>
<P>“..X…..X…”<BR>返回: 11<BR>该例正如题目中（绿色轨迹）所图示。</P>
<P>1)</P>
<P>“…X…”<BR>返回: 3<BR>假如没有该礁石,可以扔一距离4,从而总距离为7。但在有礁石情形下，最佳则是扔出距离2</P>
<P>，再跳1而停止。</P>
<P>2)</P>
<P>“….X….X…XXXX.X…..”<BR>返回: 22<BR>12 + 6 + 3 + 1 = 22, 为最佳结果.</P>
<P>3)</P>
<P>“XXXXXXX.XXX.X..”<BR>返回: 15 <BR></P><img src ="http://www.blogjava.net/emu/aggbug/23647.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/emu/" target="_blank">emu</a> 2005-12-13 13:39 <a href="http://www.blogjava.net/emu/articles/23647.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>google中国编程挑战赛资格赛真题 -- ReverseSubstring  </title><link>http://www.blogjava.net/emu/articles/23646.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 13 Dec 2005 05:35:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/23646.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/23646.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/23646.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/23646.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/23646.html</trackback:ping><description><![CDATA[<TABLE cellSpacing=0 cellPadding=0 width=447 border=0>
<TBODY>
<TR>
<TD colSpan=2 height=29><STRONG>ReverseSubstring</STRONG> </TD></TR>
<TR>
<TD style="WORD-BREAK: break-all" colSpan=2>You&nbsp;are&nbsp;given&nbsp;a&nbsp;String&nbsp;input.&nbsp;You&nbsp;are&nbsp;to&nbsp;find&nbsp;the&nbsp;longest&nbsp;substring&nbsp;of&nbsp;<BR>input&nbsp;such&nbsp;that&nbsp;the&nbsp;reversal&nbsp;of&nbsp;the&nbsp;substring&nbsp;is&nbsp;also&nbsp;a&nbsp;substring&nbsp;of&nbsp;<BR>input.&nbsp;In&nbsp;case&nbsp;of&nbsp;a&nbsp;tie,&nbsp;return&nbsp;the&nbsp;string&nbsp;that&nbsp;occurs&nbsp;earliest&nbsp;in&nbsp;<BR>input.&nbsp;<BR>Definition&nbsp;<BR>给你一个字符串，你再生成一个颠倒的字符串，从原串中找出任意子串能同时存在颠倒的字符串中，&nbsp;<BR>求出最长子串&nbsp;<BR>Class:&nbsp;<BR>ReverseSubstring&nbsp;<BR>Method:&nbsp;<BR>findReversed&nbsp;<BR>Parameters:&nbsp;<BR>String&nbsp;<BR>Returns:&nbsp;<BR>String&nbsp;<BR>Method&nbsp;signature:&nbsp;<BR>String&nbsp;findReversed(String&nbsp;input)&nbsp;<BR>(be&nbsp;sure&nbsp;your&nbsp;method&nbsp;is&nbsp;public)&nbsp;<BR>类ReverseSubstring方法&nbsp;&nbsp;public&nbsp;String&nbsp;findReversed(String&nbsp;input)&nbsp;<BR><BR><BR>Notes&nbsp;<BR>-&nbsp;<BR>The&nbsp;substring&nbsp;and&nbsp;its&nbsp;reversal&nbsp;may&nbsp;overlap&nbsp;partially&nbsp;or&nbsp;completely.&nbsp;<BR>-&nbsp;<BR>The&nbsp;entire&nbsp;original&nbsp;string&nbsp;is&nbsp;itself&nbsp;a&nbsp;valid&nbsp;substring&nbsp;(see&nbsp;example&nbsp;4).&nbsp;<BR>Constraints&nbsp;<BR>-&nbsp;<BR>input&nbsp;will&nbsp;contain&nbsp;between&nbsp;1&nbsp;and&nbsp;50&nbsp;characters,&nbsp;inclusive.&nbsp;<BR>-&nbsp;<BR>Each&nbsp;character&nbsp;of&nbsp;input&nbsp;will&nbsp;be&nbsp;an&nbsp;uppercase&nbsp;letter&nbsp;('A'-'Z').&nbsp;<BR>Examples&nbsp;<BR>0)&nbsp;<BR><BR><BR>"XBCDEFYWFEDCBZ"&nbsp;<BR>Returns:&nbsp;"BCDEF"&nbsp;<BR>We&nbsp;see&nbsp;that&nbsp;the&nbsp;reverse&nbsp;of&nbsp;BCDEF&nbsp;is&nbsp;FEDCB,&nbsp;which&nbsp;appears&nbsp;later&nbsp;in&nbsp;the&nbsp;<BR>string.&nbsp;<BR>颠倒的字符串为"ZBCDEFWYFEDCBX"，原串中BCDEF也是颠倒的字符串的子串，并且为最长的&nbsp;<BR>1)&nbsp;<BR><BR><BR>"XYZ"&nbsp;<BR>Returns:&nbsp;"X"&nbsp;<BR>The&nbsp;best&nbsp;we&nbsp;can&nbsp;do&nbsp;is&nbsp;find&nbsp;a&nbsp;one&nbsp;character&nbsp;substring,&nbsp;so&nbsp;we&nbsp;implement&nbsp;<BR>the&nbsp;tie-breaker&nbsp;rule&nbsp;of&nbsp;taking&nbsp;the&nbsp;earliest&nbsp;one&nbsp;first.&nbsp;<BR>2)&nbsp;<BR><BR><BR>"ABCABA"&nbsp;<BR>Returns:&nbsp;"ABA"&nbsp;<BR>The&nbsp;string&nbsp;ABA&nbsp;is&nbsp;a&nbsp;palindrome&nbsp;(it's&nbsp;its&nbsp;own&nbsp;reversal),&nbsp;so&nbsp;it&nbsp;meets&nbsp;the&nbsp;<BR>criteria.&nbsp;<BR>3)&nbsp;<BR><BR><BR>"FDASJKUREKJFDFASIREYUFDHSAJYIREWQ"&nbsp;<BR>Returns:&nbsp;"FDF"&nbsp;<BR><BR><BR>4)&nbsp;<BR><BR><BR>"ABCDCBA"&nbsp;<BR>Returns:&nbsp;"ABCDCBA"&nbsp;<BR>Here,&nbsp;the&nbsp;entire&nbsp;string&nbsp;is&nbsp;its&nbsp;own&nbsp;reversal.&nbsp;<BR>This&nbsp;problem&nbsp;statement&nbsp;is&nbsp;the&nbsp;exclusive&nbsp;and&nbsp;proprietary&nbsp;property&nbsp;of&nbsp;<BR>TopCoder,&nbsp;Inc.&nbsp;Any&nbsp;unauthorized&nbsp;use&nbsp;or&nbsp;reproduction&nbsp;of&nbsp;this&nbsp;information&nbsp;<BR>without&nbsp;the&nbsp;prior&nbsp;written&nbsp;consent&nbsp;of&nbsp;TopCoder,&nbsp;Inc.&nbsp;is&nbsp;strictly&nbsp;<BR>prohibited.&nbsp;(c)2003,&nbsp;TopCoder,&nbsp;Inc.&nbsp;All&nbsp;rights&nbsp;reserved.</TD></TR></TBODY></TABLE><img src ="http://www.blogjava.net/emu/aggbug/23646.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/emu/" target="_blank">emu</a> 2005-12-13 13:35 <a href="http://www.blogjava.net/emu/articles/23646.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>google中国编程挑战赛资格赛真题 -- PlayCards </title><link>http://www.blogjava.net/emu/articles/23645.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 13 Dec 2005 05:34:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/23645.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/23645.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/23645.html#Feedback</comments><slash:comments>15</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/23645.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/23645.html</trackback:ping><description><![CDATA[<TABLE cellSpacing=0 cellPadding=0 width=447 border=0>
<TBODY>
<TR>
<TD colSpan=2 height=29><STRONG>PlayCards</STRONG> </TD></TR>
<TR>
<TD style="WORD-BREAK: break-all" colSpan=2>Problem&nbsp;Statement<BR><BR>You&nbsp;are&nbsp;playing&nbsp;a&nbsp;card&nbsp;game,&nbsp;and&nbsp;in&nbsp;your&nbsp;hand,&nbsp;you&nbsp;are&nbsp;holding&nbsp;several&nbsp;cards.&nbsp;Each&nbsp;card&nbsp;has&nbsp;a&nbsp;suit,<BR>'S',&nbsp;'H',&nbsp;'D',&nbsp;or&nbsp;'C',and&nbsp;a&nbsp;value&nbsp;between&nbsp;1&nbsp;and&nbsp;10,&nbsp;inclusive.&nbsp;You&nbsp;may&nbsp;play&nbsp;cards&nbsp;as&nbsp;part&nbsp;of&nbsp;a&nbsp;set,<BR>which&nbsp;is&nbsp;three&nbsp;or&nbsp;more&nbsp;cards&nbsp;of&nbsp;the&nbsp;same&nbsp;value,or&nbsp;as&nbsp;part&nbsp;of&nbsp;a&nbsp;run,&nbsp;which&nbsp;is&nbsp;three&nbsp;or&nbsp;more&nbsp;cards&nbsp;<BR>of&nbsp;the&nbsp;same&nbsp;suit,&nbsp;in&nbsp;sequential&nbsp;order.&nbsp;(Runs&nbsp;may&nbsp;not&nbsp;wrap,&nbsp;thus,&nbsp;9-10-1&nbsp;is&nbsp;not&nbsp;a&nbsp;valid&nbsp;run.)&nbsp;Each&nbsp;<BR>card&nbsp;may&nbsp;be&nbsp;played&nbsp;only&nbsp;once.For&nbsp;example,&nbsp;"1&nbsp;S",&nbsp;"1&nbsp;H"&nbsp;and&nbsp;"1&nbsp;D"&nbsp;would&nbsp;be&nbsp;a&nbsp;valid&nbsp;set.&nbsp;"2&nbsp;S",&nbsp;"3&nbsp;S",<BR>and&nbsp;"4&nbsp;S"&nbsp;would&nbsp;be&nbsp;a&nbsp;valid&nbsp;run.You&nbsp;want&nbsp;to&nbsp;play&nbsp;as&nbsp;many&nbsp;cards&nbsp;as&nbsp;possible,&nbsp;maybe&nbsp;in&nbsp;several&nbsp;plays&nbsp;<BR>(see&nbsp;example&nbsp;4).&nbsp;Given&nbsp;a&nbsp;String[]&nbsp;cards&nbsp;representing&nbsp;the&nbsp;cards&nbsp;held&nbsp;in&nbsp;your&nbsp;hand,&nbsp;you&nbsp;are&nbsp;to&nbsp;return&nbsp;<BR>an&nbsp;int&nbsp;indicating&nbsp;the&nbsp;maximum&nbsp;number&nbsp;of&nbsp;cards&nbsp;you&nbsp;can&nbsp;play.&nbsp;Each&nbsp;card&nbsp;will&nbsp;be&nbsp;given&nbsp;in&nbsp;the&nbsp;form&nbsp;<BR>"value&nbsp;suit"&nbsp;(quotes&nbsp;added&nbsp;for&nbsp;clarity).<BR><BR>Definition<BR><BR>Class:<BR>PlayCards<BR>Method:<BR>maxCards<BR>Parameters:<BR>String[]<BR>Returns:<BR>int<BR>Method&nbsp;signature:<BR>int&nbsp;maxCards(String[]&nbsp;cards)<BR>(be&nbsp;sure&nbsp;your&nbsp;method&nbsp;is&nbsp;public)<BR><BR><BR>Constraints<BR>-<BR>cards&nbsp;will&nbsp;contain&nbsp;between&nbsp;0&nbsp;and&nbsp;20&nbsp;elements,&nbsp;inclusive.<BR>-<BR>No&nbsp;two&nbsp;elements&nbsp;of&nbsp;cards&nbsp;will&nbsp;be&nbsp;the&nbsp;same.<BR>-<BR>Each&nbsp;element&nbsp;of&nbsp;cards&nbsp;will&nbsp;be&nbsp;of&nbsp;the&nbsp;form&nbsp;"value&nbsp;suit"&nbsp;(quotes&nbsp;added&nbsp;for&nbsp;clarity).<BR>-<BR>Each&nbsp;number&nbsp;represented&nbsp;will&nbsp;be&nbsp;between&nbsp;1&nbsp;and&nbsp;10,&nbsp;inclusive,&nbsp;with&nbsp;no&nbsp;leading&nbsp;zeroes.<BR>-<BR>Each&nbsp;suit&nbsp;represented&nbsp;will&nbsp;be&nbsp;'S',&nbsp;'H',&nbsp;'D',&nbsp;or&nbsp;'C'.<BR>Examples<BR>0)<BR><BR><BR>{"1&nbsp;S",&nbsp;"2&nbsp;S",&nbsp;"3&nbsp;S"}<BR>Returns:&nbsp;3<BR>We&nbsp;have&nbsp;a&nbsp;run&nbsp;of&nbsp;three&nbsp;cards,&nbsp;which&nbsp;we&nbsp;can&nbsp;play.<BR>1)<BR><BR><BR>{"4&nbsp;C",&nbsp;"4&nbsp;D",&nbsp;"4&nbsp;S",&nbsp;"3&nbsp;S",&nbsp;"2&nbsp;S"}<BR>Returns:&nbsp;3<BR>We&nbsp;can&nbsp;take&nbsp;the&nbsp;4's&nbsp;as&nbsp;a&nbsp;set,&nbsp;or&nbsp;we&nbsp;can&nbsp;take&nbsp;the&nbsp;2-3-4&nbsp;run.&nbsp;Either&nbsp;way,&nbsp;we&nbsp;play&nbsp;3&nbsp;cards.<BR>2)<BR><BR><BR>{"1&nbsp;S",&nbsp;"2&nbsp;S",&nbsp;"2&nbsp;H",&nbsp;"3&nbsp;H",&nbsp;"3&nbsp;D",&nbsp;"4&nbsp;D",&nbsp;"4&nbsp;C",&nbsp;"5&nbsp;C",&nbsp;"5&nbsp;S"}<BR>Returns:&nbsp;0<BR>We've&nbsp;got&nbsp;lots&nbsp;of&nbsp;cards,&nbsp;but&nbsp;no&nbsp;way&nbsp;to&nbsp;put&nbsp;three&nbsp;together.<BR>3)<BR><BR><BR>{"1&nbsp;S",&nbsp;"2&nbsp;S"}<BR>Returns:&nbsp;0<BR>Since&nbsp;we&nbsp;have&nbsp;to&nbsp;play&nbsp;at&nbsp;least&nbsp;three&nbsp;cards&nbsp;at&nbsp;a&nbsp;time,&nbsp;there's&nbsp;nothing&nbsp;to&nbsp;do&nbsp;here.<BR>4)<BR><BR><BR>{"1&nbsp;S",&nbsp;"2&nbsp;S",&nbsp;"10&nbsp;S",&nbsp;"5&nbsp;S",&nbsp;"8&nbsp;S",<BR>&nbsp;"3&nbsp;H",&nbsp;"9&nbsp;H",&nbsp;"6&nbsp;H",&nbsp;"5&nbsp;H",&nbsp;"4&nbsp;H",<BR>&nbsp;"10&nbsp;D",&nbsp;"5&nbsp;D",&nbsp;"7&nbsp;D",&nbsp;"4&nbsp;D",&nbsp;"1&nbsp;D",<BR>&nbsp;"2&nbsp;C",&nbsp;"4&nbsp;C",&nbsp;"5&nbsp;C",&nbsp;"6&nbsp;C",&nbsp;"7&nbsp;C"}<BR>Returns:&nbsp;9<BR>The&nbsp;best&nbsp;we&nbsp;can&nbsp;do&nbsp;is&nbsp;to&nbsp;take&nbsp;the&nbsp;set&nbsp;of&nbsp;4s,&nbsp;the&nbsp;5-6-7&nbsp;C,&nbsp;and&nbsp;the&nbsp;remaining&nbsp;three&nbsp;5s.&nbsp;We&nbsp;could&nbsp;have&nbsp;taken<BR>the&nbsp;4-5-6-7&nbsp;of&nbsp;C,or&nbsp;all&nbsp;four&nbsp;5s,&nbsp;but&nbsp;we&nbsp;would&nbsp;not&nbsp;end&nbsp;up&nbsp;playing&nbsp;as&nbsp;many&nbsp;cards.</TD></TR></TBODY></TABLE><img src ="http://www.blogjava.net/emu/aggbug/23645.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/emu/" target="_blank">emu</a> 2005-12-13 13:34 <a href="http://www.blogjava.net/emu/articles/23645.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>google中国编程挑战赛资格赛真题 -- DiskClusters</title><link>http://www.blogjava.net/emu/articles/23644.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 13 Dec 2005 05:33:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/23644.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/23644.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/23644.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/23644.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/23644.html</trackback:ping><description><![CDATA[<TABLE cellSpacing=0 cellPadding=0 width=447 border=0>
<TBODY>
<TR>
<TD colSpan=2 height=29><STRONG>DiskClusters</STRONG> </TD></TR>
<TR>
<TD style="WORD-BREAK: break-all" colSpan=2>Problem&nbsp;Statement<BR><BR>You&nbsp;are&nbsp;given&nbsp;a&nbsp;String&nbsp;disk&nbsp;representing&nbsp;the&nbsp;clusters&nbsp;on&nbsp;a&nbsp;disk.&nbsp;An&nbsp;'X'&nbsp;represents&nbsp;a&nbsp;used&nbsp;cluster,<BR>and&nbsp;a&nbsp;'.'&nbsp;represents&nbsp;an&nbsp;available&nbsp;cluster.&nbsp;You&nbsp;are&nbsp;also&nbsp;given&nbsp;an&nbsp;int&nbsp;size&nbsp;representing&nbsp;the&nbsp;size,&nbsp;<BR>in&nbsp;clusters,&nbsp;of&nbsp;a&nbsp;file&nbsp;waiting&nbsp;to&nbsp;be&nbsp;written&nbsp;to&nbsp;disk.&nbsp;A&nbsp;file&nbsp;can&nbsp;only&nbsp;be&nbsp;stored&nbsp;in&nbsp;clusters&nbsp;not&nbsp;already&nbsp;being&nbsp;used.<BR>Return&nbsp;the&nbsp;minimum&nbsp;number&nbsp;of&nbsp;groups&nbsp;of&nbsp;consecutive&nbsp;clusters&nbsp;needed&nbsp;to&nbsp;store&nbsp;the&nbsp;file&nbsp;on&nbsp;the&nbsp;disk.<BR>(The&nbsp;disk&nbsp;does&nbsp;not&nbsp;wrap&nbsp;around&nbsp;at&nbsp;the&nbsp;end.)&nbsp;Return&nbsp;-1&nbsp;if&nbsp;the&nbsp;disk&nbsp;does&nbsp;not&nbsp;have&nbsp;enough&nbsp;space&nbsp;available<BR>to&nbsp;store&nbsp;the&nbsp;file.<BR>Definition<BR><BR>Class:<BR>DiskClusters<BR>Method:<BR>minimumFragmentation<BR>Parameters:<BR>String,&nbsp;int<BR>Returns:<BR>int<BR>Method&nbsp;signature:<BR>int&nbsp;minimumFragmentation(String&nbsp;disk,&nbsp;int&nbsp;size)<BR>(be&nbsp;sure&nbsp;your&nbsp;method&nbsp;is&nbsp;public)<BR><BR><BR>Constraints<BR>-<BR>disk&nbsp;will&nbsp;contain&nbsp;between&nbsp;1&nbsp;and&nbsp;50&nbsp;characters,&nbsp;inclusive.<BR>-<BR>Each&nbsp;character&nbsp;of&nbsp;disk&nbsp;will&nbsp;be&nbsp;'X'&nbsp;or&nbsp;'.'.<BR>-<BR>size&nbsp;will&nbsp;be&nbsp;between&nbsp;1&nbsp;and&nbsp;50,&nbsp;inclusive.<BR>Examples<BR>0)<BR><BR><BR>"."<BR>2<BR>Returns:&nbsp;-1<BR>We&nbsp;can't&nbsp;fit&nbsp;the&nbsp;file&nbsp;on&nbsp;the&nbsp;disk.<BR>1)<BR><BR><BR>".XXXXXXXX.XXXXXX.XX.X.X."<BR>6<BR>Returns:&nbsp;6<BR>There&nbsp;is&nbsp;only&nbsp;ever&nbsp;one&nbsp;cluster&nbsp;together,&nbsp;so&nbsp;all&nbsp;six&nbsp;clusters&nbsp;are&nbsp;separated.<BR>2)<BR><BR><BR>"XX..XX....X.XX........X...X.XX...XXXX..XX...XXXXX."<BR>12<BR>Returns:&nbsp;2<BR>We&nbsp;fit&nbsp;eight&nbsp;clusters&nbsp;together,&nbsp;and&nbsp;four&nbsp;clusters&nbsp;together.<BR>3)<BR><BR><BR>".X.XXXX.......XX....X.....X............XX.X.....X."<BR>20<BR>Returns:&nbsp;3<BR><BR>4)<BR><BR><BR>"....X...X..X"<BR>11<BR>Returns:&nbsp;-1<BR><BR>This&nbsp;problem&nbsp;statement&nbsp;is&nbsp;the&nbsp;exclusive&nbsp;and&nbsp;proprietary&nbsp;property&nbsp;of&nbsp;TopCoder,&nbsp;Inc.&nbsp;<BR>Any&nbsp;unauthorized&nbsp;use&nbsp;or&nbsp;reproduction&nbsp;of&nbsp;this&nbsp;information&nbsp;without&nbsp;the&nbsp;prior&nbsp;written<BR>consent&nbsp;of&nbsp;TopCoder,&nbsp;Inc.&nbsp;is&nbsp;strictly&nbsp;prohibited.&nbsp;(c)2003,&nbsp;TopCoder,&nbsp;Inc.&nbsp;All&nbsp;rights&nbsp;reserved.</TD></TR></TBODY></TABLE><img src ="http://www.blogjava.net/emu/aggbug/23644.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/emu/" target="_blank">emu</a> 2005-12-13 13:33 <a href="http://www.blogjava.net/emu/articles/23644.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>google中国编程挑战赛资格赛真题 -- WordPath（750分） </title><link>http://www.blogjava.net/emu/articles/23623.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 13 Dec 2005 04:00:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/23623.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/23623.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/23623.html#Feedback</comments><slash:comments>19</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/23623.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/23623.html</trackback:ping><description><![CDATA[<P>考试刚刚结束，题目帖出来交流一下。<BR>Problem Statement<BR>????<BR>You are given a String[] grid representing a rectangular grid of letters. You are also given a String find, a word you are to find within the grid. The starting point may be anywhere in the grid. The path may move up, down, left, right, or diagonally from one letter to the next, and may use letters in the grid more than once, but you may not stay on the same cell twice in a row (see example 6 for clarification).<BR>You are to return an int indicating the number of ways find can be found within the grid. If the result is more than 1,000,000,000, return -1.<BR>Definition<BR>????<BR>Class:<BR>WordPath<BR>Method:<BR>countPaths<BR>Parameters:<BR>String[], String<BR>Returns:<BR>int<BR>Method signature:<BR>int countPaths(String[] grid, String find)<BR>(be sure your method is public)<BR>????</P>
<P>Constraints<BR>-<BR>grid will contain between 1 and 50 elements, inclusive.<BR>-<BR>Each element of grid will contain between 1 and 50 uppercase ('A'-'Z') letters, inclusive.<BR>-<BR>Each element of grid will contain the same number of characters.<BR>-<BR>find will contain between 1 and 50 uppercase ('A'-'Z') letters, inclusive.<BR>Examples<BR>0)</P>
<P>????<BR>{"ABC",<BR>&nbsp;"FED",<BR>&nbsp;"GHI"}<BR>"ABCDEFGHI"<BR>Returns: 1<BR>There is only one way to trace this path. Each letter is used exactly once.<BR>1)</P>
<P>????<BR>{"ABC",<BR>&nbsp;"FED",<BR>&nbsp;"GAI"}<BR>"ABCDEA"<BR>Returns: 2<BR>Once we get to the 'E', we can choose one of two directions for the final 'A'.<BR>2)</P>
<P>????<BR>{"ABC",<BR>&nbsp;"DEF",<BR>&nbsp;"GHI"}<BR>"ABCD"<BR>Returns: 0<BR>We can trace a path for "ABC", but there's no way to complete a path to the letter 'D'.<BR>3)</P>
<P>????<BR>{"AA",<BR>&nbsp;"AA"}<BR>"AAAA"<BR>Returns: 108<BR>We can start from any of the four locations. From each location, we can then move in any of the three possible directions for our second letter, and again for the third and fourth letter. 4 * 3 * 3 * 3 = 108.<BR>4)</P>
<P>????<BR>{"ABABA",<BR>&nbsp;"BABAB",<BR>&nbsp;"ABABA",<BR>&nbsp;"BABAB",<BR>&nbsp;"ABABA"}<BR>"ABABABBA"<BR>Returns: 56448<BR>There are a lot of ways to trace this path.<BR>5)</P>
<P>????<BR>{"AAAAA",<BR>&nbsp;"AAAAA",<BR>&nbsp;"AAAAA",<BR>&nbsp;"AAAAA",<BR>&nbsp;"AAAAA"}<BR>"AAAAAAAAAAA"<BR>Returns: -1<BR>There are well over 1,000,000,000 paths that can be traced.<BR>6)</P>
<P>????<BR>{"AB",<BR>&nbsp;"CD"}<BR>"AA"<BR>Returns: 0<BR>Since we can't stay on the same cell, we can't trace the path at all.<BR>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><img src ="http://www.blogjava.net/emu/aggbug/23623.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/emu/" target="_blank">emu</a> 2005-12-13 12:00 <a href="http://www.blogjava.net/emu/articles/23623.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>google中国编程挑战赛资格赛真题 -- BusStops（250分） </title><link>http://www.blogjava.net/emu/articles/23624.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 13 Dec 2005 04:00:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/23624.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/23624.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/23624.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/23624.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/23624.html</trackback:ping><description><![CDATA[<P>考试刚刚结束，题目帖出来交流一下。<BR>Problem Statement<BR>????<BR>You are given a String[] cityMap representing the layout of a city. The city consists of blocks. The first element of cityMap represents the first row of blocks, etc. A 'B' character indicates a location where there is a bus stop. There will be exactly one 'X' character, indicating your location. All other characters will be '.'. You are also given an int walkingDistance, which is the maximum distance you are willing to walk to a bus stop. The distance should be calculated as the number of blocks vertically plus the number of blocks horizontally. Return the number of bus stops that are within walking distance of your current location.<BR>Definition<BR>????<BR>Class:<BR>BusStops<BR>Method:<BR>countStops<BR>Parameters:<BR>String[], int<BR>Returns:<BR>int<BR>Method signature:<BR>int countStops(String[] cityMap, int walkingDistance)<BR>(be sure your method is public)<BR>????</P>
<P>Constraints<BR>-<BR>cityMap will contain between 1 and 50 elements, inclusive.<BR>-<BR>Each element of cityMap will contain between 1 and 50 characters, inclusive.<BR>-<BR>Each element of cityMap will contain the same number of characters.<BR>-<BR>Each character of each element of cityMap will be 'B', 'X', or '.'.<BR>-<BR>There will be exactly one 'X' character in cityMap.<BR>-<BR>walkingDistance will be between 1 and 100, inclusive.<BR>Examples<BR>0)</P>
<P>????<BR>{"...B.",<BR>&nbsp;".....",<BR>&nbsp;"..X.B",<BR>&nbsp;".....",<BR>&nbsp;"B...."}<BR>3<BR>Returns: 2<BR>You can reach the bus stop at the top (3 units away), or on the right (2 units away). The one in the lower left is 4 units away, which is too far.<BR>1)</P>
<P>????<BR>{"B.B..",<BR>&nbsp;".....",<BR>&nbsp;"B....",<BR>&nbsp;".....",<BR>&nbsp;"....X"}<BR>8<BR>Returns: 3<BR>A distance of 8 can get us anywhere on the map, so we can reach all 3 bus stops.<BR>2)</P>
<P>????<BR>{"BBBBB",<BR>&nbsp;"BB.BB",<BR>&nbsp;"B.X.B",<BR>&nbsp;"BB.BB",<BR>&nbsp;"BBBBB"}<BR>1<BR>Returns: 0<BR>Plenty of bus stops, but unfortunately we cannot reach any of them.<BR>3)</P>
<P>????<BR>{"B..B..",<BR>&nbsp;".B...B",<BR>&nbsp;"..B...",<BR>&nbsp;"..B.X.",<BR>&nbsp;"B.B.B.",<BR>&nbsp;".B.B.B"}<BR>3<BR>Returns: 7</P>
<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><img src ="http://www.blogjava.net/emu/aggbug/23624.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/emu/" target="_blank">emu</a> 2005-12-13 12:00 <a href="http://www.blogjava.net/emu/articles/23624.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>google中国编程挑战赛资格赛真题 -- FillBaskets（250分） </title><link>http://www.blogjava.net/emu/articles/23625.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 13 Dec 2005 04:00:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/23625.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/23625.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/23625.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/23625.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/23625.html</trackback:ping><description><![CDATA[<P>考试刚刚结束，题目帖出来交流一下。<BR>Problem Statement<BR>????<BR>You have several identical balls that you wish to place in several baskets. Each basket has the same maximum capacity. You are given an int baskets, the number of baskets you have. You are given an int capacity, the maximum capacity of each basket. Finally you are given an int balls, the number of balls to sort into baskets. Return the number of ways you can divide the balls into baskets. If this cannot be done without exceeding the capacity of the baskets, return 0.<BR>Each basket is distinct, but all balls are identical. Thus, if you have two balls to place into two baskets, you could have (0, 2), (1, 1), or (2, 0), so there would be three ways to do this.<BR>Definition<BR>????<BR>Class:<BR>FillBaskets<BR>Method:<BR>countWays<BR>Parameters:<BR>int, int, int<BR>Returns:<BR>int<BR>Method signature:<BR>int countWays(int baskets, int capacity, int balls)<BR>(be sure your method is public)<BR>????</P>
<P>Constraints<BR>-<BR>baskets will be between 1 and 5, inclusive.<BR>-<BR>capacity will be between 1 and 20, inclusive.<BR>-<BR>balls will be between 1 and 100, inclusive.<BR>Examples<BR>0)</P>
<P>????<BR>2<BR>20<BR>2<BR>Returns: 3<BR>The example from the problem statement.<BR>1)</P>
<P>????<BR>3<BR>20<BR>1<BR>Returns: 3<BR>We have only 1 ball, so we must choose which of the three baskets to place it in.<BR>2)</P>
<P>????<BR>3<BR>20<BR>2<BR>Returns: 6<BR>We can place both balls in the same basket (3 ways to do this), or one ball in each of two baskets (3 ways to do this).<BR>3)</P>
<P>????<BR>1<BR>5<BR>10<BR>Returns: 0<BR>We have more balls than our basket can hold.<BR>4)</P>
<P>????<BR>4<BR>5<BR>10<BR>Returns: 146</P>
<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><img src ="http://www.blogjava.net/emu/aggbug/23625.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/emu/" target="_blank">emu</a> 2005-12-13 12:00 <a href="http://www.blogjava.net/emu/articles/23625.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>google中国编程挑战赛模拟题 -- CursorPosition（1000分）</title><link>http://www.blogjava.net/emu/articles/22130.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Thu, 01 Dec 2005 08:57:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/22130.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/22130.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/22130.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/22130.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/22130.html</trackback:ping><description><![CDATA[<P><BR>Problem Statement<BR>????<BR>When editing a single line of text, there are four keys that can be used to move the cursor: end, home, left-arrow and right-arrow. As you would expect, left-arrow and right-arrow move the cursor one character left or one character right, unless the cursor is at the beginning of the line or the end of the line, respectively, in which case the keystrokes do nothing (the cursor does not wrap to the previous or next line). The home key moves the cursor to the beginning of the line, and the end key moves the cursor to the end of the line.&nbsp; You will be given a int, N, representing the number of character in a line of text. The cursor is always between two adjacent characters, at the beginning of the line, or at the end of the line. It starts before the first character, at position 0. The position after the last character on the line is position N. You should simulate a series of keystrokes and return the final position of the cursor. You will be given a String where characters of the String represent the keystrokes made, in order. 'L' and 'R' represent left and right, while 'H' and 'E' represent home and end.<BR>Definition<BR>????<BR>Class:<BR>CursorPosition<BR>Method:<BR>getPosition<BR>Parameters:<BR>String, int<BR>Returns:<BR>int<BR>Method signature:<BR>int getPosition(String keystrokes, int N)<BR>(be sure your method is public)<BR>????</P>
<P>Constraints<BR>-<BR>keystrokes will be contain between 1 and 50 'L', 'R', 'H', and 'E' characters, inclusive.<BR>-<BR>N will be between 1 and 100, inclusive.<BR>Examples<BR>0)</P>
<P>????<BR>"ERLLL"<BR>10<BR>Returns: 7<BR>First, we go to the end of the line at position 10. Then, the right-arrow does nothing because we are already at the end of the line. Finally, three left-arrows brings us to position 7.<BR>1)</P>
<P>????<BR>"EHHEEHLLLLRRRRRR"<BR>2<BR>Returns: 2<BR>All the right-arrows at the end ensure that we end up at the end of the line.<BR>2)</P>
<P>????<BR>"ELLLELLRRRRLRLRLLLRLLLRLLLLRLLRRRL"<BR>10<BR>Returns: 3</P>
<P>3)</P>
<P>????<BR>"RRLEERLLLLRLLRLRRRLRLRLRLRLLLLL"<BR>19<BR>Returns: 12</P>
<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.<BR><BR><BR><BR>没有难度<BR><BR></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG id=Codehighlighter1_28_876_Open_Image onclick="this.style.display='none'; Codehighlighter1_28_876_Open_Text.style.display='none'; Codehighlighter1_28_876_Closed_Image.style.display='inline'; Codehighlighter1_28_876_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_28_876_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_28_876_Closed_Text.style.display='none'; Codehighlighter1_28_876_Open_Image.style.display='inline'; Codehighlighter1_28_876_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;CursorPosition&nbsp;</SPAN><SPAN id=Codehighlighter1_28_876_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_28_876_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG id=Codehighlighter1_78_436_Open_Image onclick="this.style.display='none'; Codehighlighter1_78_436_Open_Text.style.display='none'; Codehighlighter1_78_436_Closed_Image.style.display='inline'; Codehighlighter1_78_436_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_78_436_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_78_436_Closed_Text.style.display='none'; Codehighlighter1_78_436_Open_Image.style.display='inline'; Codehighlighter1_78_436_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;getPosition(String&nbsp;keystrokes,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;N)</SPAN><SPAN id=Codehighlighter1_78_436_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_78_436_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;p&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(keystrokes.lastIndexOf(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">H</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">&gt;-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">)<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;keystrokes</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">keystrokes.substring(keystrokes.lastIndexOf(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">H</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">);<BR><IMG id=Codehighlighter1_229_305_Open_Image onclick="this.style.display='none'; Codehighlighter1_229_305_Open_Text.style.display='none'; Codehighlighter1_229_305_Closed_Image.style.display='inline'; Codehighlighter1_229_305_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_229_305_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_229_305_Closed_Text.style.display='none'; Codehighlighter1_229_305_Open_Image.style.display='inline'; Codehighlighter1_229_305_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(keystrokes.lastIndexOf(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">E</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">&gt;-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN id=Codehighlighter1_229_305_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_229_305_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;keystrokes</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">keystrokes.substring(keystrokes.lastIndexOf(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">E</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">N;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_346_423_Open_Image onclick="this.style.display='none'; Codehighlighter1_346_423_Open_Text.style.display='none'; Codehighlighter1_346_423_Closed_Image.style.display='inline'; Codehighlighter1_346_423_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_346_423_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_346_423_Closed_Text.style.display='none'; Codehighlighter1_346_423_Open_Image.style.display='inline'; Codehighlighter1_346_423_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;i</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">keystrokes.length();i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN id=Codehighlighter1_346_423_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_346_423_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(keystrokes.charAt(i)</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">R</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">)<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</SPAN><SPAN style="COLOR: #000000">+=</SPAN><SPAN style="COLOR: #000000">(p</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">N)</SPAN><SPAN style="COLOR: #000000">?</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">:</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</SPAN><SPAN style="COLOR: #000000">-=</SPAN><SPAN style="COLOR: #000000">(p</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">?</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">:</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;p;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_476_874_Open_Image onclick="this.style.display='none'; Codehighlighter1_476_874_Open_Text.style.display='none'; Codehighlighter1_476_874_Closed_Image.style.display='inline'; Codehighlighter1_476_874_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_476_874_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_476_874_Closed_Text.style.display='none'; Codehighlighter1_476_874_Open_Image.style.display='inline'; Codehighlighter1_476_874_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;main(String[]&nbsp;args)</SPAN><SPAN id=Codehighlighter1_476_874_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_476_874_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;CursorPosition().getPosition(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">ERLLL</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">10</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;CursorPosition().getPosition(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">EHHEEHLLLLRRRRRR</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;CursorPosition().getPosition(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">ELLLELLRRRRLRLRLLLRLLLRLLLLRLLRRRL</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">10</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;CursorPosition().getPosition(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">RRLEERLLLLRLLRLRRRLRLRLRLRLLLLL</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">19</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;CursorPosition().getPosition(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">R</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">9</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV><img src ="http://www.blogjava.net/emu/aggbug/22130.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/emu/" target="_blank">emu</a> 2005-12-01 16:57 <a href="http://www.blogjava.net/emu/articles/22130.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>google中国编程挑战赛模拟题 -- MatrixTool (500分)</title><link>http://www.blogjava.net/emu/articles/22125.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Thu, 01 Dec 2005 08:33:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/22125.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/22125.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/22125.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/22125.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/22125.html</trackback:ping><description><![CDATA[<P><BR>Problem Statement<BR>????<BR>A square matrix is a grid of NxN numbers. For example, the following is a 3x3 matrix:<BR>&nbsp;4 3 5<BR>&nbsp;2 4 5<BR>&nbsp;0 1 9<BR>One way to represent a matrix of numbers, each of which is between 0 and 9 inclusive, is as a row-major String. To generate the String, simply concatenate all of the elements from the first row followed by the second row and so on, without any spaces. For example, the above matrix would be represented as "435245019".&nbsp; You will be given a square matrix as a row-major String. Your task is to convert it into a String[], where each element represents one row of the original matrix. Element i of the String[] represents row i of the matrix. You should not include any spaces in your return. Hence, for the above String, you would return {"435","245","019"}. If the input does not represent a square matrix because the number of characters is not a perfect square, return an empty String[], {}.<BR>Definition<BR>????<BR>Class:<BR>MatrixTool<BR>Method:<BR>convert<BR>Parameters:<BR>String<BR>Returns:<BR>String[]<BR>Method signature:<BR>String[] convert(String s)<BR>(be sure your method is public)<BR>????</P>
<P>Constraints<BR>-<BR>s will contain between 1 and 50 digits, inclusive.<BR>Examples<BR>0)</P>
<P>????<BR>"435245019"<BR>Returns: {"435", "245", "019" }<BR>The example above.<BR>1)</P>
<P>????<BR>"9"<BR>Returns: {"9" }</P>
<P>2)</P>
<P>????<BR>"0123456789"<BR>Returns: { }<BR>This input has 10 digits, and 10 is not a perfect square.<BR>3)</P>
<P>????<BR>"3357002966366183191503444273807479559869883303524"<BR>Returns: {"3357002", "9663661", "8319150", "3444273", "8074795", "5986988", "3303524" }</P>
<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.<BR><BR><BR><BR>局搞笑的题目。这次中国锦标赛的模拟题比起上次东亚的差的太远了。解一个吧：<BR><BR></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG id=Codehighlighter1_24_674_Open_Image onclick="this.style.display='none'; Codehighlighter1_24_674_Open_Text.style.display='none'; Codehighlighter1_24_674_Closed_Image.style.display='inline'; Codehighlighter1_24_674_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_24_674_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_24_674_Closed_Text.style.display='none'; Codehighlighter1_24_674_Open_Image.style.display='inline'; Codehighlighter1_24_674_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;MatrixTool&nbsp;</SPAN><SPAN id=Codehighlighter1_24_674_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_24_674_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG id=Codehighlighter1_60_288_Open_Image onclick="this.style.display='none'; Codehighlighter1_60_288_Open_Text.style.display='none'; Codehighlighter1_60_288_Closed_Image.style.display='inline'; Codehighlighter1_60_288_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_60_288_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_60_288_Closed_Text.style.display='none'; Codehighlighter1_60_288_Open_Image.style.display='inline'; Codehighlighter1_60_288_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;String[]&nbsp;convert(String&nbsp;s)</SPAN><SPAN id=Codehighlighter1_60_288_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_60_288_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;l&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;s.length();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;sq&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Double(Math.sqrt(l)).intValue();<BR><IMG id=Codehighlighter1_165_166_Open_Image onclick="this.style.display='none'; Codehighlighter1_165_166_Open_Text.style.display='none'; Codehighlighter1_165_166_Closed_Image.style.display='inline'; Codehighlighter1_165_166_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_165_166_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_165_166_Closed_Text.style.display='none'; Codehighlighter1_165_166_Open_Image.style.display='inline'; Codehighlighter1_165_166_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(sq</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">sq</SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000">l)</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;String[]</SPAN><SPAN id=Codehighlighter1_165_166_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_165_166_Open_Text><SPAN style="COLOR: #000000">{}</SPAN></SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String[]&nbsp;result&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;String[sq];<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;i</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">sq;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result[i]</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">s.substring(i</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">sq,(i</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">sq);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;result;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_329_672_Open_Image onclick="this.style.display='none'; Codehighlighter1_329_672_Open_Text.style.display='none'; Codehighlighter1_329_672_Closed_Image.style.display='inline'; Codehighlighter1_329_672_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_329_672_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_329_672_Closed_Text.style.display='none'; Codehighlighter1_329_672_Open_Image.style.display='inline'; Codehighlighter1_329_672_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;main(String[]&nbsp;args)</SPAN><SPAN id=Codehighlighter1_329_672_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_329_672_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String[]&nbsp;s;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;MatrixTool().convert(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">435245019</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(java.util.Arrays.asList(s));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;MatrixTool().convert(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">0123456789</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(java.util.Arrays.asList(s));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;MatrixTool().convert(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">3357002966366183191503444273807479559869883303524</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(java.util.Arrays.asList(s));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV><img src ="http://www.blogjava.net/emu/aggbug/22125.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/emu/" target="_blank">emu</a> 2005-12-01 16:33 <a href="http://www.blogjava.net/emu/articles/22125.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>google中国编程挑战赛模拟题 -- DrawLines (250分)</title><link>http://www.blogjava.net/emu/articles/22085.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Thu, 01 Dec 2005 02:37:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/22085.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/22085.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/22085.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/22085.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/22085.html</trackback:ping><description><![CDATA[<P>Problem Statement<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>A simple line drawing program uses a blank 20 x 20 pixel canvas and a directional cursor that starts at the upper left corner pointing straight down. The upper left corner of the canvas is at (0, 0) and the lower right corner is at (19, 19). You are given a String[], commands, each element of which contains one of two possible commands. A command of the form "FORWARD x" means that the cursor should move forward by x pixels. Each pixel on its path, including the start and end points, is painted black. The only other command is "LEFT", which means that the cursor should change its direction by 90 degrees counterclockwise. So, if the cursor is initially pointing straight down and it receives a single "LEFT" command, it will end up pointing straight to the right. Execute all the commands in order and return the resulting 20 x 20 pixel canvas as a String[] where character j of element i represents the pixel at (i, j). Black pixels should be represented as uppercase 'X' characters and blank pixels should be represented as '.' characters.<BR>Definition<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>Class:<BR>DrawLines<BR>Method:<BR>execute<BR>Parameters:<BR>String[]<BR>Returns:<BR>String[]<BR>Method signature:<BR>String[] execute(String[] commands)<BR>(be sure your method is public)<BR>&nbsp;&nbsp;&nbsp;&nbsp;</P>
<P>Notes<BR>-<BR>The cursor only paints the canvas if it moves (see example 1).<BR>Constraints<BR>-<BR>commands will contain between 1 and 50 elements, inclusive.<BR>-<BR>Each element of commands will be formatted as either "LEFT" or "FORWARD x" (quotes for clarity only), where x is an integer between 1 and 19, inclusive, with no extra leading zeros.<BR>-<BR>When executing the commands in order, the cursor will never leave the 20 x 20 pixel canvas.<BR>Examples<BR>0)</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;<BR>{"FORWARD 19", "LEFT", "FORWARD 19", "LEFT", "FORWARD 19", "LEFT", "FORWARD 19"}<BR>Returns: <BR>{"XXXXXXXXXXXXXXXXXXXX",<BR>&nbsp;"X..................X",<BR>&nbsp;"X..................X",<BR>&nbsp;"X..................X",<BR>&nbsp;"X..................X",<BR>&nbsp;"X..................X",<BR>&nbsp;"X..................X",<BR>&nbsp;"X..................X",<BR>&nbsp;"X..................X",<BR>&nbsp;"X..................X",<BR>&nbsp;"X..................X",<BR>&nbsp;"X..................X",<BR>&nbsp;"X..................X",<BR>&nbsp;"X..................X",<BR>&nbsp;"X..................X",<BR>&nbsp;"X..................X",<BR>&nbsp;"X..................X",<BR>&nbsp;"X..................X",<BR>&nbsp;"X..................X",<BR>&nbsp;"XXXXXXXXXXXXXXXXXXXX" }<BR>This sequence of commands draws a 20 x 20 outline of a square. The cursor is initially at (0, 0) pointing straight down. It then travels to (0, 19) after the first FORWARD command, painting each pixel along its path with a '*'. It then rotates 90 degrees left, travels to (19, 19), rotates 90 degrees left, travels to (19, 0), rotates 90 degrees left, and finally travels back to (0, 0).<BR>1)</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;<BR>{"LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT"}<BR>Returns: <BR>{"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"...................." }<BR>The cursor spins round and round, but never actually paints any pixels. The result is an empty canvas.<BR>2)</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;<BR>{"FORWARD 1"}<BR>Returns: <BR>{"X...................",<BR>&nbsp;"X...................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"....................",<BR>&nbsp;"...................." }<BR>Going forward by one pixel creates a line that is 2 pixels long because both the start and end points are painted.<BR>3)</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;<BR>{"LEFT", "FORWARD 19", "LEFT", "LEFT", "LEFT",<BR>&nbsp;"FORWARD 18", "LEFT", "LEFT", "LEFT", "FORWARD 17",<BR>&nbsp;"LEFT", "LEFT", "LEFT", "FORWARD 16", "LEFT",<BR>&nbsp;"LEFT", "LEFT", "FORWARD 15", "LEFT", "LEFT", "LEFT",<BR>&nbsp;"FORWARD 14", "LEFT", "LEFT", "LEFT", "FORWARD 13",<BR>&nbsp;"LEFT", "LEFT", "LEFT", "FORWARD 12", "LEFT", "LEFT",<BR>&nbsp;"LEFT", "FORWARD 11", "LEFT", "LEFT", "LEFT", "FORWARD 10",<BR>&nbsp;"LEFT", "LEFT", "LEFT", "FORWARD 9", "LEFT", "LEFT",<BR>&nbsp;"LEFT", "FORWARD 8", "LEFT", "LEFT", "LEFT", "FORWARD 7"}<BR>Returns: <BR>{"XXXXXXXXXXXXXXXXXXXX",<BR>&nbsp;"...................X",<BR>&nbsp;"..XXXXXXXXXXXXXXXX.X",<BR>&nbsp;"..X..............X.X",<BR>&nbsp;"..X.XXXXXXXXXXXX.X.X",<BR>&nbsp;"..X.X..........X.X.X",<BR>&nbsp;"..X.X.XXXXXXXX.X.X.X",<BR>&nbsp;"..X.X.X........X.X.X",<BR>&nbsp;"..X.X.X........X.X.X",<BR>&nbsp;"..X.X.X........X.X.X",<BR>&nbsp;"..X.X.X........X.X.X",<BR>&nbsp;"..X.X.X........X.X.X",<BR>&nbsp;"..X.X.X........X.X.X",<BR>&nbsp;"..X.X.X........X.X.X",<BR>&nbsp;"..X.X.XXXXXXXXXX.X.X",<BR>&nbsp;"..X.X............X.X",<BR>&nbsp;"..X.XXXXXXXXXXXXXX.X",<BR>&nbsp;"..X................X",<BR>&nbsp;"..XXXXXXXXXXXXXXXXXX",<BR>&nbsp;"...................." }</P>
<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.<BR><BR><BR><BR>emu解答：</P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG id=Codehighlighter1_23_1728_Open_Image onclick="this.style.display='none'; Codehighlighter1_23_1728_Open_Text.style.display='none'; Codehighlighter1_23_1728_Closed_Image.style.display='inline'; Codehighlighter1_23_1728_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_23_1728_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_23_1728_Closed_Text.style.display='none'; Codehighlighter1_23_1728_Open_Image.style.display='inline'; Codehighlighter1_23_1728_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;DrawLines&nbsp;</SPAN><SPAN id=Codehighlighter1_23_1728_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_23_1728_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG id=Codehighlighter1_68_750_Open_Image onclick="this.style.display='none'; Codehighlighter1_68_750_Open_Text.style.display='none'; Codehighlighter1_68_750_Closed_Image.style.display='inline'; Codehighlighter1_68_750_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_68_750_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_68_750_Closed_Text.style.display='none'; Codehighlighter1_68_750_Open_Image.style.display='inline'; Codehighlighter1_68_750_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;String[]&nbsp;execute(String[]&nbsp;commands)</SPAN><SPAN id=Codehighlighter1_68_750_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_68_750_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">[][]&nbsp;map&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">[</SPAN><SPAN style="COLOR: #000000">20</SPAN><SPAN style="COLOR: #000000">][</SPAN><SPAN style="COLOR: #000000">20</SPAN><SPAN style="COLOR: #000000">];<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;x</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,y</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;<BR><IMG id=Codehighlighter1_139_165_Open_Image onclick="this.style.display='none'; Codehighlighter1_139_165_Open_Text.style.display='none'; Codehighlighter1_139_165_Closed_Image.style.display='inline'; Codehighlighter1_139_165_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_139_165_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_139_165_Closed_Text.style.display='none'; Codehighlighter1_139_165_Open_Image.style.display='inline'; Codehighlighter1_139_165_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">[][]&nbsp;directions</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN id=Codehighlighter1_139_165_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_139_165_Open_Text><SPAN style="COLOR: #000000">{</SPAN><SPAN id=Codehighlighter1_140_144_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_140_144_Open_Text><SPAN style="COLOR: #000000">{</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">}</SPAN></SPAN><SPAN style="COLOR: #