﻿<?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>Sun, 09 Sep 2012 16:54:25 GMT</lastBuildDate><pubDate>Sun, 09 Sep 2012 16:54:25 GMT</pubDate><ttl>60</ttl><item><title>没忍住手痒做了一道题，结果还没作对。</title><link>http://www.blogjava.net/emu/articles/387356.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Sun, 09 Sep 2012 14:40:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/387356.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/387356.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/387356.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/387356.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/387356.html</trackback:ping><description><![CDATA[今晚举行的腾讯编程马拉松，监考过程看到第二题居然一直没人做出来，忍不住手痒做了一下。题目如下
<div><br />
</div>
<div>
<div style="background-color: #eeeeee; font-size: 13px; border-left-color: #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; "><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->赛车手&nbsp;返回比赛首页<br />
古哥是腾讯著名的赛车手。在一次特殊的内部赛车比赛中，古哥为了体现出他对参赛MM的关照，约定在比赛过程中有车速限制，每一个这样的限制都可以描述为一个三元组(s,t,d)，表示在比赛的t时间开始，持续d时间的过程中，古哥的车速不会超过s.古哥为了在这种情况下依旧证明他强大的实力，想让聪明的你帮他求出在给定比赛时间T内，赛车的加速度最大为a的情况下，古哥可能行驶的最远距离。<br />
PS：车速初始为0.<br />
输入:<br />
第一行为一个数Cases，用来描述有多少组数据。<br />
对于每组测试数据，首先为一个数&nbsp;n&nbsp;(0&lt;=n&lt;=50)&nbsp;表示有&nbsp;n个速度限制的三元组(s,t,d)&nbsp;其中&nbsp;0&lt;=s&lt;=100，0&lt;=t&lt;=T，0&lt;=d&lt;=1000<br />
接下来为两个正整数T&nbsp;a，用来描述比赛总时长和汽车的最大加速度。其中0&lt;=T&lt;=1000，&nbsp;0&lt;=a&lt;=25<br />
输出:<br />
对于每个测试数据,输出古哥可能行驶的最远距离，精确到0.0001。<br />
样例输入：<br />
2<br />
0<br />
998&nbsp;1<br />
2<br />
10&nbsp;10&nbsp;10<br />
20&nbsp;30&nbsp;20<br />
50&nbsp;1<br />
样例输出：<br />
498002.0000<br />
700.0000<br />
</div>
</div>
<div><br />
</div>
<div>我用js（非指定竞赛语言），在规定时间内做到这样：</div>
<div>
<div style="background-color: #eeeeee; font-size: 13px; border-left-color: #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; "><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">html</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">head</span><span style="color: #0000FF; ">&gt;&lt;/</span><span style="color: #800000; ">head</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">body</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">textarea</span><span style="color: #0000FF; ">&gt;</span>2<br />
0<br />
998&nbsp;1<br />
2<br />
10&nbsp;10&nbsp;10<br />
20&nbsp;30&nbsp;20<br />
50&nbsp;1<br />
5<br />
2&nbsp;1&nbsp;2<br />
6&nbsp;4&nbsp;3<br />
4&nbsp;7&nbsp;1<br />
5&nbsp;10&nbsp;1<br />
1&nbsp;12&nbsp;1<br />
12&nbsp;2<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">textarea</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">script</span><span style="color: #0000FF; ">&gt;</span><span style="background-color: #f5f5f5; "><br />
</span><span style="background-color: #F5F5F5; color: #0000FF; ">var</span><span style="background-color: #f5f5f5; ">&nbsp;data</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">document.getElementsByTagName(</span><span style="background-color: #f5f5f5; ">"</span><span style="background-color: #f5f5f5; ">textarea</span><span style="background-color: #f5f5f5; ">"</span><span style="background-color: #f5f5f5; ">)[</span><span style="background-color: #f5f5f5; ">0</span><span style="background-color: #f5f5f5; ">].value.split(</span><span style="background-color: #f5f5f5; ">"</span><span style="background-color: #f5f5f5; ">\n</span><span style="background-color: #f5f5f5; ">"</span><span style="background-color: #f5f5f5; ">);<br />
</span><span style="background-color: #F5F5F5; color: #0000FF; ">var</span><span style="background-color: #f5f5f5; ">&nbsp;idx</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">0</span><span style="background-color: #f5f5f5; ">;<br />
</span><span style="background-color: #F5F5F5; color: #0000FF; ">for</span><span style="background-color: #f5f5f5; ">(</span><span style="background-color: #F5F5F5; color: #0000FF; ">var</span><span style="background-color: #f5f5f5; ">&nbsp;i</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">1</span><span style="background-color: #f5f5f5; ">;i</span><span style="background-color: #f5f5f5; ">&lt;</span><span style="background-color: #f5f5f5; ">data[</span><span style="background-color: #f5f5f5; ">0</span><span style="background-color: #f5f5f5; ">]</span><span style="background-color: #f5f5f5; ">+</span><span style="background-color: #f5f5f5; ">1</span><span style="background-color: #f5f5f5; ">;i</span><span style="background-color: #f5f5f5; ">++</span><span style="background-color: #f5f5f5; ">){<br />
</span><span style="background-color: #F5F5F5; color: #0000FF; ">var</span><span style="background-color: #f5f5f5; ">&nbsp;limits</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">[]<br />
&nbsp;&nbsp;&nbsp;&nbsp;n</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">data[</span><span style="background-color: #f5f5f5; ">++</span><span style="background-color: #f5f5f5; ">idx];<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: #F5F5F5; color: #0000FF; ">for</span><span style="background-color: #f5f5f5; ">(</span><span style="background-color: #F5F5F5; color: #0000FF; ">var</span><span style="background-color: #f5f5f5; ">&nbsp;j</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">0</span><span style="background-color: #f5f5f5; ">;j</span><span style="background-color: #f5f5f5; ">&lt;</span><span style="background-color: #f5f5f5; ">n;j</span><span style="background-color: #f5f5f5; ">++</span><span style="background-color: #f5f5f5; ">){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;limits.push(data[</span><span style="background-color: #f5f5f5; ">++</span><span style="background-color: #f5f5f5; ">idx].split(</span><span style="background-color: #f5f5f5; ">"</span><span style="background-color: #f5f5f5; ">&nbsp;</span><span style="background-color: #f5f5f5; ">"</span><span style="background-color: #f5f5f5; ">))<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;tmp</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">data[</span><span style="background-color: #f5f5f5; ">++</span><span style="background-color: #f5f5f5; ">idx].split(</span><span style="background-color: #f5f5f5; ">"</span><span style="background-color: #f5f5f5; ">&nbsp;</span><span style="background-color: #f5f5f5; ">"</span><span style="background-color: #f5f5f5; ">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;T</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">tmp[</span><span style="background-color: #f5f5f5; ">0</span><span style="background-color: #f5f5f5; ">]</span><span style="background-color: #f5f5f5; ">-</span><span style="background-color: #f5f5f5; ">0</span><span style="background-color: #f5f5f5; ">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;a</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">tmp[</span><span style="background-color: #f5f5f5; ">1</span><span style="background-color: #f5f5f5; ">]</span><span style="background-color: #f5f5f5; ">-</span><span style="background-color: #f5f5f5; ">0</span><span style="background-color: #f5f5f5; ">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: #F5F5F5; color: #0000FF; ">var</span><span style="background-color: #f5f5f5; ">&nbsp;speedAtRealTime</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #F5F5F5; color: #0000FF; ">new</span><span style="background-color: #f5f5f5; ">&nbsp;Array(T</span><span style="background-color: #f5f5f5; ">+</span><span style="background-color: #f5f5f5; ">1</span><span style="background-color: #f5f5f5; ">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;speedAtRealTime[</span><span style="background-color: #f5f5f5; ">0</span><span style="background-color: #f5f5f5; ">]</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">0</span><span style="background-color: #f5f5f5; ">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: #F5F5F5; color: #0000FF; ">for</span><span style="background-color: #f5f5f5; ">(</span><span style="background-color: #F5F5F5; color: #0000FF; ">var</span><span style="background-color: #f5f5f5; ">&nbsp;j</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">1</span><span style="background-color: #f5f5f5; ">;j</span><span style="background-color: #f5f5f5; ">&lt;=</span><span style="background-color: #f5f5f5; ">T;j</span><span style="background-color: #f5f5f5; ">++</span><span style="background-color: #f5f5f5; ">){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;speedAtRealTime[j]</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">speedAtRealTime[j</span><span style="background-color: #f5f5f5; ">-</span><span style="background-color: #f5f5f5; ">1</span><span style="background-color: #f5f5f5; ">]</span><span style="background-color: #f5f5f5; ">+</span><span style="background-color: #f5f5f5; ">a;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: #F5F5F5; color: #0000FF; ">for</span><span style="background-color: #f5f5f5; ">(</span><span style="background-color: #F5F5F5; color: #0000FF; ">var</span><span style="background-color: #f5f5f5; ">&nbsp;j</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">0</span><span style="background-color: #f5f5f5; ">;j</span><span style="background-color: #f5f5f5; ">&lt;</span><span style="background-color: #f5f5f5; ">limits.length;j</span><span style="background-color: #f5f5f5; ">++</span><span style="background-color: #f5f5f5; ">){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: #F5F5F5; color: #0000FF; ">for</span><span style="background-color: #f5f5f5; ">(</span><span style="background-color: #F5F5F5; color: #0000FF; ">var</span><span style="background-color: #f5f5f5; ">&nbsp;k</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">limits[j][</span><span style="background-color: #f5f5f5; ">1</span><span style="background-color: #f5f5f5; ">];k</span><span style="background-color: #f5f5f5; ">&lt;=</span><span style="background-color: #f5f5f5; ">limits[j][</span><span style="background-color: #f5f5f5; ">1</span><span style="background-color: #f5f5f5; ">]</span><span style="background-color: #f5f5f5; ">-</span><span style="background-color: #f5f5f5; ">(</span><span style="background-color: #f5f5f5; ">-</span><span style="background-color: #f5f5f5; ">limits[j][</span><span style="background-color: #f5f5f5; ">2</span><span style="background-color: #f5f5f5; ">]);k</span><span style="background-color: #f5f5f5; ">++</span><span style="background-color: #f5f5f5; ">){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: #F5F5F5; color: #0000FF; ">if</span><span style="background-color: #f5f5f5; ">(speedAtRealTime[k]</span><span style="background-color: #f5f5f5; ">&gt;</span><span style="background-color: #f5f5f5; ">limits[j][</span><span style="background-color: #f5f5f5; ">0</span><span style="background-color: #f5f5f5; ">]</span><span style="background-color: #f5f5f5; ">-</span><span style="background-color: #f5f5f5; ">0</span><span style="background-color: #f5f5f5; ">){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;speedAtRealTime[k]</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">limits[j][</span><span style="background-color: #f5f5f5; ">0</span><span style="background-color: #f5f5f5; ">]</span><span style="background-color: #f5f5f5; ">-</span><span style="background-color: #f5f5f5; ">0</span><span style="background-color: #f5f5f5; ">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: #F5F5F5; color: #0000FF; ">var</span><span style="background-color: #f5f5f5; ">&nbsp;adjustSpeed</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #F5F5F5; color: #0000FF; ">true</span><span style="background-color: #f5f5f5; ">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: #F5F5F5; color: #0000FF; ">while</span><span style="background-color: #f5f5f5; ">(adjustSpeed){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;adjustSpeed</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #F5F5F5; color: #0000FF; ">false</span><span style="background-color: #f5f5f5; ">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: #F5F5F5; color: #0000FF; ">for</span><span style="background-color: #f5f5f5; ">(</span><span style="background-color: #F5F5F5; color: #0000FF; ">var</span><span style="background-color: #f5f5f5; ">&nbsp;j</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">1</span><span style="background-color: #f5f5f5; ">;j</span><span style="background-color: #f5f5f5; ">&lt;=</span><span style="background-color: #f5f5f5; ">T;j</span><span style="background-color: #f5f5f5; ">++</span><span style="background-color: #f5f5f5; ">){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: #F5F5F5; color: #0000FF; ">if</span><span style="background-color: #f5f5f5; ">(speedAtRealTime[j]</span><span style="background-color: #f5f5f5; ">-</span><span style="background-color: #f5f5f5; ">speedAtRealTime[j</span><span style="background-color: #f5f5f5; ">-</span><span style="background-color: #f5f5f5; ">1</span><span style="background-color: #f5f5f5; ">]</span><span style="background-color: #f5f5f5; ">&gt;</span><span style="background-color: #f5f5f5; ">a){</span><span style="background-color: #F5F5F5; color: #008000; ">//</span><span style="background-color: #F5F5F5; color: #008000; ">加速不了那么快</span><span style="background-color: #F5F5F5; color: #008000; "><br />
</span><span style="background-color: #f5f5f5; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;speedAtRealTime[j]</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">speedAtRealTime[j</span><span style="background-color: #f5f5f5; ">-</span><span style="background-color: #f5f5f5; ">1</span><span style="background-color: #f5f5f5; ">]</span><span style="background-color: #f5f5f5; ">+</span><span style="background-color: #f5f5f5; ">a;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;adjustSpeed</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #F5F5F5; color: #0000FF; ">true</span><span style="background-color: #f5f5f5; ">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: #F5F5F5; color: #0000FF; ">for</span><span style="background-color: #f5f5f5; ">(</span><span style="background-color: #F5F5F5; color: #0000FF; ">var</span><span style="background-color: #f5f5f5; ">&nbsp;j</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">T;j</span><span style="background-color: #f5f5f5; ">&gt;</span><span style="background-color: #f5f5f5; ">0</span><span style="background-color: #f5f5f5; ">;j</span><span style="background-color: #f5f5f5; ">--</span><span style="background-color: #f5f5f5; ">){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: #F5F5F5; color: #0000FF; ">if</span><span style="background-color: #f5f5f5; ">(speedAtRealTime[j</span><span style="background-color: #f5f5f5; ">-</span><span style="background-color: #f5f5f5; ">1</span><span style="background-color: #f5f5f5; ">]</span><span style="background-color: #f5f5f5; ">-</span><span style="background-color: #f5f5f5; ">speedAtRealTime[j]</span><span style="background-color: #f5f5f5; ">&gt;</span><span style="background-color: #f5f5f5; ">a){</span><span style="background-color: #F5F5F5; color: #008000; ">//</span><span style="background-color: #F5F5F5; color: #008000; ">要提前减速</span><span style="background-color: #F5F5F5; color: #008000; "><br />
</span><span style="background-color: #f5f5f5; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;speedAtRealTime[j</span><span style="background-color: #f5f5f5; ">-</span><span style="background-color: #f5f5f5; ">1</span><span style="background-color: #f5f5f5; ">]</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">speedAtRealTime[j]</span><span style="background-color: #f5f5f5; ">+</span><span style="background-color: #f5f5f5; ">a;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;adjustSpeed</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #F5F5F5; color: #0000FF; ">true</span><span style="background-color: #f5f5f5; ">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(speedAtRealTime.join(</span><span style="background-color: #f5f5f5; ">"</span><span style="background-color: #f5f5f5; ">,</span><span style="background-color: #f5f5f5; ">"</span><span style="background-color: #f5f5f5; ">));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: #F5F5F5; color: #0000FF; ">var</span><span style="background-color: #f5f5f5; ">&nbsp;length</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">0</span><span style="background-color: #f5f5f5; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="background-color: #F5F5F5; color: #0000FF; ">for</span><span style="background-color: #f5f5f5; ">(</span><span style="background-color: #F5F5F5; color: #0000FF; ">var</span><span style="background-color: #f5f5f5; ">&nbsp;j</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">1</span><span style="background-color: #f5f5f5; ">;j</span><span style="background-color: #f5f5f5; ">&lt;</span><span style="background-color: #f5f5f5; ">speedAtRealTime.length;j</span><span style="background-color: #f5f5f5; ">++</span><span style="background-color: #f5f5f5; ">){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;length</span><span style="background-color: #f5f5f5; ">+=</span><span style="background-color: #f5f5f5; ">speedAtRealTime[j</span><span style="background-color: #f5f5f5; ">-</span><span style="background-color: #f5f5f5; ">1</span><span style="background-color: #f5f5f5; ">]</span><span style="background-color: #f5f5f5; ">+</span><span style="background-color: #f5f5f5; ">speedAtRealTime[j]<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;length</span><span style="background-color: #f5f5f5; ">=</span><span style="background-color: #f5f5f5; ">length</span><span style="background-color: #f5f5f5; ">/</span><span style="background-color: #f5f5f5; ">2</span><span style="background-color: #f5f5f5; ">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;alert(length)<br />
}<br />
</span><span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">script</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">body</span><span style="color: #0000FF; ">&gt;</span><br />
<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">html</span><span style="color: #0000ff; ">&gt;</span></div>
</div>
<div><br />
</div>
<div>结果还是差了临门一脚：</div>
<div>
<div>1</div>
<div>0 1 0</div>
<div>1 1</div>
<div>正确输出:</div>
<div>0.2500</div>
</div>
<div>谁想出来的在一秒内还可以加速半秒减速半秒这么损的招啊？</div>
<div><br />
</div>
<div><br />
</div>
<div><br />
</div><img src ="http://www.blogjava.net/emu/aggbug/387356.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> 2012-09-09 22:40 <a href="http://www.blogjava.net/emu/articles/387356.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>差点被燕潘考倒了</title><link>http://www.blogjava.net/emu/articles/327759.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Mon, 02 Aug 2010 08:49:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/327759.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/327759.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/327759.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/327759.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/327759.html</trackback:ping><description><![CDATA[问题是这样的：从1到100000中任意拿掉两个数字，把剩下99998个数的顺序打乱并且放到数组中，要求只扫描一遍，把这个两个数找出来，可以使用最多不超过5个局部变量，不能使用数组变量并且不能改变数组的值。<br />
<br />
开始老担心溢出问题，最简单的方法不敢用，老想另辟蹊径。最后发现担心是多余的，这里需要用到的数只是稍微超过32位而已，大多数高级语言都能很轻松的处理64位大整数，连javascript也可以处理54位的大整数而不丢失精度，远远超过了这个问题的规模。<br />
<br />
这里特地把计算范围扩大了5倍来检验溢出问题。规模再大的时候我的IE计算时间超过5秒开始要警告了。为了代码简洁，打乱次序使用了效率很低的sort方法，大量的时间都消耗在这一步。把排序参数调整为0.8（而不是0.5）主要是为了减少排序计算量。<br />
<br />
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><span style="color: #0000ff">&lt;</span><span style="color: #800000">HTML</span><span style="color: #0000ff">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">BODY</span><span style="color: #0000ff">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">SCRIPT&nbsp;</span><span style="color: #ff0000">LANGUAGE</span><span style="color: #0000ff">="JavaScript"</span><span style="color: #0000ff">&gt;</span><span style="background-color: #f5f5f5; color: #000000"><br />
</span><span style="background-color: #f5f5f5; color: #000000">&lt;!--</span><span style="background-color: #f5f5f5; color: #000000"><br />
</span><span style="background-color: #f5f5f5; color: #0000ff">var</span><span style="background-color: #f5f5f5; color: #000000">&nbsp;n</span><span style="background-color: #f5f5f5; color: #000000">=</span><span style="background-color: #f5f5f5; color: #000000">500000</span><span style="background-color: #f5f5f5; color: #000000">;</span><span style="background-color: #f5f5f5; color: #008000">//</span><span style="background-color: #f5f5f5; color: #008000">n是常数,不算临时变量。</span><span style="background-color: #f5f5f5; color: #008000"><br />
</span><span style="background-color: #f5f5f5; color: #0000ff">var</span><span style="background-color: #f5f5f5; color: #000000">&nbsp;ar</span><span style="background-color: #f5f5f5; color: #000000">=</span><span style="background-color: #f5f5f5; color: #000000">[];</span><span style="background-color: #f5f5f5; color: #008000">//</span><span style="background-color: #f5f5f5; color: #008000">这是输入数据，不算临时变量</span><span style="background-color: #f5f5f5; color: #008000"><br />
</span><span style="background-color: #f5f5f5; color: #0000ff">for</span><span style="background-color: #f5f5f5; color: #000000">(</span><span style="background-color: #f5f5f5; color: #0000ff">var</span><span style="background-color: #f5f5f5; color: #000000">&nbsp;i</span><span style="background-color: #f5f5f5; color: #000000">=</span><span style="background-color: #f5f5f5; color: #000000">0</span><span style="background-color: #f5f5f5; color: #000000">;i</span><span style="background-color: #f5f5f5; color: #000000">&lt;</span><span style="background-color: #f5f5f5; color: #000000">n;i</span><span style="background-color: #f5f5f5; color: #000000">++</span><span style="background-color: #f5f5f5; color: #000000">){<br />
&nbsp;&nbsp;&nbsp;&nbsp;ar.push(i</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">1</span><span style="background-color: #f5f5f5; color: #000000">)<br />
}<br />
</span><span style="background-color: #f5f5f5; color: #008000">//</span><span style="background-color: #f5f5f5; color: #008000">i是生成输入数据使用的，不算临时变量</span><span style="background-color: #f5f5f5; color: #008000"><br />
//</span><span style="background-color: #f5f5f5; color: #008000">随机抽取掉两个数</span><span style="background-color: #f5f5f5; color: #008000"><br />
</span><span style="background-color: #f5f5f5; color: #000000">document.write(</span><span style="background-color: #f5f5f5; color: #000000">"</span><span style="background-color: #f5f5f5; color: #000000">抽掉的第1个数是：</span><span style="background-color: #f5f5f5; color: #000000">"</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">ar.splice(Math.floor(Math.random()</span><span style="background-color: #f5f5f5; color: #000000">*</span><span style="background-color: #f5f5f5; color: #000000">ar.length),</span><span style="background-color: #f5f5f5; color: #000000">1</span><span style="background-color: #f5f5f5; color: #000000">))<br />
document.write(</span><span style="background-color: #f5f5f5; color: #000000">"</span><span style="background-color: #f5f5f5; color: #000000">&lt;br&gt;抽掉的第2个数是：</span><span style="background-color: #f5f5f5; color: #000000">"</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">ar.splice(Math.floor(Math.random()</span><span style="background-color: #f5f5f5; color: #000000">*</span><span style="background-color: #f5f5f5; color: #000000">ar.length),</span><span style="background-color: #f5f5f5; color: #000000">1</span><span style="background-color: #f5f5f5; color: #000000">))<br />
</span><span style="background-color: #f5f5f5; color: #008000">//</span><span style="background-color: #f5f5f5; color: #008000">打乱顺序</span><span style="background-color: #f5f5f5; color: #008000"><br />
</span><span style="background-color: #f5f5f5; color: #000000">ar.sort(</span><span style="background-color: #f5f5f5; color: #0000ff">function</span><span style="background-color: #f5f5f5; color: #000000">(){</span><span style="background-color: #f5f5f5; color: #0000ff">return</span><span style="background-color: #f5f5f5; color: #000000">&nbsp;Math.random()</span><span style="background-color: #f5f5f5; color: #000000">-</span><span style="background-color: #f5f5f5; color: #000000">.</span><span style="background-color: #f5f5f5; color: #000000">8</span><span style="background-color: #f5f5f5; color: #000000">})<br />
</span><span style="background-color: #f5f5f5; color: #008000">//</span><span style="background-color: #f5f5f5; color: #008000">使用了3个临时变量</span><span style="background-color: #f5f5f5; color: #008000"><br />
</span><span style="background-color: #f5f5f5; color: #0000ff">var</span><span style="background-color: #f5f5f5; color: #000000">&nbsp;t1</span><span style="background-color: #f5f5f5; color: #000000">=</span><span style="background-color: #f5f5f5; color: #000000">0</span><span style="background-color: #f5f5f5; color: #000000">,t2</span><span style="background-color: #f5f5f5; color: #000000">=</span><span style="background-color: #f5f5f5; color: #000000">0</span><span style="background-color: #f5f5f5; color: #000000">,t3;<br />
</span><span style="background-color: #f5f5f5; color: #0000ff">for</span><span style="background-color: #f5f5f5; color: #000000">(t3</span><span style="background-color: #f5f5f5; color: #000000">=</span><span style="background-color: #f5f5f5; color: #000000">ar.length</span><span style="background-color: #f5f5f5; color: #000000">-</span><span style="background-color: #f5f5f5; color: #000000">1</span><span style="background-color: #f5f5f5; color: #000000">;t3</span><span style="background-color: #f5f5f5; color: #000000">&gt;=</span><span style="background-color: #f5f5f5; color: #000000">0</span><span style="background-color: #f5f5f5; color: #000000">;t3</span><span style="background-color: #f5f5f5; color: #000000">--</span><span style="background-color: #f5f5f5; color: #000000">){<br />
&nbsp;&nbsp;&nbsp;&nbsp;t1</span><span style="background-color: #f5f5f5; color: #000000">=</span><span style="background-color: #f5f5f5; color: #000000">t1</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">ar[t3];<br />
&nbsp;&nbsp;&nbsp;&nbsp;t2</span><span style="background-color: #f5f5f5; color: #000000">=</span><span style="background-color: #f5f5f5; color: #000000">t2</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">(t3</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">1</span><span style="background-color: #f5f5f5; color: #000000">)</span><span style="background-color: #f5f5f5; color: #000000">*</span><span style="background-color: #f5f5f5; color: #000000">(t3</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">1</span><span style="background-color: #f5f5f5; color: #000000">)</span><span style="background-color: #f5f5f5; color: #000000">-</span><span style="background-color: #f5f5f5; color: #000000">ar[t3]</span><span style="background-color: #f5f5f5; color: #000000">*</span><span style="background-color: #f5f5f5; color: #000000">ar[t3];<br />
}<br />
t2</span><span style="background-color: #f5f5f5; color: #000000">=</span><span style="background-color: #f5f5f5; color: #000000">t2</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">n</span><span style="background-color: #f5f5f5; color: #000000">*</span><span style="background-color: #f5f5f5; color: #000000">n</span><span style="background-color: #f5f5f5; color: #000000">*</span><span style="background-color: #f5f5f5; color: #000000">2</span><span style="background-color: #f5f5f5; color: #000000">-</span><span style="background-color: #f5f5f5; color: #000000">n</span><span style="background-color: #f5f5f5; color: #000000">*</span><span style="background-color: #f5f5f5; color: #000000">2</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">1</span><span style="background-color: #f5f5f5; color: #000000">;<br />
document.write(</span><span style="background-color: #f5f5f5; color: #000000">"</span><span style="background-color: #f5f5f5; color: #000000">&lt;br&gt;计算得到两个数是：&lt;br&gt;</span><span style="background-color: #f5f5f5; color: #000000">"</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">(((n</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">1</span><span style="background-color: #f5f5f5; color: #000000">)</span><span style="background-color: #f5f5f5; color: #000000">*</span><span style="background-color: #f5f5f5; color: #000000">n</span><span style="background-color: #f5f5f5; color: #000000">/</span><span style="background-color: #f5f5f5; color: #000000">2</span><span style="background-color: #f5f5f5; color: #000000">-</span><span style="background-color: #f5f5f5; color: #000000">t1)</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">Math.sqrt(</span><span style="background-color: #f5f5f5; color: #000000">2</span><span style="background-color: #f5f5f5; color: #000000">*</span><span style="background-color: #f5f5f5; color: #000000">(t2)</span><span style="background-color: #f5f5f5; color: #000000">-</span><span style="background-color: #f5f5f5; color: #000000">((n</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">1</span><span style="background-color: #f5f5f5; color: #000000">)</span><span style="background-color: #f5f5f5; color: #000000">*</span><span style="background-color: #f5f5f5; color: #000000">n</span><span style="background-color: #f5f5f5; color: #000000">/</span><span style="background-color: #f5f5f5; color: #000000">2</span><span style="background-color: #f5f5f5; color: #000000">-</span><span style="background-color: #f5f5f5; color: #000000">t1)</span><span style="background-color: #f5f5f5; color: #000000">*</span><span style="background-color: #f5f5f5; color: #000000">((n</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">1</span><span style="background-color: #f5f5f5; color: #000000">)</span><span style="background-color: #f5f5f5; color: #000000">*</span><span style="background-color: #f5f5f5; color: #000000">n</span><span style="background-color: #f5f5f5; color: #000000">/</span><span style="background-color: #f5f5f5; color: #000000">2</span><span style="background-color: #f5f5f5; color: #000000">-</span><span style="background-color: #f5f5f5; color: #000000">t1)))</span><span style="background-color: #f5f5f5; color: #000000">/</span><span style="background-color: #f5f5f5; color: #000000">2</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">"</span><span style="background-color: #f5f5f5; color: #000000">&lt;br&gt;</span><span style="background-color: #f5f5f5; color: #000000">"</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">(((n</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">1</span><span style="background-color: #f5f5f5; color: #000000">)</span><span style="background-color: #f5f5f5; color: #000000">*</span><span style="background-color: #f5f5f5; color: #000000">n</span><span style="background-color: #f5f5f5; color: #000000">/</span><span style="background-color: #f5f5f5; color: #000000">2</span><span style="background-color: #f5f5f5; color: #000000">-</span><span style="background-color: #f5f5f5; color: #000000">t1)</span><span style="background-color: #f5f5f5; color: #000000">-</span><span style="background-color: #f5f5f5; color: #000000">Math.sqrt(</span><span style="background-color: #f5f5f5; color: #000000">2</span><span style="background-color: #f5f5f5; color: #000000">*</span><span style="background-color: #f5f5f5; color: #000000">(t2)</span><span style="background-color: #f5f5f5; color: #000000">-</span><span style="background-color: #f5f5f5; color: #000000">((n</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">1</span><span style="background-color: #f5f5f5; color: #000000">)</span><span style="background-color: #f5f5f5; color: #000000">*</span><span style="background-color: #f5f5f5; color: #000000">n</span><span style="background-color: #f5f5f5; color: #000000">/</span><span style="background-color: #f5f5f5; color: #000000">2</span><span style="background-color: #f5f5f5; color: #000000">-</span><span style="background-color: #f5f5f5; color: #000000">t1)</span><span style="background-color: #f5f5f5; color: #000000">*</span><span style="background-color: #f5f5f5; color: #000000">((n</span><span style="background-color: #f5f5f5; color: #000000">+</span><span style="background-color: #f5f5f5; color: #000000">1</span><span style="background-color: #f5f5f5; color: #000000">)</span><span style="background-color: #f5f5f5; color: #000000">*</span><span style="background-color: #f5f5f5; color: #000000">n</span><span style="background-color: #f5f5f5; color: #000000">/</span><span style="background-color: #f5f5f5; color: #000000">2</span><span style="background-color: #f5f5f5; color: #000000">-</span><span style="background-color: #f5f5f5; color: #000000">t1)))</span><span style="background-color: #f5f5f5; color: #000000">/</span><span style="background-color: #f5f5f5; color: #000000">2</span><span style="background-color: #f5f5f5; color: #000000">)<br />
</span><span style="background-color: #f5f5f5; color: #008000">//</span><span style="background-color: #f5f5f5; color: #008000">--&gt;</span><span style="background-color: #f5f5f5; color: #008000"><br />
</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">SCRIPT</span><span style="color: #0000ff">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">BODY</span><span style="color: #0000ff">&gt;</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">HTML</span><span style="color: #0000ff">&gt;</span></div>
<img src ="http://www.blogjava.net/emu/aggbug/327759.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> 2010-08-02 16:49 <a href="http://www.blogjava.net/emu/articles/327759.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><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>7</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>3</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>4</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>6</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>4</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>2</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>9</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>3</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>4</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>5</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中国编程挑战赛资格赛真题 -- 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中国编程挑战赛资格赛真题 -- 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中国编程挑战赛资格赛真题 -- 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中国编程挑战赛模拟题 -- 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: #000000">,</SPAN><SPAN id=Codehighlighter1_146_150_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_146_150_Open_Text><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">}</SPAN></SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN id=Codehighlighter1_152_157_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_152_157_Open_Text><SPAN style="COLOR: #000000">{</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><SPAN style="COLOR: #000000">,</SPAN><SPAN id=Codehighlighter1_159_164_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_159_164_Open_Text><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">}</SPAN></SPAN><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;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;directionIndex&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 id=Codehighlighter1_230_548_Open_Image onclick="this.style.display='none'; Codehighlighter1_230_548_Open_Text.style.display='none'; Codehighlighter1_230_548_Closed_Image.style.display='inline'; Codehighlighter1_230_548_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_230_548_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_230_548_Closed_Text.style.display='none'; Codehighlighter1_230_548_Open_Image.style.display='inline'; Codehighlighter1_230_548_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">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">commands.length;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN id=Codehighlighter1_230_548_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_230_548_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;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;c&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;commands[i];<BR><IMG id=Codehighlighter1_286_335_Open_Image onclick="this.style.display='none'; Codehighlighter1_286_335_Open_Text.style.display='none'; Codehighlighter1_286_335_Closed_Image.style.display='inline'; Codehighlighter1_286_335_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_286_335_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_286_335_Closed_Text.style.display='none'; Codehighlighter1_286_335_Open_Image.style.display='inline'; Codehighlighter1_286_335_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(c.indexOf(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</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_286_335_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_286_335_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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;directionIndex&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(directionIndex</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">4</SPAN><SPAN style="COLOR: #000000">&nbsp;;<BR><IMG id=Codehighlighter1_340_544_Open_Image onclick="this.style.display='none'; Codehighlighter1_340_544_Open_Text.style.display='none'; Codehighlighter1_340_544_Closed_Image.style.display='inline'; Codehighlighter1_340_544_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_340_544_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_340_544_Closed_Text.style.display='none'; Codehighlighter1_340_544_Open_Image.style.display='inline'; Codehighlighter1_340_544_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN id=Codehighlighter1_340_544_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_340_544_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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;steps&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;Integer.parseInt(c.substring(</SPAN><SPAN style="COLOR: #000000">8</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;&nbsp;&nbsp;&nbsp;&nbsp;map[x][y]</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">;<BR><IMG id=Codehighlighter1_437_539_Open_Image onclick="this.style.display='none'; Codehighlighter1_437_539_Open_Text.style.display='none'; Codehighlighter1_437_539_Closed_Image.style.display='inline'; Codehighlighter1_437_539_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_437_539_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_437_539_Closed_Text.style.display='none'; Codehighlighter1_437_539_Open_Image.style.display='inline'; Codehighlighter1_437_539_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;j</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;j</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">steps;j</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN id=Codehighlighter1_437_539_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_437_539_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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x</SPAN><SPAN style="COLOR: #000000">+=</SPAN><SPAN style="COLOR: #000000">directions[directionIndex][</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y</SPAN><SPAN style="COLOR: #000000">+=</SPAN><SPAN style="COLOR: #000000">directions[directionIndex][</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;map[x][y]</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/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;String[]&nbsp;result</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;String[</SPAN><SPAN style="COLOR: #000000">20</SPAN><SPAN style="COLOR: #000000">];<BR><IMG id=Codehighlighter1_607_730_Open_Image onclick="this.style.display='none'; Codehighlighter1_607_730_Open_Text.style.display='none'; Codehighlighter1_607_730_Closed_Image.style.display='inline'; Codehighlighter1_607_730_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_607_730_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_607_730_Closed_Text.style.display='none'; Codehighlighter1_607_730_Open_Image.style.display='inline'; Codehighlighter1_607_730_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">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">20</SPAN><SPAN style="COLOR: #000000">;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN id=Codehighlighter1_607_730_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_607_730_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;&nbsp;&nbsp;&nbsp;&nbsp;result[i]</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">;<BR><IMG id=Codehighlighter1_650_692_Open_Image onclick="this.style.display='none'; Codehighlighter1_650_692_Open_Text.style.display='none'; Codehighlighter1_650_692_Closed_Image.style.display='inline'; Codehighlighter1_650_692_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_650_692_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_650_692_Closed_Text.style.display='none'; Codehighlighter1_650_692_Open_Image.style.display='inline'; Codehighlighter1_650_692_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&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;j</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;j</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">20</SPAN><SPAN style="COLOR: #000000">;j</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN id=Codehighlighter1_650_692_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_650_692_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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result[i]</SPAN><SPAN style="COLOR: #000000">+=</SPAN><SPAN style="COLOR: #000000">map[j][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">X</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">:</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">.</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(result[i]);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&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;&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 src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_793_1726_Open_Image onclick="this.style.display='none'; Codehighlighter1_793_1726_Open_Text.style.display='none'; Codehighlighter1_793_1726_Closed_Image.style.display='inline'; Codehighlighter1_793_1726_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_793_1726_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_793_1726_Closed_Text.style.display='none'; Codehighlighter1_793_1726_Open_Image.style.display='inline'; Codehighlighter1_793_1726_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)&nbsp;</SPAN><SPAN id=Codehighlighter1_793_1726_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_793_1726_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 id=Codehighlighter1_826_905_Open_Image onclick="this.style.display='none'; Codehighlighter1_826_905_Open_Text.style.display='none'; Codehighlighter1_826_905_Closed_Image.style.display='inline'; Codehighlighter1_826_905_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_826_905_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_826_905_Closed_Text.style.display='none'; Codehighlighter1_826_905_Open_Image.style.display='inline'; Codehighlighter1_826_905_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;String[]</SPAN><SPAN id=Codehighlighter1_826_905_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_826_905_Open_Text><SPAN style="COLOR: #000000">{</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">FORWARD&nbsp;19</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">FORWARD&nbsp;19</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">FORWARD&nbsp;19</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">FORWARD&nbsp;19</SPAN><SPAN style="COLOR: #000000">"</SPAN><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;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;DrawLines().execute(s);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();<BR><IMG id=Codehighlighter1_979_1042_Open_Image onclick="this.style.display='none'; Codehighlighter1_979_1042_Open_Text.style.display='none'; Codehighlighter1_979_1042_Closed_Image.style.display='inline'; Codehighlighter1_979_1042_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_979_1042_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_979_1042_Closed_Text.style.display='none'; Codehighlighter1_979_1042_Open_Image.style.display='inline'; Codehighlighter1_979_1042_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;String[]</SPAN><SPAN id=Codehighlighter1_979_1042_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_979_1042_Open_Text><SPAN style="COLOR: #000000">{</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><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;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;DrawLines().execute(s);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();<BR><IMG id=Codehighlighter1_1116_1128_Open_Image onclick="this.style.display='none'; Codehighlighter1_1116_1128_Open_Text.style.display='none'; Codehighlighter1_1116_1128_Closed_Image.style.display='inline'; Codehighlighter1_1116_1128_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1116_1128_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1116_1128_Closed_Text.style.display='none'; Codehighlighter1_1116_1128_Open_Image.style.display='inline'; Codehighlighter1_1116_1128_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;String[]</SPAN><SPAN id=Codehighlighter1_1116_1128_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_1116_1128_Open_Text><SPAN style="COLOR: #000000">{</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">FORWARD&nbsp;1</SPAN><SPAN style="COLOR: #000000">"</SPAN><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;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;DrawLines().execute(s);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();<BR><IMG id=Codehighlighter1_1202_1692_Open_Image onclick="this.style.display='none'; Codehighlighter1_1202_1692_Open_Text.style.display='none'; Codehighlighter1_1202_1692_Closed_Image.style.display='inline'; Codehighlighter1_1202_1692_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1202_1692_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1202_1692_Closed_Text.style.display='none'; Codehighlighter1_1202_1692_Open_Image.style.display='inline'; Codehighlighter1_1202_1692_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;String[]</SPAN><SPAN id=Codehighlighter1_1202_1692_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_1202_1692_Open_Text><SPAN style="COLOR: #000000">{</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">FORWARD&nbsp;19</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</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;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">FORWARD&nbsp;18</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">FORWARD&nbsp;17</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;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">FORWARD&nbsp;16</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</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;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">FORWARD&nbsp;15</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</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;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">FORWARD&nbsp;14</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">FORWARD&nbsp;13</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;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">FORWARD&nbsp;12</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</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;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">FORWARD&nbsp;11</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">FORWARD&nbsp;10</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;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">FORWARD&nbsp;9</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">FORWARD&nbsp;8</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">LEFT</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">FORWARD&nbsp;7</SPAN><SPAN style="COLOR: #000000">"</SPAN><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;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;DrawLines().execute(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><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV><BR><BR>热身题，很久没有写java了，改了半天语法错误。<img src ="http://www.blogjava.net/emu/aggbug/22085.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 10:37 <a href="http://www.blogjava.net/emu/articles/22085.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SongRenamer (入围赛250分真题)</title><link>http://www.blogjava.net/emu/articles/10997.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Thu, 25 Aug 2005 03:08:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/10997.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/10997.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/10997.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/10997.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/10997.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>You are given a collection of music files that have each been tagged with the artist, album, track number, and song title. However, the actual file names do not follow any standard format. Given a desired naming format, determine the proper names for all of the files in the collection. You are given four String[]s, <B>artists</B>, <B>albums</B>, <B>tracks</B>, and <B>titles</B>, which contain the artist, album, track number, and song title, respectively, for all the music files. Element i of each String[] corresponds to the ith file. You are given the desired file name format as a String, <B>format</B>. This String will contain only characters from "ABTS -()._" (quotes for clarity only). To determine a file name, replace all occurrences of 'A', 'B', 'T', and 'S' in <B>format</B> with the artist, album, track number, and song title, respectively. All other characters should remain untouched. For example, if <B>format</B> = "A - B - T) S", the artist is "The Beatles", the album is "Rubber Soul", the track number is "07", and the song title is "Michelle", the file should be named "The Beatles - Rubber Soul - 07) Michelle". Return a String[] containing the file names for all the songs in the collection. The ith element of the return String[] should correspond to the song represented by the ith elements of the four String[] parameters. </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>SongRenamer </TD></TR>
<TR>
<TD>Method: </TD>
<TD>rename </TD></TR>
<TR>
<TD>Parameters: </TD>
<TD>String[], String[], String[], String[], String </TD></TR>
<TR>
<TD>Returns: </TD>
<TD>String[] </TD></TR>
<TR>
<TD>Method signature: </TD>
<TD>String[] rename(String[] artists, String[] albums, String[] tracks, String[] titles, String format) </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>artists</B>, <B>albums</B>, <B>tracks</B>, and <B>titles</B> will each contain between 1 and 20 elements, inclusive. </TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD><B>artists</B>, <B>albums</B>, <B>tracks</B>, and <B>titles</B> will each contain the same number of elements. </TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD>Each element of <B>artists</B>, <B>albums</B>, <B>tracks</B>, and <B>titles</B> will contain between 1 and 20 characters, inclusive. </TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD>Each element of <B>artists</B>, <B>albums</B>, <B>tracks</B>, and <B>titles</B> will contain only letters ('a'-'z', 'A'-'Z'), digits ('0'-'9'), and spaces. </TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD><B>format</B> will contain between 1 and 10 characters, inclusive. </TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD><B>format</B> will contain only characters from the String "ABTS -()._" (quotes for clarity only). </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>{"Marvin Gaye", "Marvin Gaye"}</PRE></TD></TR>
<TR>
<TD><PRE>{"Here My Dear", "Whats Going On"}</PRE></TD></TR>
<TR>
<TD><PRE>{"09", "7"}</PRE></TD></TR>
<TR>
<TD><PRE>{"Annas Song", "Right On"}</PRE></TD></TR>
<TR>
<TD><PRE>"A - B-T-S"</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: 
{"Marvin Gaye - Here My Dear-09-Annas Song",
 "Marvin Gaye - Whats Going On-7-Right On" }</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>{"Booker T and the MGs"}</PRE></TD></TR>
<TR>
<TD><PRE>{"McLemore Avenue"}</PRE></TD></TR>
<TR>
<TD><PRE>{"Number Two"}</PRE></TD></TR>
<TR>
<TD><PRE>{"Something"}</PRE></TD></TR>
<TR>
<TD><PRE>"T. S_B_(S)"</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: {"Number Two. Something_McLemore Avenue_(Something)" }</PRE></TD></TR>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD colSpan=2><B>format</B> can contain multiple instances of the same tag. Also, track numbers do not have to contain only digits. </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>{"The Beatles", "The Supremes", "YellowMatterCustard"}</PRE></TD></TR>
<TR>
<TD><PRE>{"A Hard Days Night", "A Bit Of Liverpool", "One Night In NYC"}</PRE></TD></TR>
<TR>
<TD><PRE>{"Twelve", "Siete", "7"}</PRE></TD></TR>
<TR>
<TD><PRE>{"You Cant Do That", "You Cant Do That", "You Cant Do That"}</PRE></TD></TR>
<TR>
<TD><PRE>"S (S) S"</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: 
{"You Cant Do That (You Cant Do That) You Cant Do That",
 "You Cant Do That (You Cant Do That) You Cant Do That",
 "You Cant Do That (You Cant Do That) You Cant Do That" }</PRE></TD></TR>
<TR>
<TD></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>{"  The Leading Spaces"}</PRE></TD></TR>
<TR>
<TD><PRE>{"  "}</PRE></TD></TR>
<TR>
<TD><PRE>{"Trailing Space  "}</PRE></TD></TR>
<TR>
<TD><PRE>{" s p a  c e s "}</PRE></TD></TR>
<TR>
<TD><PRE>"S._A_B(T)"</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: {" s p a  c e s ._  The Leading Spaces_  (Trailing Space  )" }</PRE></TD></TR>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD colSpan=2>Preserve all spaces. </TD></TR></TBODY></TABLE></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>{"Ignored"}</PRE></TD></TR>
<TR>
<TD><PRE>{"Unnoticed"}</PRE></TD></TR>
<TR>
<TD><PRE>{"000"}</PRE></TD></TR>
<TR>
<TD><PRE>{"Uncredited"}</PRE></TD></TR>
<TR>
<TD><PRE>"()-(). "</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: {"()-(). " }</PRE></TD></TR>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD colSpan=2><B>format</B> doesn't necessarily have to contain any tags. </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/10997.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-08-25 11:08 <a href="http://www.blogjava.net/emu/articles/10997.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Crop(入围赛250分真题)</title><link>http://www.blogjava.net/emu/articles/10996.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Thu, 25 Aug 2005 03:04:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/10996.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/10996.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/10996.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/10996.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/10996.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>You are given a black and white image in a String[], <B>image</B>. Character j of element i (both 0-based indices) of <B>image</B> represents the pixel in row i, column j. 'X' characters represent black pixels and '.' characters represent white pixels. You are given a String[], <B>crops</B>, which contains a series of rectangular crop operations that are performed on the image. Cropping is an operation that trims an image so that only the specified area of the original image remains. Each element of <B>crops</B> is formatted as "r1 c1 r2 c2" (quotes for clarity only), where the upper left corner of the area to crop is at row r1, column c1, and the lower right corner is at row r2, column c2. The coordinates are inclusive. The crop operations are performed in the order that they appear in <B>crops</B>, and each one is performed on the most recent version of the image. The constraints will guarantee that all crop operations will be within the boundaries of the image. Return the final cropped image as a String[] in the same format as the original image String[]. </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>Crop </TD></TR>
<TR>
<TD>Method: </TD>
<TD>crop </TD></TR>
<TR>
<TD>Parameters: </TD>
<TD>String[], String[] </TD></TR>
<TR>
<TD>Returns: </TD>
<TD>String[] </TD></TR>
<TR>
<TD>Method signature: </TD>
<TD>String[] crop(String[] image, String[] crops) </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>image</B> will contain between 1 and 50 elements, inclusive. </TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD>Each element of <B>image</B> will contain between 1 and 50 characters, inclusive. </TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD>Each element of <B>image</B> will contain exactly the same number of characters. </TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD>Each element of <B>image</B> will contain only '.' and uppercase 'X' characters. </TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD><B>crops</B> will contain between 1 and 10 elements, inclusive. </TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD>Each element of <B>crops</B> will be formatted as described in the problem statement and no integers within <B>crops</B> will contain extra leading zeros. </TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD>Within each element of <B>crops</B>, r2 will be greater than or equal to r1 and c2 will be greater than or equal to c1. </TD></TR>
<TR>
<TD vAlign=top align=middle>- </TD>
<TD><B>crops</B> will contain no operations that exceed the boundaries of the image at any time in the cropping process. </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>{".........",
 "X.XXXXXXX",
 "....X....",
 "........." }</PRE></TD></TR>
<TR>
<TD><PRE>{"1 0 2 8", "0 0 1 1"}</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: {"X.", ".." }</PRE></TD></TR>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD colSpan=2>The first crop effectively removes the top and bottom rows of the image and results in: 
<P></P><PRE>X.XXXXXXX
....X....</PRE>
<P></P>The second crop is then performed relative to the new image: 
<P></P><PRE>X.
..</PRE></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>{"X.X.X.X.X.X.X.X",
 ".X.X.X.X.X.X.X."}</PRE></TD></TR>
<TR>
<TD><PRE>{"0 0 1 14", "0 0 1 14", "0 0 1 14"}</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: {"X.X.X.X.X.X.X.X", ".X.X.X.X.X.X.X." }</PRE></TD></TR>
<TR>
<TD>
<TABLE>
<TBODY>
<TR>
<TD colSpan=2>These crops don't affect the original image at all. </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>{".X..X.X.XX.",
 "..X..X...X.",
 "X......X..X",
 ".X....X...X",
 "..XXXX.X.X.",
 "XXX..XXX..X"}</PRE></TD></TR>
<TR>
<TD><PRE>{"0 0 0 0"}</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: {"." }</PRE></TD></TR>
<TR>
<TD></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>{".X..X.X.XX.",
 "..X..X...X.",
 "X......X..X",
 ".X....X...X",
 "..XXXX.X.X.",
 "XXX..XXX..X"}</PRE></TD></TR>
<TR>
<TD><PRE>{"1 0 5 9", "0 1 4 8", "0 0 3 5"}</PRE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><PRE>Returns: {".X..X.", "......", "X....X", ".XXXX." }</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/10996.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-08-25 11:04 <a href="http://www.blogjava.net/emu/articles/10996.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>URLParser(入围赛250分真题)</title><link>http://www.blogjava.net/emu/articles/10808.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 23 Aug 2005 08:38:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/10808.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/10808.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/10808.html#Feedback</comments><slash:comments>10</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/10808.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/10808.html</trackback:ping><description><![CDATA[<P><BR>Problem Statement<BR>????<BR>When a web client (like a browser) requests a particular web page, it typically replaces certain characters with escape sequences. For instance, spaces are replaced with "%20". Your task is to reverse this, replacing every escape sequence in the input with the character it represents. Each escape sequence is formatted as "%XX" where XX is the ASCII value of the escaped character in hexadecimal.<BR>Definition<BR>????<BR>Class:<BR>URLParser<BR>Method:<BR>parse<BR>Parameters:<BR>String<BR>Returns:<BR>String<BR>Method signature:<BR>String parse(String url)<BR>(be sure your method is public)<BR>????</P>
<P>Constraints<BR>-<BR>url will contain between 1 and 50 characters, inclusive.<BR>-<BR>Each '%' in the input will be followed by a hexadecimal value between 20 (hex) and 7E (letters will be uppercase).<BR>-<BR>Each character in the input will have ASCII value between 32 and 126, inclusive.<BR>Examples<BR>0)</P>
<P>????<BR>"<A href="http://www.%20%40%20%40%20.com/%25">http://www.%20%40%20%40%20.com/%25</A>"<BR>Returns: "<A href="http://www">http://www</A>. @ @ .com/%"<BR>"%20" is the escape sequence for ' ', while "%40" stands for <A href="mailto:'@'">'@'</A> and "%25" stands for '%'.<BR>1)</P>
<P>????<BR>"%20%21%22%23%24%25%26%27%28"<BR>Returns: " !\"#$%&amp;'("</P>
<P>2)</P>
<P>????<BR>"%48%65%6C%6C%6F%20%57%6F%72%6C%64%21"<BR>Returns: "Hello World!"</P>
<P>3)</P>
<P>????<BR>"%2525"<BR>Returns: "%25"</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/10808.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-08-23 16:38 <a href="http://www.blogjava.net/emu/articles/10808.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>NewStation(入围赛750分真题)</title><link>http://www.blogjava.net/emu/articles/10807.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 23 Aug 2005 08:37:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/10807.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/10807.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/10807.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/10807.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/10807.html</trackback:ping><description><![CDATA[<P><BR>Problem Statement<BR>????<BR>You are given a String[], grid, representing a city where each character in grid is a single city block. Each block will contain a digit representing the relative population on that block. For example, a block containing the digit '6' will contain three times as many people as a block containing the digit '2'. You are also given a String[], stations, containing the locations of all the fire stations within the city. Each element of stations is formatted as "r c" (quotes for clarity only), where r and c represent the row and column, respectively, of the block on which a fire station is located. Character j of element i of grid represents the block at row i, column j. All indices are 0-based.</P>
<P>The city has received enough funds to build one additional fire station, and the mayor has decided that it is most important to minimize the average distance between a person and the closest fire station to that person. The metric used to determine the distance between two locations in the city is the Manhattan distance between the two blocks on which the locations are situated. The Manhattan distance between two blocks (r1, c1) and (r2, c2) is |r1-r2|+|c1-c2| (the vertical bars represent absolute value). Determine the block on which the new station should be built and return its row and column formatted as "r c" (quotes for clarity only). The return String should contain no extra leading zeros. If multiple blocks are equally optimal, return the one with the lowest row, and if multiple optimal blocks have the same lowest row, return the one among them with the lowest column. If adding an additional fire station would not reduce the average distance between a person and the closest fire station to that person, return the empty String ("").<BR>Definition<BR>????<BR>Class:<BR>NewStation<BR>Method:<BR>location<BR>Parameters:<BR>String[], String[]<BR>Returns:<BR>String<BR>Method signature:<BR>String location(String[] grid, String[] stations)<BR>(be sure your method is public)<BR>????</P>
<P>Constraints<BR>-<BR>grid will contain between 1 and 20 elements, inclusive.<BR>-<BR>Each element of grid will contain between 1 and 20 characters, inclusive.<BR>-<BR>Each element of grid will contain exactly the same number of characters.<BR>-<BR>Each element of grid will contain only digits ('0'-'9').<BR>-<BR>At least one character in grid will be non-zero.<BR>-<BR>stations will contain between 1 and 10 elements, inclusive.<BR>-<BR>Each element of stations will be formatted as "r c" (quotes for clarity only), where r and c are each integers between 0 and 19, inclusive, with no leading zeros.<BR>-<BR>Each element of stations will represent a location within the boundaries of grid.<BR>Examples<BR>0)</P>
<P>????<BR>{"111",<BR>&nbsp;"111",<BR>&nbsp;"111"}<BR>{"1 1"}<BR>Returns: "0 1"<BR>There's an existing station at (1, 1) and each block contains exactly the same number of people. Placing a new station at either (0, 1), (1, 0), (1, 2), or (2, 1) would minimize the average distance. (0, 1) is chosen since it has the lowest row. Adding the new station reduces the average distance from approximately 1.33 to 1.0. The distance from each block to the nearest station becomes:<BR>101<BR>101<BR>212<BR>1)</P>
<P>????<BR>{"111",<BR>&nbsp;"111",<BR>&nbsp;"111"}<BR>{"0 0", "0 1", "0 2",<BR>&nbsp;"1 0", "1 1", "1 2",<BR>&nbsp;"2 0", "2 1", "2 2"}<BR>Returns: ""<BR>There's a fire station on every block, so adding a new station would not reduce the average distance.<BR>2)</P>
<P>????<BR>{"2312",<BR>&nbsp;"0233"}<BR>{"1 3"}<BR>Returns: "0 1"<BR>Placing a fire station at (0, 1) would make the average distance 0.625.<BR>3)</P>
<P>????<BR>{"2312",<BR>&nbsp;"0233"}<BR>{"1 1", "1 1"}<BR>Returns: "0 3"</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/10807.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-08-23 16:37 <a href="http://www.blogjava.net/emu/articles/10807.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SalesFigures(入围赛250分真题)</title><link>http://www.blogjava.net/emu/articles/10795.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 23 Aug 2005 07:04:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/10795.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/10795.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/10795.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/10795.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/10795.html</trackback:ping><description><![CDATA[<P><BR>Problem Statement<BR>????<BR>A company stores sales data in a single, cumbersome file. Each line of the file represents one sale and is formatted as:<BR>&nbsp;&nbsp;&nbsp; CLIENT_ID CNT_1 PRODUCT_1 CNT_2 PRODUCT_2 ...<BR>This indicates that CNT_1 units of PRODUCT_1 were sold to the client whose id is CLIENT_ID, and CNT_2 units of PRODUCT_2 and so on. You have been tasked with figuring out how many units of a particular product have been sold over time to a particular client. You will be given a String[] sales, a String, client, and a String, product. You are to return an int representing how many units of product were sold to client in sales.<BR>Definition<BR>????<BR>Class:<BR>SalesFigures<BR>Method:<BR>getCount<BR>Parameters:<BR>String[], String, String<BR>Returns:<BR>int<BR>Method signature:<BR>int getCount(String[] sales, String client, String product)<BR>(be sure your method is public)<BR>????</P>
<P>Constraints<BR>-<BR>sales will contain between 1 and 50 elements, inclusive.<BR>-<BR>Each element of sales will be formatted as described in the problem statement, with at least 1 product and at most 50 characters.<BR>-<BR>CLIENT_ID and each PRODUCT_* will contain between 1 and 10 uppercase letters ('A'-'Z'), inclusive.<BR>-<BR>Each CNT_* will represent an integer between 1 and 999, inclusive, with no leading zeros.<BR>-<BR>client will contain between 1 and 10 uppercase letters ('A'-'Z'), inclusive.<BR>-<BR>product will contain between 1 and 10 uppercase letters ('A'-'Z'), inclusive.<BR>Examples<BR>0)</P>
<P>????<BR>{"BOB 1 SHOE",<BR>&nbsp;"JOHN 2 SHOE",<BR>&nbsp;"BOB 3 SHOE 1 HORSE"}<BR>"BOB"<BR>"SHOE"<BR>Returns: 4</P>
<P>1)</P>
<P>????<BR>{"MEG 1 TV 1 VCR 10 DVD 3 DVD",<BR>&nbsp;"HARRY 2 TV 6 DVD",<BR>&nbsp;"MEG 11 DVD",<BR>&nbsp;"MEG 2 TV",<BR>&nbsp;"HARRY 101 DVD"}<BR>"MEG"<BR>"DVD"<BR>Returns: 24<BR>Note that "DVD" occurs twice in the first element.<BR>2)</P>
<P>????<BR>{"GEORGE 999 PETS"}<BR>"BOB"<BR>"SHOE"<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/10795.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-08-23 15:04 <a href="http://www.blogjava.net/emu/articles/10795.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SongFilter (入围赛250真题)</title><link>http://www.blogjava.net/emu/articles/10781.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 23 Aug 2005 03:47:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/10781.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/10781.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/10781.html#Feedback</comments><slash:comments>9</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/10781.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/10781.html</trackback:ping><description><![CDATA[<P><BR>Problem Statement<BR>????<BR>You have a collection of music files with names formatted as "genre-artist-album-song" (quotes for clarity only), where genre, artist, album, and song each consist of only lowercase letters ('a'-'z') and spaces (but no leading/trailing spaces). The collection is given in the String[] collection. You would like to filter the songs according to a set of criteria given in the String[] filterInfo. Each element of filterInfo is an equality check formatted as "field=value" (quotes for clarity only), where field is "genre", "artist", "album", or "song", and value consists of only lowercase letters ('a'-'z') and spaces (but no leading/trailing spaces). For a file to pass through the filter, it must satisfy every equality check in filterInfo. For example, if filterInfo = {"genre=country", "album=greatest hits"}, only songs from country greatest hits albums should be returned. Return a String[] containing all the files that meet the given criteria in the same relative order as they appear in collection.<BR>Definition<BR>????<BR>Class:<BR>SongFilter<BR>Method:<BR>filter<BR>Parameters:<BR>String[], String[]<BR>Returns:<BR>String[]<BR>Method signature:<BR>String[] filter(String[] collection, String[] filterInfo)<BR>(be sure your method is public)<BR>????</P>
<P>Constraints<BR>-<BR>collection will contain between 1 and 50 elements, inclusive.<BR>-<BR>Each element of collection will be formatted as described in the problem statement.<BR>-<BR>Each element of collection will contain between 7 and 50 characters, inclusive.<BR>-<BR>Each genre, artist, album, and song in collection will contain between 1 and 20 characters, inclusive.<BR>-<BR>collection will contain no duplicate elements.<BR>-<BR>filterInfo will contain between 1 and 4 elements, inclusive.<BR>-<BR>Each element of filterInfo will be formatted as described in the problem statement.<BR>-<BR>Each value in filterInfo will contain between 1 and 20 characters, inclusive.<BR>Examples<BR>0)</P>
<P>????<BR>{"jazz-joe pass-virtuoso-cherokee",<BR>&nbsp;"rock-led zeppelin-ii-lemon song",<BR>&nbsp;"country-dwight yoakam-long way home-things change",<BR>&nbsp;"metal-iron maiden-powerslave-aces high",<BR>&nbsp;"pop-supremes-more hits-ask any girl",<BR>&nbsp;"rock-faith no more-angel dust-rv",<BR>&nbsp;"jazz-chuck mangione-feels so good-feels so good",<BR>&nbsp;"rock-van halen-ii-spanish fly"}<BR>{"genre=rock", "album=ii"}<BR>Returns: {"rock-led zeppelin-ii-lemon song", "rock-van halen-ii-spanish fly" }<BR>This filter returns all the rock songs from albums with the title "ii".<BR>1)</P>
<P>????<BR>{"rock-jimi hendrix-axis bold as love-little wing",<BR>&nbsp;"rock-cars-cars-moving in stereo",<BR>&nbsp;"rock-jimi hendrix-electric ladyland-gypsy eyes",<BR>&nbsp;"blues-albert collins-ice pickin-ice pick",<BR>&nbsp;"rock-jimi hendrix-axis bold as love-bold as love",<BR>&nbsp;"rock-jimi&nbsp; hendrix-axis bold as love-exp"}<BR>{"artist=jimi hendrix", "album=axis bold as love"}<BR>Returns: <BR>{"rock-jimi hendrix-axis bold as love-little wing",<BR>&nbsp;"rock-jimi hendrix-axis bold as love-bold as love" }<BR>This filter returns all the songs that are from the album "axis bold as love" by the artist "jimi hendrix". The last element in the collection is not returned because there are two spaces between "jimi" and "hendrix".<BR>2)</P>
<P>????<BR>{"rock-ozzy osbourne-blizzard of ozz-dee",<BR>&nbsp;"rock-marvelous three-hey album-let me go",<BR>&nbsp;"rock-cheap trick-in color-downed"}<BR>{"genre=soul"}<BR>Returns: { }<BR>There is no soul music in this collection, so an empty String[] is returned.<BR>3)</P>
<P>????<BR>{"country-topcoder-the country album-twangy",<BR>&nbsp;"rock-topcoder-the rock album-rockin",<BR>&nbsp;"jazz-topcoder-the jazz album-jazzy",<BR>&nbsp;"soul-topcoder-the soul album-soulful",<BR>&nbsp;"metal-topcoder-the metal album-thrash"}<BR>{"artist=topcoder", "genre=jazz", "album=the jazz album", "song=jazzy"}<BR>Returns: {"jazz-topcoder-the jazz album-jazzy" }</P>
<P>4)</P>
<P>????<BR>{"pop-jackson five-abc-the love you save",<BR>&nbsp;"rock-ac dc-powerage-riff raff"}<BR>{"genre=pop", "genre=rock"}<BR>Returns: { }<BR>No single element of collection can represent more than one genre, so this filter returns an empty String[].<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/10781.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-08-23 11:47 <a href="http://www.blogjava.net/emu/articles/10781.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ImageLayers（入围赛750分真题）</title><link>http://www.blogjava.net/emu/articles/10779.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 23 Aug 2005 03:44:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/10779.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/10779.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/10779.html#Feedback</comments><slash:comments>12</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/10779.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/10779.html</trackback:ping><description><![CDATA[<P><BR><BR>Problem Statement<BR>????<BR>An image editing application allows users to construct images containing multiple layers. When dealing with large images, however, it is sometimes necessary to limit the number of layers due to memory constraints. If certain layers will not be altered during an editing session, they can be merged together to reduce the total number of layers in memory. You are given a macro containing commands to open files and merge layers. Each time a file is opened, it is loaded into a new layer of the current image. Layers are numbered starting at 0 for the bottommost layer, 1 for the layer directly on top of the bottommost layer, etc... Whenever a new layer is created, it is positioned on top of the previous topmost layer. An open command is formatted as "OPEN filename" where filename is the name of the file to open. Consecutive layers can be merged using the merge command, which is formatted as "MERGE layer1-layer2", where layer1 and layer2 specify an inclusive range of layer numbers that exist in the current image. After multiple layers are merged, all the layers are renumbered according to the original specification. For example, if an image contains four layers (0, 1, 2, 3), and layers 1 and 2 are merged into a single layer, the final image will contain three layers numbered 0, 1, 2 from bottom to top, where layer 0 is the same as before, layer 1 was previously layers 1 and 2, and layer 2 was previously layer 3.</P>
<P>Given the String[] macro, perform all the operations in the macro in order and return the final state of the image layers as a String[]. The String[] should contain exactly the same number of elements as there are layers in the final image, and each element i should correspond to the ith layer. Each element of the String[] should be a single space delimited list of the filenames contained in that layer. The filenames should be sorted in alphabetical order within each layer.<BR>Definition<BR>????<BR>Class:<BR>ImageLayers<BR>Method:<BR>contents<BR>Parameters:<BR>String[]<BR>Returns:<BR>String[]<BR>Method signature:<BR>String[] contents(String[] macro)<BR>(be sure your method is public)<BR>????</P>
<P>Constraints<BR>-<BR>macro will contain between 1 and 50 elements, inclusive.<BR>-<BR>Each element of macro will be formatted as either "OPEN filename" or "MERGE layer1-layer2".<BR>-<BR>Each filename in macro will contain between 1 and 15 lowercase letters ('a'-'z'), inclusive.<BR>-<BR>Each layer1 and layer2 in macro will be integers between 0 and n-1, inclusive, with no leading zeros, where n is the number of layers that exist in the image immediately before the command is executed.<BR>-<BR>Within each element of macro that represents a merge command, layer1 will be less than layer2.<BR>-<BR>The first element of macro will be an OPEN command.<BR>Examples<BR>0)</P>
<P>????<BR>{"OPEN background",<BR>&nbsp;"OPEN aone",<BR>&nbsp;"OPEN atwo",<BR>&nbsp;"OPEN foreground",<BR>&nbsp;"MERGE 0-2",<BR>&nbsp;"OPEN border"}<BR>Returns: {"aone atwo background", "foreground", "border" }<BR>After the first four commands in macro are executed, the layers are (from bottom to top):</P>
<P>0. background 1. aone 2. atwo 3. foreground</P>
<P>The merge command combines the bottom three layers into a single layer. There are now only two layers (from bottom to top):</P>
<P>0. background aone atwo 1. foreground</P>
<P>Finally, one last file is opened and placed in a new layer on top. The final return value contains the filenames within each layer sorted alphabetically:</P>
<P>0. aone atwo background 1. foreground 2. border<BR>1)</P>
<P>????<BR>{"OPEN sky",<BR>&nbsp;"OPEN clouds",<BR>&nbsp;"OPEN ground",<BR>&nbsp;"MERGE 0-1",<BR>&nbsp;"OPEN grass",<BR>&nbsp;"MERGE 0-2",<BR>&nbsp;"OPEN trees",<BR>&nbsp;"OPEN leaves",<BR>&nbsp;"OPEN birds",<BR>&nbsp;"MERGE 1-2",<BR>&nbsp;"MERGE 0-1"}<BR>Returns: {"clouds grass ground leaves sky trees", "birds" }</P>
<P>2)</P>
<P>????<BR>{"OPEN a", "OPEN b", "OPEN a", "OPEN a", "MERGE 0-3"}<BR>Returns: {"a a a b" }</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/10779.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-08-23 11:44 <a href="http://www.blogjava.net/emu/articles/10779.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DiskDefrag(赛前模拟题)</title><link>http://www.blogjava.net/emu/articles/10196.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 16 Aug 2005 01:30:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/10196.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/10196.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/10196.html#Feedback</comments><slash:comments>16</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/10196.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/10196.html</trackback:ping><description><![CDATA[<P>Problem Statement<BR>????<BR>When files are stored on a hard disk, they often become fragmented. This means that the file is not stored in sequential sectors on the disk. The first half of a file might be stored in sector 243, while the second half of a file might be far away in sector 105. The goal of defragmenting a hard drive is to arrange the files so that each file is stored in order on sequential sectors of the disk. Thus, if a file required 4 sectors of storage space, it would end up in sectors N, N+1, N+2, and N+3, for some N. Typically, this is done to increase the overall speed of the computer.&nbsp; There are a number of programs that will defrag a hard disk as described above. However, many of them are painfully slow. You are trying to develop a new algorithm to defrag hard drives, but before you start, you would like to determine how fast you can defrag a very small drive without very many files on it. You will be given the locations of a number of files on a small hard disk, and are to determine the minimum number of sectors that must be moved before the entire drive is defragged. You have enough memory to hold two sectors worth of data at once, but that is all.&nbsp; You will be given a String[], disk, each of whose elements represents a single file. Each element of disk will be formatted as a single-space delimited list of integers which represent the locations of the parts of the file, in order. Hence, the String, "4 9 6 59 41" represents a file stored in 5 sectors where the first part of the file is in sector 4 of the disk. One way to defrag this file would be to move the contents of sector 9 to sector 5, the contents of sector 59 to sector 7, and the contents of sector 41 to sector 8. By doing this, the file would be stored sequentially in sectors 4-8. You will also be given an int, size, representing the total number of sectors on the disk (sectors 0 through size-1, inclusive, may contain data). You are to return the smallest number of sectors that must be moved to defragment the whole disk. Keep in mind that you can not move data to a sector until any data being stored there is moved.<BR>Definition<BR>????<BR>Class:<BR>DiskDefrag<BR>Method:<BR>minMoves<BR>Parameters:<BR>String[], int<BR>Returns:<BR>int<BR>Method signature:<BR>int minMoves(String[] disk, int size)<BR>(be sure your method is public)<BR>????</P>
<P>Constraints<BR>-<BR>size will be between 10 and 100, inclusive.<BR>-<BR>disk will contain between 1 and 12 elements, inclusive.<BR>-<BR>Each element of disk will contain between 1 and 50 characters, inclusive.<BR>-<BR>Each element of disk will be a single-space delimited list of integers, without extraneous leading zeros.<BR>-<BR>Each integer in disk will be between 0 and size-1, inclusive.<BR>-<BR>No integer will be appear more than once in disk.<BR>Examples<BR>0)</P>
<P>????<BR>{"3 4 5 6 8 9 10","17 16 15"}<BR>20<BR>Returns: 5<BR>We can defrag the first file by moving the contents of sector 8 to sector 7, then 9 to 8, and finally 10 to 9. The second file can be defragged in a number of ways by moving the contents of two sectors, for a total of 5.<BR>1)</P>
<P>????<BR>{"1 2 3 5 4 6 7 8"}<BR>10<BR>Returns: 2<BR>Here we can take advantage of the fact that we have enough memory to hold two sectors worth of data. First, load the contents of sectors 4 and 5 into memory. Now, simply write the data back in the reverse order.<BR>2)</P>
<P>????<BR>{"1 3 5 7","0 2 4 8","6 9"}<BR>100<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/10196.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-08-16 09:30 <a href="http://www.blogjava.net/emu/articles/10196.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SimpleRouter(赛前模拟题)</title><link>http://www.blogjava.net/emu/articles/10195.html</link><dc:creator>emu</dc:creator><author>emu</author><pubDate>Tue, 16 Aug 2005 01:30:00 GMT</pubDate><guid>http://www.blogjava.net/emu/articles/10195.html</guid><wfw:comment>http://www.blogjava.net/emu/comments/10195.html</wfw:comment><comments>http://www.blogjava.net/emu/articles/10195.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/emu/comments/commentRss/10195.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/emu/services/trackbacks/10195.html</trackback:ping><description><![CDATA[<P>Problem Statement<BR>????<BR>A router's job is to route packets of information to the correct computer. In addition, a router may throw out some packets, or handle the packets on its own. In this problem, you are to implement the software for a simple, rule-based router. Each rule in the router will take one of the following forms (quotes and angle brackets for clarity only):<BR>"ACCEPT &lt;IP_RANGE&gt; &lt;PORT_RANGE&gt;"<BR>"REJECT &lt;IP_RANGE&gt; &lt;PORT_RANGE&gt;"<BR>"FORWARD &lt;IP_RANGE&gt; &lt;PORT_RANGE&gt; &lt;DESTINATION&gt; (&lt;PORT&gt;)"<BR>Each &lt;IP_RANGE&gt; is a string of exactly four &lt;NUMBER_RANGE&gt;s, separated by periods, and each &lt;PORT_RANGE&gt; consists of a single &lt;NUMBER_RANGE&gt;. A &lt;NUMBER_RANGE&gt; can take one of three forms. It may be a single integer, a range of integers (in the form "&lt;LOWER_LIMIT&gt;-&lt;UPPER_LIMIT&gt;", where both limits are inclusive), or an asterisk. &lt;DESTINATION&gt; consists of exactly 4 integers, with 3 periods separating them (an IP address). If a FORWARD rule has a &lt;PORT_RANGE&gt; with only a single integer, then the &lt;DESTINATION&gt; may optionally be followed by a single integer, &lt;PORT&gt;.&nbsp; Each rule tells the router what to do with a packet of information if that packet comes from an IP in the rule's &lt;IP_RANGE&gt; and to a port in the rule's &lt;PORT_RANGE&gt;. An IP is in the &lt;IP_RANGE&gt; if each &lt;NUMBER_RANGE&gt; in the &lt;IP_RANGE&gt; matches the corresponding number in the IP. A &lt;NUMBER_RANGE&gt; matches a number, N, if the &lt;NUMBER_RANGE&gt; is an asterisk, if it is a single number that is the same as N, or if it is a range and N falls within the range, inclusive. The rules for matching a &lt;PORT_RANGE&gt; are the same.&nbsp; If a rule tells the router to forward the packet, then it should be forwarded to &lt;DESTINATION&gt;. If no &lt;PORT&gt; is specified, the packet should be forwarded to the same port it was received on. Otherwise, it should be forwarded to the specified port. If multiple rules apply to a packet, you should use the one that comes last in the input. If no rules apply, REJECT the packet.&nbsp; You will be given a String[], rules, representing a number of rules that the router is to follow. You will also be given a String[], packets, each of whose elements represents a packet of data in the form "&lt;SOURCE_IP&gt; &lt;PORT&gt;" (&lt;SOURCE_IP&gt; is formatted the same as &lt;DESTINATION&gt;). You should return a String[] with one element per packet, specifying what to do with the packet with the same index in the input as the return. Each element of the return should be either "ACCEPT", "REJECT", or "&lt;IP&gt;:&lt;PORT&gt;", where &lt;IP&gt; and &lt;PORT&gt; represent the location to which the packet should be forwarded.<BR>Definition<BR>????<BR>Class:<BR>SimpleRouter<BR>Method:<BR>route<BR>Parameters:<BR>String[], String[]<BR>Returns:<BR>String[]<BR>Method signature:<BR>String[] route(String[] rules, String[] packets)<BR>(be sure your method is public)<BR>????</P>
<P>Notes<BR>-<BR>While the input may have extraneous leading zeros, your return should not.<BR>Constraints<BR>-<BR>rules will contain between 1 and 50 elements, inclusive.<BR>-<BR>Each element of rules will be formatted as described in the problem statement.<BR>-<BR>packets will contain between 1 and 50 elements, inclusive.<BR>-<BR>Each element of packets will be formatted as described in the problem statement.<BR>-<BR>Each of the four numbers in an IP address, or a number range in an IP address will be between 0 and 255, inclusive.<BR>-<BR>Each port or number in a port range will be between 1 and 65535 inclusive.<BR>-<BR>In any &lt;NUMBER_RANGE&gt; with two numbers, &lt;LOWER_LIMIT&gt; will be less than or equal to &lt;UPPER_LIMIT&gt;.<BR>Examples<BR>0)</P>
<P>????<BR>{"FORWARD 192.168.000.* 001-100 192.168.0.10",<BR>&nbsp;"FORWARD 192.168.0.1 80 10.10.95.184 8080",<BR>&nbsp;"ACCEPT 192.168.*.* 25",<BR>&nbsp;"REJECT 192.168.5.38 *"}<BR>{"192.168.0.43 80",<BR>&nbsp;"00192.00168.000.001 00080",<BR>&nbsp;"192.168.0.1 110",<BR>&nbsp;"192.168.1.73 80",<BR>&nbsp;"192.168.1.73 25",<BR>&nbsp;"206.26.210.5 53",<BR>&nbsp;"192.168.5.38 25"<BR>&nbsp;}<BR>Returns: <BR>{ "192.168.0.10:80",<BR>&nbsp; "10.10.95.184:8080",<BR>&nbsp; "REJECT",<BR>&nbsp; "REJECT",<BR>&nbsp; "ACCEPT",<BR>&nbsp; "REJECT",<BR>&nbsp; "REJECT" }<BR>Packet 0 matches rule 0, and gets forwarded according to that rule. Packet 1 matches both rules 0 and 1, so rule 1 is applied. Packets 2, 3, and 5 don't match any rules, so they are rejected. Packet 4 matches rule 2, and is therefore accepted. Packet 6 matches rules 2 and 3, so it gets rejected (rule 3 is applied).<BR>1)</P>
<P>????<BR>{"FORWARD *.*.*.* * 192.168.0.1"}<BR>{"213.148.161.82 9484",<BR>&nbsp;"172.230.108.145 16627",<BR>&nbsp;"122.141.122.130 46874",<BR>&nbsp;"241.145.145.77 26390",<BR>&nbsp;"139.97.106.125 35305",<BR>&nbsp;"244.131.151.77 26390"}<BR>Returns: <BR>{ "192.168.0.1:9484",<BR>&nbsp; "192.168.0.1:16627",<BR>&nbsp; "192.168.0.1:46874",<BR>&nbsp; "192.168.0.1:26390",<BR>&nbsp; "192.168.0.1:35305",<BR>&nbsp; "192.168.0.1:26390" }</P>
<P>2)</P>
<P>????<BR>{"REJECT *.20-252.114-157.36-91 13171-54085",<BR>&nbsp;"ACCEPT *.*.73-180.* *",<BR>&nbsp;"FORWARD 55.63.173.239 * 168.154.33.25",<BR>&nbsp;"REJECT *.72-73.*.48-191 *",<BR>&nbsp;"REJECT 20.51.*.* 4579",<BR>&nbsp;"ACCEPT 70-166.*.*.86-182 *",<BR>&nbsp;"REJECT 88-190.*.119-157.* 3316-27844",<BR>&nbsp;"FORWARD *.52-221.134-250.66-207 * 116.94.120.82"}<BR>{"203.11.104.45 44072",<BR>&nbsp;"154.92.128.87 30085",<BR>&nbsp;"20.51.68.55 4579",<BR>&nbsp;"177.73.138.69 14319",<BR>&nbsp;"112.65.145.82 26287",<BR>&nbsp;"55.63.173.239 45899"}<BR>Returns: <BR>{ "ACCEPT",<BR>&nbsp; "ACCEPT",<BR>&nbsp; "REJECT",<BR>&nbsp; "116.94.120.82:14319",<BR>&nbsp; "116.94.120.82:26287",<BR>&nbsp; "168.154.33.25:45899" }</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></P><img src ="http://www.blogjava.net/emu/aggbug/10195.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-08-16 09:30 <a href="http://www.blogjava.net/emu/articles/10195.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>