﻿<?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>C++博客-Vontroy</title><link>http://www.cppblog.com/vontroy/</link><description /><language>zh-cn</language><lastBuildDate>Sun, 05 Apr 2026 17:27:36 GMT</lastBuildDate><pubDate>Sun, 05 Apr 2026 17:27:36 GMT</pubDate><ttl>60</ttl><item><title>POJ 2488 A Knight's Journey (DFS)</title><link>http://www.cppblog.com/vontroy/archive/2016/08/31/214245.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Wed, 31 Aug 2016 02:16:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2016/08/31/214245.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/214245.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2016/08/31/214245.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/214245.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/214245.html</trackback:ping><description><![CDATA[<p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, Verdana, Arial, sans-serif; line-height: 23.8px; background-color: #ffffff;"><span style="font-family: Courier;">输入一个棋盘 ( p &#215; q )，从任意点开始，每次走日子格，求能走遍每个点的序列，以Sample中给出的样式按字典序输出，如果得不到这样的序列输出impossible</span></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, Verdana, Arial, sans-serif; line-height: 23.8px; background-color: #ffffff;"><span style="font-family: Courier;">由于要按字典序输出，所以优先访问坐标较小的点，第一次得到的序列就是所求结果</span></p><div style="font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; background-color: #eeeeee;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="font-family: Courier;">#include&nbsp;&lt;</span><span style="font-family: Courier;">iostream</span><span style="font-family: Courier;">&gt;</span><br /><span style="font-family: Courier;">#include&nbsp;</span><span style="font-family: Courier;">&lt;</span><span style="font-family: Courier;">cstdio</span><span style="font-family: Courier;">&gt;</span><br /><span style="font-family: Courier;">#include&nbsp;</span><span style="font-family: Courier;">&lt;</span><span style="font-family: Courier;">cstring</span><span style="font-family: Courier;">&gt;</span><br /><span style="font-family: Courier;">#include&nbsp;</span><span style="font-family: Courier;">&lt;</span><span style="font-family: Courier;">vector</span><span style="font-family: Courier;">&gt;</span><br />&nbsp;<br /><span style="color: #0000ff; font-family: Courier;">using</span>&nbsp;<span style="color: #0000ff; font-family: Courier;">namespace</span><span style="font-family: Courier;">&nbsp;std;</span><br />&nbsp;<br /><span style="color: #0000ff; font-family: Courier;">int</span>&nbsp;<span style="color: #0000ff; font-family: Courier;">const</span><span style="font-family: Courier;">&nbsp;maxn&nbsp;</span><span style="font-family: Courier;">=</span>&nbsp;<span style="font-family: Courier;">30</span><span style="font-family: Courier;">;</span><br />&nbsp;<br /><span style="color: #0000ff; font-family: Courier;">bool</span><span style="font-family: Courier;">&nbsp;vis[maxn][maxn];</span><br /><span style="color: #0000ff; font-family: Courier;">int</span><span style="font-family: Courier;">&nbsp;p,&nbsp;q;</span><br /><span style="color: #0000ff; font-family: Courier;">bool</span><span style="font-family: Courier;">&nbsp;flag&nbsp;</span><span style="font-family: Courier;">=</span>&nbsp;<span style="color: #0000ff; font-family: Courier;">false</span><span style="font-family: Courier;">;</span><br />&nbsp;<br /><span style="color: #0000ff; font-family: Courier;">int</span>&nbsp;<span style="color: #0000ff; font-family: Courier;">const</span><span style="font-family: Courier;">&nbsp;steps[</span><span style="font-family: Courier;">8</span><span style="font-family: Courier;">][</span><span style="font-family: Courier;">2</span><span style="font-family: Courier;">]&nbsp;</span><span style="font-family: Courier;">=</span><span style="font-family: Courier;">&nbsp;{&nbsp;{&nbsp;</span><span style="font-family: Courier;">-</span><span style="font-family: Courier;">1</span><span style="font-family: Courier;">,&nbsp;</span><span style="font-family: Courier;">-</span><span style="font-family: Courier;">2</span><span style="font-family: Courier;">&nbsp;},&nbsp;{&nbsp;</span><span style="font-family: Courier;">1</span><span style="font-family: Courier;">,&nbsp;</span><span style="font-family: Courier;">-</span><span style="font-family: Courier;">2</span><span style="font-family: Courier;">&nbsp;},&nbsp;{&nbsp;</span><span style="font-family: Courier;">-</span><span style="font-family: Courier;">2</span><span style="font-family: Courier;">,&nbsp;</span><span style="font-family: Courier;">-</span><span style="font-family: Courier;">1</span><span style="font-family: Courier;">&nbsp;},&nbsp;{&nbsp;</span><span style="font-family: Courier;">2</span><span style="font-family: Courier;">,&nbsp;</span><span style="font-family: Courier;">-</span><span style="font-family: Courier;">1</span><span style="font-family: Courier;">&nbsp;},&nbsp;{&nbsp;</span><span style="font-family: Courier;">-</span><span style="font-family: Courier;">2</span><span style="font-family: Courier;">,&nbsp;</span><span style="font-family: Courier;">1</span><span style="font-family: Courier;">&nbsp;},&nbsp;{&nbsp;</span><span style="font-family: Courier;">2</span><span style="font-family: Courier;">,&nbsp;</span><span style="font-family: Courier;">1</span><span style="font-family: Courier;">&nbsp;},&nbsp;{&nbsp;</span><span style="font-family: Courier;">-</span><span style="font-family: Courier;">1</span><span style="font-family: Courier;">,&nbsp;</span><span style="font-family: Courier;">2</span><span style="font-family: Courier;">&nbsp;},&nbsp;{&nbsp;</span><span style="font-family: Courier;">1</span><span style="font-family: Courier;">,&nbsp;</span><span style="font-family: Courier;">2</span><span style="font-family: Courier;">&nbsp;}&nbsp;};</span><br />&nbsp;<br /><span style="font-family: Courier;">typedef&nbsp;</span><span style="color: #0000ff; font-family: Courier;">struct</span><span style="font-family: Courier;">&nbsp;node</span><br /><span style="font-family: Courier;">{<br /></span><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; int</span><span style="font-family: Courier;">&nbsp;x;<br /></span><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; int</span><span style="font-family: Courier;">&nbsp;y;</span><br /><span style="font-family: Courier;">}coordinate;</span><br />&nbsp;<br /><span style="color: #0000ff; font-family: Courier;">bool</span><span style="font-family: Courier;">&nbsp;judge()</span><br /><span style="font-family: Courier;">{</span><br /><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; for</span><span style="font-family: Courier;">(&nbsp;</span><span style="color: #0000ff; font-family: Courier;">int</span><span style="font-family: Courier;">&nbsp;i&nbsp;</span><span style="font-family: Courier;">=</span>&nbsp;<span style="font-family: Courier;">0</span><span style="font-family: Courier;">;&nbsp;i&nbsp;</span><span style="font-family: Courier;">&lt;</span><span style="font-family: Courier;">&nbsp;p;&nbsp;i</span><span style="font-family: Courier;">++</span><span style="font-family: Courier;">&nbsp;)<br /></span><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; for</span><span style="font-family: Courier;">(&nbsp;</span><span style="color: #0000ff; font-family: Courier;">int</span><span style="font-family: Courier;">&nbsp;j&nbsp;</span><span style="font-family: Courier;">=</span>&nbsp;<span style="font-family: Courier;">0</span><span style="font-family: Courier;">;&nbsp;j&nbsp;</span><span style="font-family: Courier;">&lt;</span><span style="font-family: Courier;">&nbsp;q;&nbsp;j</span><span style="font-family: Courier;">++</span><span style="font-family: Courier;">&nbsp;)</span><br /><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if</span><span style="font-family: Courier;">(&nbsp;</span><span style="font-family: Courier;">!</span><span style="font-family: Courier;">vis[i][j]&nbsp;)</span><br /><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return</span>&nbsp;<span style="color: #0000ff; font-family: Courier;">false</span><span style="font-family: Courier;">;<br /></span><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; return</span>&nbsp;<span style="color: #0000ff; font-family: Courier;">true</span><span style="font-family: Courier;">;</span><br /><span style="font-family: Courier;">}</span><br />&nbsp;<br /><span style="font-family: Courier;">vector</span><span style="font-family: Courier;">&lt;</span><span style="font-family: Courier;">coordinate</span><span style="font-family: Courier;">&gt;</span><span style="font-family: Courier;">&nbsp;path;</span><br />&nbsp;<br /><span style="color: #0000ff; font-family: Courier;">void</span><span style="font-family: Courier;">&nbsp;dfs(&nbsp;</span><span style="color: #0000ff; font-family: Courier;">int</span><span style="font-family: Courier;">&nbsp;x,&nbsp;</span><span style="color: #0000ff; font-family: Courier;">int</span><span style="font-family: Courier;">&nbsp;y&nbsp;)</span><br /><span style="font-family: Courier;">{</span><br /><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; if</span><span style="font-family: Courier;">(&nbsp;flag&nbsp;)</span><br /><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; return</span><span style="font-family: Courier;">;</span><br /><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; if</span><span style="font-family: Courier;">(&nbsp;judge()&nbsp;</span><span style="font-family: Courier;">&amp;&amp;</span>&nbsp;<span style="font-family: Courier;">!</span><span style="font-family: Courier;">flag&nbsp;)&nbsp;{</span><br /><span style="font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; printf(&nbsp;</span><span style="font-family: Courier;">"</span><span style="font-family: Courier;">A1</span><span style="font-family: Courier;">"</span><span style="font-family: Courier;">&nbsp;);</span><br /><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; for</span><span style="font-family: Courier;">(&nbsp;</span><span style="color: #0000ff; font-family: Courier;">int</span><span style="font-family: Courier;">&nbsp;i&nbsp;</span><span style="font-family: Courier;">=</span>&nbsp;<span style="font-family: Courier;">0</span><span style="font-family: Courier;">;&nbsp;i&nbsp;</span><span style="font-family: Courier;">&lt;</span><span style="font-family: Courier;">&nbsp;path.size();&nbsp;i</span><span style="font-family: Courier;">++</span><span style="font-family: Courier;">&nbsp;){</span><br /><span style="font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(&nbsp;</span><span style="font-family: Courier;">"</span><span style="font-family: Courier;">%c</span><span style="font-family: Courier;">"</span><span style="font-family: Courier;">,&nbsp;path[i].y&nbsp;</span><span style="font-family: Courier;">+</span>&nbsp;<span style="font-family: Courier;">65</span><span style="font-family: Courier;">&nbsp;);</span><br /><span style="font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(&nbsp;</span><span style="font-family: Courier;">"</span><span style="font-family: Courier;">%d</span><span style="font-family: Courier;">"</span><span style="font-family: Courier;">,&nbsp;path[i].x&nbsp;</span><span style="font-family: Courier;">+</span>&nbsp;<span style="font-family: Courier;">1</span><span style="font-family: Courier;">&nbsp;);</span><br /><span style="font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; }</span><br /><span style="font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; puts(</span><span style="font-family: Courier;">""</span><span style="font-family: Courier;">);</span><br /><span style="font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; flag&nbsp;</span><span style="font-family: Courier;">=</span>&nbsp;<span style="color: #0000ff; font-family: Courier;">true</span><span style="font-family: Courier;">;</span><br /><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; return</span><span style="font-family: Courier;">;</span><br /><span style="font-family: Courier;">&nbsp; &nbsp; }<br /></span><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; for</span><span style="font-family: Courier;">(&nbsp;</span><span style="color: #0000ff; font-family: Courier;">int</span><span style="font-family: Courier;">&nbsp;i&nbsp;</span><span style="font-family: Courier;">=</span>&nbsp;<span style="font-family: Courier;">0</span><span style="font-family: Courier;">;&nbsp;i&nbsp;</span><span style="font-family: Courier;">&lt;</span>&nbsp;<span style="font-family: Courier;">8</span><span style="font-family: Courier;">;&nbsp;i</span><span style="font-family: Courier;">++</span><span style="font-family: Courier;">&nbsp;)&nbsp;{</span><br /><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; int</span><span style="font-family: Courier;">&nbsp;next_x&nbsp;</span><span style="font-family: Courier;">=</span><span style="font-family: Courier;">&nbsp;x&nbsp;</span><span style="font-family: Courier;">+</span><span style="font-family: Courier;">&nbsp;steps[i][</span><span style="font-family: Courier;">0</span><span style="font-family: Courier;">];</span><br /><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; int</span><span style="font-family: Courier;">&nbsp;next_y&nbsp;</span><span style="font-family: Courier;">=</span><span style="font-family: Courier;">&nbsp;y&nbsp;</span><span style="font-family: Courier;">+</span><span style="font-family: Courier;">&nbsp;steps[i][</span><span style="font-family: Courier;">1</span><span style="font-family: Courier;">];</span><br /><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; if</span><span style="font-family: Courier;">(&nbsp;next_x&nbsp;</span><span style="font-family: Courier;">&gt;=</span>&nbsp;<span style="font-family: Courier;">0</span>&nbsp;<span style="font-family: Courier;">&amp;&amp;</span><span style="font-family: Courier;">&nbsp;next_x&nbsp;</span><span style="font-family: Courier;">&lt;</span><span style="font-family: Courier;">&nbsp;p&nbsp;</span><span style="font-family: Courier;">&amp;&amp;</span><span style="font-family: Courier;">&nbsp;next_y&nbsp;</span><span style="font-family: Courier;">&gt;=</span>&nbsp;<span style="font-family: Courier;">0</span>&nbsp;<span style="font-family: Courier;">&amp;&amp;</span><span style="font-family: Courier;">&nbsp;next_y&nbsp;</span><span style="font-family: Courier;">&lt;</span><span style="font-family: Courier;">&nbsp;q&nbsp;</span><span style="font-family: Courier;">&amp;&amp;</span>&nbsp;<span style="font-family: Courier;">!</span><span style="font-family: Courier;">vis[next_x][next_y]&nbsp;)&nbsp;{</span><br /><span style="font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; coordinate&nbsp;tmp;</span><br /><span style="font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tmp.x&nbsp;</span><span style="font-family: Courier;">=</span><span style="font-family: Courier;">&nbsp;next_x;</span><br /><span style="font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tmp.y&nbsp;</span><span style="font-family: Courier;">=</span><span style="font-family: Courier;">&nbsp;next_y;</span><br />&nbsp;<br /><span style="font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; path.push_back(&nbsp;tmp&nbsp;);</span><br /><span style="font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vis[next_x][next_y]&nbsp;</span><span style="font-family: Courier;">=</span>&nbsp;<span style="font-family: Courier;">1</span><span style="font-family: Courier;">;</span><br />&nbsp;<br /><span style="font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dfs(&nbsp;next_x,&nbsp;next_y&nbsp;);</span><br />&nbsp;<br /><span style="font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vis[next_x][next_y]&nbsp;</span><span style="font-family: Courier;">=</span>&nbsp;<span style="font-family: Courier;">0</span><span style="font-family: Courier;">;</span><br /><span style="font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; path.pop_back();</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;}</span><br />&nbsp;<span style="font-family: Courier;">}</span><br />&nbsp;<br /><span style="color: #0000ff; font-family: Courier;">int</span><span style="font-family: Courier;">&nbsp;main()</span><br /><span style="font-family: Courier;">{<br /></span><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; int</span><span style="font-family: Courier;">&nbsp;n;&nbsp;scanf(&nbsp;</span><span style="font-family: Courier;">"</span><span style="font-family: Courier;">%d</span><span style="font-family: Courier;">"</span><span style="font-family: Courier;">,&nbsp;</span><span style="font-family: Courier;">&amp;</span><span style="font-family: Courier;">n&nbsp;);</span><br />&nbsp;<br /><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; for</span><span style="font-family: Courier;">(&nbsp;</span><span style="color: #0000ff; font-family: Courier;">int</span><span style="font-family: Courier;">&nbsp;i&nbsp;</span><span style="font-family: Courier;">=</span>&nbsp;<span style="font-family: Courier;">0</span><span style="font-family: Courier;">;&nbsp;i&nbsp;</span><span style="font-family: Courier;">&lt;</span><span style="font-family: Courier;">&nbsp;n;&nbsp;i</span><span style="font-family: Courier;">++</span><span style="font-family: Courier;">&nbsp;)&nbsp;{</span><br /><span style="font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; scanf(&nbsp;</span><span style="font-family: Courier;">"</span><span style="font-family: Courier;">%d%d</span><span style="font-family: Courier;">"</span><span style="font-family: Courier;">,&nbsp;</span><span style="font-family: Courier;">&amp;</span><span style="font-family: Courier;">p,&nbsp;</span><span style="font-family: Courier;">&amp;</span><span style="font-family: Courier;">q&nbsp;);</span><br />&nbsp;<br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flag&nbsp;</span><span style="font-family: Courier;">=</span>&nbsp;<span style="color: #0000ff; font-family: Courier;">false</span><span style="font-family: Courier;">;</span><br />&nbsp;<br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&nbsp;</span><span style="font-family: Courier;">"</span><span style="font-family: Courier;">Scenario&nbsp;#%d:\n</span><span style="font-family: Courier;">"</span><span style="font-family: Courier;">,&nbsp;i&nbsp;</span><span style="font-family: Courier;">+</span>&nbsp;<span style="font-family: Courier;">1</span><span style="font-family: Courier;">&nbsp;);</span><br />&nbsp;<br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(&nbsp;vis,&nbsp;</span><span style="font-family: Courier;">0</span><span style="font-family: Courier;">,&nbsp;</span><span style="color: #0000ff; font-family: Courier;">sizeof</span><span style="font-family: Courier;">(&nbsp;vis&nbsp;)&nbsp;);</span><br />&nbsp;<br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path.clear();</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vis[</span><span style="font-family: Courier;">0</span><span style="font-family: Courier;">][</span><span style="font-family: Courier;">0</span><span style="font-family: Courier;">]&nbsp;</span><span style="font-family: Courier;">=</span>&nbsp;<span style="font-family: Courier;">1</span><span style="font-family: Courier;">;</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dfs(&nbsp;</span><span style="font-family: Courier;">0</span><span style="font-family: Courier;">,&nbsp;</span><span style="font-family: Courier;">0</span><span style="font-family: Courier;">&nbsp;);<br /></span><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; &nbsp; &nbsp; if</span><span style="font-family: Courier;">(&nbsp;</span><span style="font-family: Courier;">!</span><span style="font-family: Courier;">flag&nbsp;)</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&nbsp;</span><span style="font-family: Courier;">"</span><span style="font-family: Courier;">impossible\n</span><span style="font-family: Courier;">"</span><span style="font-family: Courier;">&nbsp;);</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts(</span><span style="font-family: Courier;">""</span><span style="font-family: Courier;">);</span><br />&nbsp;<br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #0000ff; font-family: Courier;">&nbsp; &nbsp; return</span>&nbsp;<span style="font-family: Courier;">0</span><span style="font-family: Courier;">;</span><br /><span style="font-family: Courier;">}</span></div><img src ="http://www.cppblog.com/vontroy/aggbug/214245.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2016-08-31 10:16 <a href="http://www.cppblog.com/vontroy/archive/2016/08/31/214245.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>字典树(Trie树)</title><link>http://www.cppblog.com/vontroy/archive/2016/08/31/214243.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Wed, 31 Aug 2016 01:35:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2016/08/31/214243.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/214243.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2016/08/31/214243.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/214243.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/214243.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; color: #555555; font-family: &quot;microsoft yahei&quot;; font-size: 15px; line-height: 35px; background-color: #ffffff;"><img src="http://img.blog.csdn.net/20151128210114865" alt="" style="border: none; max-width: 602px; height: auto; font-family: Courier; font-size: 12pt;" /><br /></p><p style="margin: 0px; padding: 0px; color: #555555; font-family: &quot;microsoft yahei&quot;; font-size: 15px; line-height: 35px; background-color: #ffffff;"><span style="font-family: Courier; font-size: 12pt;">如图，每条路径上保存一个字母，从根节点开始进行dfs，每遍历到一个标记节点（图中的红点），从根节点到当前节点路径上所有字母连起来即为一个单词</span></p><p style="margin: 0px; padding: 0px; color: #555555; font-family: &quot;microsoft yahei&quot;; font-size: 15px; line-height: 35px; background-color: #ffffff;"><span style="font-family: Courier; font-size: 12pt;">上图中存储了 abc, abcd, b, bcd, efg, hij.</span></p><p style="margin: 0px; padding: 0px; color: #555555; font-family: &quot;microsoft yahei&quot;; font-size: 15px; line-height: 35px; background-color: #ffffff;"><span style="font-family: Courier; font-size: 12pt;">对于Trie树主要有三种操作：</span></p><p style="margin: 0px; padding: 0px; color: #555555; font-family: &quot;microsoft yahei&quot;; font-size: 15px; line-height: 35px; background-color: #ffffff;"></p><ol style="color: #555555; font-family: &quot;microsoft yahei&quot;; font-size: 15px; line-height: 35px; background-color: #ffffff;"><li><span style="font-family: Courier; font-size: 12pt;">新建一个结点</span></li><li><span style="font-family: Courier; font-size: 12pt;">插入一个单词</span></li><li><span style="font-family: Courier; font-size: 12pt;">在trie树中查找单词</span></li></ol><div style="color: #555555; font-family: &quot;microsoft yahei&quot;; font-size: 15px; line-height: 35px; background-color: #ffffff;"><span style="font-family: Courier; font-size: 12pt;">trie树中每次插入一个结点的时间复杂度是 O( strlen( str ) )</span></div><div style="color: #555555; font-family: &quot;microsoft yahei&quot;; font-size: 15px; line-height: 35px; background-color: #ffffff;"><span style="font-family: Courier; font-size: 12pt;">建立trie树的时间复杂度为 O( &#8721;strlen( str[i] ) )</span></div><div style="color: #555555; font-family: &quot;microsoft yahei&quot;; font-size: 15px; line-height: 35px; background-color: #ffffff;"><span style="font-family: Courier; font-size: 12pt;">对于每个单词，查询的时间复杂度为 O( strlen( str ) )</span><br /><br /><h2><span style="font-family: Courier; font-size: 12pt;">Templates:</span></h2><h3><span style="font-family: Courier; font-size: 12pt;">Struct:</span></h3><div style="font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; background-color: #eeeeee;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">struct</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;node&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">{&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">int</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;flag;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; font-family: Courier; font-size: 12pt;">//</span><span style="color: #008000; font-family: Courier; font-size: 12pt;">The&nbsp;end&nbsp;of&nbsp;a&nbsp;word&nbsp;&nbsp;</span><span style="color: #008000; "><br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;node</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">*</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;next[</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">26</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">];&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">}; &nbsp;</span></div><br /><h3><span style="font-family: Courier; font-size: 12pt;">新建结点：</span></h3><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 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: #000000; font-family: Courier; font-size: 12pt;">node</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">*</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;newnode()&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">{&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;node</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">*</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;p&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">new</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;node;&nbsp;&nbsp;<br />&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">-&gt;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">flag&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">0</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">;&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">for</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">(&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">int</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;i&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">0</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">;&nbsp;i&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&lt;</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">26</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">;&nbsp;i</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">++</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;)&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">-&gt;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">next[i]&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">=</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;NULL;&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">return</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;p;&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">} &nbsp;</span></div><h3><span style="font-family: Courier; font-size: 12pt;">插入单词：</span></h3><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 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; font-family: Courier; font-size: 12pt;">void</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;trie_insert(&nbsp;node</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">*</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;root,&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">char</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">*</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;s&nbsp;)&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">{&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;node</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">*</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;p&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">=</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;root;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">int</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;len&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">=</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;strlen(&nbsp;s&nbsp;);&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">int</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;tmp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">for</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">(&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">int</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;i&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">0</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">;&nbsp;i&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&lt;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;len;&nbsp;i</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">++</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;)&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">=</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;s[i]&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">-</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">'</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">a</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">'</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">if</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">(&nbsp;p</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">-&gt;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">next[tmp]&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">==</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;NULL&nbsp;)&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">-&gt;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">next[tmp]&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">=</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;newnode();&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">=</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;p</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">-&gt;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">next[tmp];&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">-&gt;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">flag&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">1</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">;&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">} &nbsp;</span></div><h3><span style="font-family: Courier; font-size: 12pt;">查询：</span></h3><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 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; font-family: Courier; font-size: 12pt;">int</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;trie_search(&nbsp;node</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">*</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;root,&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">char</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">*</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;s&nbsp;)&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">{&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;node</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">*</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;p&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">=</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;root;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">int</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;len&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">=</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;strlen(&nbsp;s&nbsp;);&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">int</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;tmp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">for</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">(&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">int</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;i&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">0</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">;&nbsp;i&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&lt;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;len;&nbsp;i</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">++</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;)&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">=</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;s[i]&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">-</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">'</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">a</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">'</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">if</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">(&nbsp;p</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">-&gt;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">next[tmp]&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">==</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;NULL&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; font-family: Courier; font-size: 12pt;">//</span><span style="color: #008000; font-family: Courier; font-size: 12pt;">not&nbsp;matched&nbsp;&nbsp;</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">return</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">0</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">;&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">=</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;p</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">-&gt;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">next[tmp];&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">if</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">(&nbsp;p</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">-&gt;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">flag&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; font-family: Courier; font-size: 12pt;">//</span><span style="color: #008000; font-family: Courier; font-size: 12pt;">match&nbsp;&amp;&amp;&nbsp;it&nbsp;is&nbsp;a&nbsp;word&nbsp;which&nbsp;has&nbsp;been&nbsp;stored&nbsp;&nbsp;<br /></span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">&nbsp; &nbsp; return</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">1</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-family: Courier; font-size: 12pt;">return</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">0</span><span style="color: #000000; font-family: Courier; font-size: 12pt;">;&nbsp;&nbsp;<br /></span><span style="color: #000000; font-family: Courier; font-size: 12pt;">} &nbsp;</span></div></div><img src ="http://www.cppblog.com/vontroy/aggbug/214243.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2016-08-31 09:35 <a href="http://www.cppblog.com/vontroy/archive/2016/08/31/214243.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ 2653 Pick-up sticks 判断线段相交</title><link>http://www.cppblog.com/vontroy/archive/2010/10/03/128488.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sun, 03 Oct 2010 08:21:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/03/128488.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128488.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/03/128488.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128488.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128488.html</trackback:ping><description><![CDATA[<div lang="en-US" class="ptt">Pick-up sticks</div>
<div class="plm">
<table align="center">
    <tbody>
        <tr>
            <td><strong>Time Limit:</strong> 3000MS</td>
            <td width="10"></td>
            <td><strong>Memory Limit:</strong> 65536K</td>
        </tr>
        <tr>
            <td><strong>Total Submissions:</strong> 4189</td>
            <td width="10"></td>
            <td><strong>Accepted:</strong> 1501</td>
        </tr>
    </tbody>
</table>
</div>
<p class="pst">Description</p>
<div lang="en-US" class="ptx">Stan has n sticks of various length. He throws them one at a time on the floor in a random way. After finishing throwing, Stan tries to find the top sticks, that is these sticks such that there is no stick on top of them. Stan has noticed that the last thrown stick is always on top but he wants to know all the sticks that are on top. Stan sticks are very, very thin such that their thickness can be neglected.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/vontroy/2653_1.jpg" width="333" height="270" /></div>
<p class="pst">Input</p>
<div lang="en-US" class="ptx">Input consists of a number of cases. The data for each case start with 1 &lt;= n &lt;= 100000, the number of sticks for this case. The following n lines contain four numbers each, these numbers are the planar coordinates of the endpoints of one stick. The sticks are listed in the order in which Stan has thrown them. You may assume that there are no more than 1000 top sticks. The input is ended by the case with n=0. This case should not be processed. </div>
<p class="pst">Output</p>
<div lang="en-US" class="ptx">For each input case, print one line of output listing the top sticks in the format given in the sample. The top sticks should be listed in order in which they were thrown. <br /><br />The picture to the right below illustrates the first case from input. </div>
<p class="pst">Sample Input</p>
<pre class="sio">5
1 1 4 2
2 3 3 1
1 -2.0 8 4
1 4 8 2
3 3 6 -2.0
3
0 0 1 1
1 0 2 1
2 0 3 1
0
</pre>
<p class="pst">Sample Output</p>
<pre class="sio">Top sticks: 2, 4, 5.
Top sticks: 1, 2, 3.
</pre>
<p class="pst">Hint</p>
<div lang="en-US" class="ptx">Huge input,scanf is recommended.</div>
<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"><img id="Codehighlighter1_0_122_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_122_Open_Text.style.display='none'; Codehighlighter1_0_122_Closed_Image.style.display='inline'; Codehighlighter1_0_122_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_0_122_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_0_122_Closed_Text.style.display='none'; Codehighlighter1_0_122_Open_Image.style.display='inline'; Codehighlighter1_0_122_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_0_122_Closed_Text">/**/</span><span id="Codehighlighter1_0_122_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">**********************************<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />暴力就行，从第一个开始判断<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />如果两条线段相交就把前面一条筛选掉<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />判断线段相交直接贴的吉大模板。。。<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />**********************************</span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;maxn&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">100000</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">5</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;eps</span><span style="color: #000000">=</span><span style="color: #000000">1e</span><span style="color: #000000">-</span><span style="color: #000000">10</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img id="Codehighlighter1_271_286_Open_Image" onclick="this.style.display='none'; Codehighlighter1_271_286_Open_Text.style.display='none'; Codehighlighter1_271_286_Closed_Image.style.display='inline'; Codehighlighter1_271_286_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_271_286_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_271_286_Closed_Text.style.display='none'; Codehighlighter1_271_286_Open_Image.style.display='inline'; Codehighlighter1_271_286_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;point&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_271_286_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_271_286_Open_Text"><span style="color: #000000">{&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;x,&nbsp;y;&nbsp;}</span></span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />point&nbsp;p[maxn],&nbsp;b[maxn];<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;ans[maxn];<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img id="Codehighlighter1_362_386_Open_Image" onclick="this.style.display='none'; Codehighlighter1_362_386_Open_Text.style.display='none'; Codehighlighter1_362_386_Closed_Image.style.display='inline'; Codehighlighter1_362_386_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_362_386_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_362_386_Closed_Text.style.display='none'; Codehighlighter1_362_386_Open_Image.style.display='inline'; Codehighlighter1_362_386_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;min(</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;a,&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;b)&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_362_386_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_362_386_Open_Text"><span style="color: #000000">{&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;a&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;b&nbsp;</span><span style="color: #000000">?</span><span style="color: #000000">&nbsp;a&nbsp;:&nbsp;b;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img id="Codehighlighter1_420_444_Open_Image" onclick="this.style.display='none'; Codehighlighter1_420_444_Open_Text.style.display='none'; Codehighlighter1_420_444_Closed_Image.style.display='inline'; Codehighlighter1_420_444_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_420_444_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_420_444_Closed_Text.style.display='none'; Codehighlighter1_420_444_Open_Image.style.display='inline'; Codehighlighter1_420_444_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;max(</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;a,&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;b)&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_420_444_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_420_444_Open_Text"><span style="color: #000000">{&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;a&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;b&nbsp;</span><span style="color: #000000">?</span><span style="color: #000000">&nbsp;a&nbsp;:&nbsp;b;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;inter(point&nbsp;a,&nbsp;point&nbsp;b,&nbsp;point&nbsp;c,&nbsp;point&nbsp;d)<br /><img id="Codehighlighter1_494_992_Open_Image" onclick="this.style.display='none'; Codehighlighter1_494_992_Open_Text.style.display='none'; Codehighlighter1_494_992_Closed_Image.style.display='inline'; Codehighlighter1_494_992_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_494_992_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_494_992_Closed_Text.style.display='none'; Codehighlighter1_494_992_Open_Image.style.display='inline'; Codehighlighter1_494_992_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_494_992_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_494_992_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;min(a.x,&nbsp;b.x)&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;max(c.x,&nbsp;d.x)&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;min(a.y,&nbsp;b.y)&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;max(c.y,&nbsp;d.y)&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;min(c.x,&nbsp;d.x)&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;max(a.x,&nbsp;b.x)&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;min(c.y,&nbsp;d.y)&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;max(a.y,&nbsp;b.y)&nbsp;)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;h,&nbsp;i,&nbsp;j,&nbsp;k;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;h&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(b.x&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;a.x)&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;(c.y&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;a.y)&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;(b.y&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;a.y)&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;(c.x&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;a.x);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(b.x&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;a.x)&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;(d.y&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;a.y)&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;(b.y&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;a.y)&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;(d.x&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;a.x);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;j&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(d.x&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;c.x)&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;(a.y&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;c.y)&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;(d.y&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;c.y)&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;(a.x&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;c.x);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;k&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(d.x&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;c.x)&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;(b.y&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;c.y)&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;(d.y&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;c.y)&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;(b.x&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;c.x);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;h&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;eps&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;j&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;k&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;eps;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_1006_1807_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1006_1807_Open_Text.style.display='none'; Codehighlighter1_1006_1807_Closed_Image.style.display='inline'; Codehighlighter1_1006_1807_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_1006_1807_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1006_1807_Closed_Text.style.display='none'; Codehighlighter1_1006_1807_Open_Image.style.display='inline'; Codehighlighter1_1006_1807_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1006_1807_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1006_1807_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;res[maxn];<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;n,&nbsp;n&nbsp;)<br /><img id="Codehighlighter1_1067_1791_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1067_1791_Open_Text.style.display='none'; Codehighlighter1_1067_1791_Closed_Image.style.display='inline'; Codehighlighter1_1067_1791_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1067_1791_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1067_1791_Closed_Text.style.display='none'; Codehighlighter1_1067_1791_Open_Image.style.display='inline'; Codehighlighter1_1067_1791_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1067_1791_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1067_1791_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(&nbsp;ans,&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(&nbsp;ans&nbsp;)&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br /><img id="Codehighlighter1_1155_1222_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1155_1222_Open_Text.style.display='none'; Codehighlighter1_1155_1222_Closed_Image.style.display='inline'; Codehighlighter1_1155_1222_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1155_1222_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1155_1222_Closed_Text.style.display='none'; Codehighlighter1_1155_1222_Open_Image.style.display='inline'; Codehighlighter1_1155_1222_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1155_1222_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1155_1222_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;p[i].x&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;p[i].y&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;b[i].x&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;b[i].y;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br /><img id="Codehighlighter1_1270_1530_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1270_1530_Open_Text.style.display='none'; Codehighlighter1_1270_1530_Closed_Image.style.display='inline'; Codehighlighter1_1270_1530_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1270_1530_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1270_1530_Closed_Text.style.display='none'; Codehighlighter1_1270_1530_Open_Image.style.display='inline'; Codehighlighter1_1270_1530_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1270_1530_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1270_1530_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;j&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;j</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br /><img id="Codehighlighter1_1329_1520_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1329_1520_Open_Text.style.display='none'; Codehighlighter1_1329_1520_Closed_Image.style.display='inline'; Codehighlighter1_1329_1520_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1329_1520_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1329_1520_Closed_Text.style.display='none'; Codehighlighter1_1329_1520_Open_Image.style.display='inline'; Codehighlighter1_1329_1520_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1329_1520_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1329_1520_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;inter(p[i],&nbsp;b[i],&nbsp;p[j],&nbsp;b[j]&nbsp;)&nbsp;)<br /><img id="Codehighlighter1_1400_1506_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1400_1506_Open_Text.style.display='none'; Codehighlighter1_1400_1506_Closed_Image.style.display='inline'; Codehighlighter1_1400_1506_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1400_1506_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1400_1506_Closed_Text.style.display='none'; Codehighlighter1_1400_1506_Open_Image.style.display='inline'; Codehighlighter1_1400_1506_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1400_1506_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1400_1506_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans[i]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">不加break会超时。。。</span><span style="color: #008000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;ct&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 align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">Top&nbsp;sticks:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;</span><span style="color: #000000">!</span><span style="color: #000000">ans[i]&nbsp;)&nbsp;&nbsp;res[ct</span><span style="color: #000000">++</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;ct&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;res[i]&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;res[ct</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">.</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span></div><img src ="http://www.cppblog.com/vontroy/aggbug/128488.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-03 16:21 <a href="http://www.cppblog.com/vontroy/archive/2010/10/03/128488.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ 1269 Intersecting Lines 判断直线相交并求交点</title><link>http://www.cppblog.com/vontroy/archive/2010/10/03/128429.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sun, 03 Oct 2010 03:03:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/03/128429.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128429.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/03/128429.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128429.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128429.html</trackback:ping><description><![CDATA[<div lang="en-US" class="ptt" align="center"><strong style="font-size: 18pt"><br />Intersecting Lines<br /><br /></strong></div>
<div class="plm">
<table align="center">
    <tbody>
        <tr>
            <td><strong>Time Limit:</strong> 1000MS</td>
            <td width="10"></td>
            <td><strong>Memory Limit:</strong> 10000K</td>
        </tr>
        <tr>
            <td><strong>Total Submissions:</strong> 4260</td>
            <td width="10"></td>
            <td><strong>Accepted:</strong> 2049</td>
        </tr>
    </tbody>
</table>
</div>
<p class="pst"><strong>Description</strong></p>
<div lang="en-US" class="ptx">We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection because they are parallel, 2) intersect in a line because they are on top of one another (i.e. they are the same line), 3) intersect in a point. In this problem you will use your algebraic knowledge to create a program that determines how and where two lines intersect. <br />Your program will repeatedly read in four points that define two lines in the x-y plane and determine how and where the lines intersect. All numbers required by this problem will be reasonable, say between -1000 and 1000.</div>
<p class="pst"><strong>Input</strong></p>
<div lang="en-US" class="ptx">The first line contains an integer N between 1 and 10 describing how many pairs of lines are represented. The next N lines will each contain eight integers. These integers represent the coordinates of four points on the plane in the order x1y1x2y2x3y3x4y4. Thus each of these input lines represents two lines on the plane: the line through (x1,y1) and (x2,y2) and the line through (x3,y3) and (x4,y4). The point (x1,y1) is always distinct from (x2,y2). Likewise with (x3,y3) and (x4,y4).</div>
<p class="pst"><strong>Output</strong></p>
<div lang="en-US" class="ptx">There should be N+2 lines of output. The first line of output should read INTERSECTING LINES OUTPUT. There will then be one line of output for each pair of planar lines represented by a line of input, describing how the lines intersect: none, line, or point. If the intersection is a point then your program should output the x and y coordinates of the point, correct to two decimal places. The final line of output should read "END OF OUTPUT". </div>
<p class="pst"><strong>Sample Input</strong></p>
<pre class="sio">5
0 0 4 4 0 4 4 0
5 0 7 6 1 0 2 3
5 0 7 6 3 -6 4 -3
2 0 2 27 1 5 18 5
0 3 4 0 1 2 2 5
</pre>
<p class="pst"><strong>Sample Output</strong></p>
<pre class="sio">INTERSECTING LINES OUTPUT
POINT 2.00 2.00
NONE
LINE
POINT 2.00 5.00
POINT 1.07 2.20
END OF OUTPUT
</pre>
<pre class="sio"><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"><img id="Codehighlighter1_0_107_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_107_Open_Text.style.display='none'; Codehighlighter1_0_107_Closed_Image.style.display='inline'; Codehighlighter1_0_107_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_0_107_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_0_107_Closed_Text.style.display='none'; Codehighlighter1_0_107_Open_Image.style.display='inline'; Codehighlighter1_0_107_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_0_107_Closed_Text">/**/</span><span id="Codehighlighter1_0_107_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">************************************<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />计算几何基础题，判断直线相交及求交点<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />注意斜率不存在的情况<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />*************************************</span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_159_1728_Open_Image" onclick="this.style.display='none'; Codehighlighter1_159_1728_Open_Text.style.display='none'; Codehighlighter1_159_1728_Closed_Image.style.display='inline'; Codehighlighter1_159_1728_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_159_1728_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_159_1728_Closed_Text.style.display='none'; Codehighlighter1_159_1728_Open_Image.style.display='inline'; Codehighlighter1_159_1728_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_159_1728_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_159_1728_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;x1,&nbsp;y1,&nbsp;x2,&nbsp;y2,&nbsp;x3,&nbsp;y3,&nbsp;x4,&nbsp;y4;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;k1,&nbsp;k2;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;b1,&nbsp;b2;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;i_x,&nbsp;i_y;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">n);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">INTERSECTING&nbsp;LINES&nbsp;OUTPUT</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;std::endl;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;n</span><span style="color: #000000">--</span><span style="color: #000000">&nbsp;)<br /><img id="Codehighlighter1_375_1675_Open_Image" onclick="this.style.display='none'; Codehighlighter1_375_1675_Open_Text.style.display='none'; Codehighlighter1_375_1675_Closed_Image.style.display='inline'; Codehighlighter1_375_1675_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_375_1675_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_375_1675_Closed_Text.style.display='none'; Codehighlighter1_375_1675_Open_Image.style.display='inline'; Codehighlighter1_375_1675_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_375_1675_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_375_1675_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%lf%lf%lf%lf%lf%lf%lf%lf</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">x1,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">y1,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">x2,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">y2,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">x3,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">y3,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">x4,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">y4);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;x1&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;x2&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;x3&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;x4&nbsp;)<br /><img id="Codehighlighter1_504_1034_Open_Image" onclick="this.style.display='none'; Codehighlighter1_504_1034_Open_Text.style.display='none'; Codehighlighter1_504_1034_Closed_Image.style.display='inline'; Codehighlighter1_504_1034_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_504_1034_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_504_1034_Closed_Text.style.display='none'; Codehighlighter1_504_1034_Open_Image.style.display='inline'; Codehighlighter1_504_1034_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_504_1034_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_504_1034_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(&nbsp;y2&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;y1&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;(&nbsp;x2&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;x1&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k2&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(&nbsp;y4&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;y3&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;(&nbsp;x4&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;x3&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;y1&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;k1&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;x1;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b2&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;y3&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;k2&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;x3;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;k1&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;k2&nbsp;)<br /><img id="Codehighlighter1_695_839_Open_Image" onclick="this.style.display='none'; Codehighlighter1_695_839_Open_Text.style.display='none'; Codehighlighter1_695_839_Closed_Image.style.display='inline'; Codehighlighter1_695_839_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_695_839_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_695_839_Closed_Text.style.display='none'; Codehighlighter1_695_839_Open_Image.style.display='inline'; Codehighlighter1_695_839_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_695_839_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_695_839_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;b1&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;b2&nbsp;)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">LINE\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">NONE\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img id="Codehighlighter1_870_1024_Open_Image" onclick="this.style.display='none'; Codehighlighter1_870_1024_Open_Text.style.display='none'; Codehighlighter1_870_1024_Closed_Image.style.display='inline'; Codehighlighter1_870_1024_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_870_1024_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_870_1024_Closed_Text.style.display='none'; Codehighlighter1_870_1024_Open_Image.style.display='inline'; Codehighlighter1_870_1024_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_870_1024_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_870_1024_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i_x&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(b2&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;b1)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;(k1&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;k2);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i_y&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;k1&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;i_x&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;b1;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">POINT&nbsp;%.2lf&nbsp;%.2lf\n</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;i_x,&nbsp;i_y);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;x1&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;x2&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;x3&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;x4&nbsp;)<br /><img id="Codehighlighter1_1084_1210_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1084_1210_Open_Text.style.display='none'; Codehighlighter1_1084_1210_Closed_Image.style.display='inline'; Codehighlighter1_1084_1210_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1084_1210_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1084_1210_Closed_Text.style.display='none'; Codehighlighter1_1084_1210_Open_Image.style.display='inline'; Codehighlighter1_1084_1210_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1084_1210_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1084_1210_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;x1&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;x3&nbsp;)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">LINE\n</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">NONE\n</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;x1&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;x2&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;x3&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;x4&nbsp;)<br /><img id="Codehighlighter1_1260_1453_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1260_1453_Open_Text.style.display='none'; Codehighlighter1_1260_1453_Closed_Image.style.display='inline'; Codehighlighter1_1260_1453_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1260_1453_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1260_1453_Closed_Text.style.display='none'; Codehighlighter1_1260_1453_Open_Image.style.display='inline'; Codehighlighter1_1260_1453_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1260_1453_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1260_1453_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k2&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(&nbsp;y4&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;y3&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;(&nbsp;x4&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;x3&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b2&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;y3&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;k2&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;x3;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i_x&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;x1;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i_y&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;k2&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;x1&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;b2;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">POINT&nbsp;%.2lf&nbsp;%.2lf\n</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;i_x,&nbsp;i_y);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img id="Codehighlighter1_1476_1669_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1476_1669_Open_Text.style.display='none'; Codehighlighter1_1476_1669_Closed_Image.style.display='inline'; Codehighlighter1_1476_1669_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1476_1669_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1476_1669_Closed_Text.style.display='none'; Codehighlighter1_1476_1669_Open_Image.style.display='inline'; Codehighlighter1_1476_1669_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1476_1669_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1476_1669_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(&nbsp;y2&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;y1&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;(&nbsp;x2&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;x1&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;y1&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;k1&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;x1;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i_x&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;x3;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i_y&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;k1&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;x3&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;b1;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">POINT&nbsp;%.2lf&nbsp;%.2lf\n</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;i_x,&nbsp;i_y);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">END&nbsp;OF&nbsp;OUTPUT\n</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span></div>
</pre><img src ="http://www.cppblog.com/vontroy/aggbug/128429.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-03 11:03 <a href="http://www.cppblog.com/vontroy/archive/2010/10/03/128429.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 2734 Quicksum 简单字符串处理</title><link>http://www.cppblog.com/vontroy/archive/2010/10/03/128420.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sun, 03 Oct 2010 02:03:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/03/128420.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128420.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/03/128420.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128420.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128420.html</trackback:ping><description><![CDATA[<span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: #000000; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="font-family: 'Times New Roman'" class="Apple-style-span">
<h1 style="text-align: center; color: #1a5cc8" align="center">Quicksum</h1>
<p align="center"><font size="+0"><strong><span style="font-family: Arial; color: green; font-size: 12px; font-weight: bold">Time Limit: 2000/1000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 32768/32768 K (Java/Others)<br />Total Submission(s): 492&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 408<br /></span></strong></font><br /></p>
<div style="background-image: url(http://acm.hdu.edu.cn/images/panel-title.png); padding-bottom: 0px; background-color: transparent; padding-left: 14px; padding-right: 14px; background-repeat: no-repeat; font-family: Arial; background-position: 0% 100%; height: 38px; color: #7ca9ed; font-size: 18px; font-weight: bold; padding-top: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial" class="panel_title" align="left">Problem Description</div>
<div style="background-image: url(http://acm.hdu.edu.cn/images/panel-content.png); text-align: left; padding-bottom: 0px; margin: 0px; padding-left: 20px; padding-right: 20px; background-repeat: repeat-y; font-family: 'Times New Roman'; height: auto; font-size: 14px; padding-top: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial" class="panel_content">A checksum is an algorithm that scans a packet of data and returns a single number. The idea is that if the packet is changed, the checksum will also change, so checksums are often used for detecting transmission errors, validating document contents, and in many other situations where it is necessary to detect undesirable changes in data.<br /><br />For this problem, you will implement a checksum algorithm called Quicksum. A Quicksum packet allows only uppercase letters and spaces. It always begins and ends with an uppercase letter. Otherwise, spaces and letters can occur in any combination, including consecutive spaces.<br /><br />A Quicksum is the sum of the products of each character's position in the packet times the character's value. A space has a value of zero, while letters have a value equal to their position in the alphabet. So, A=1, B=2, etc., through Z=26. Here are example Quicksum calculations for the packets "ACM" and "MID CENTRAL":<br /><br />ACM: 1*1 + 2*3 + 3*13 = 46MID CENTRAL: 1*13 + 2*9 + 3*4 + 4*0 + 5*3 + 6*5 + 7*14 + 8*20 + 9*18 + 10*1 + 11*12 = 650</div>
<div style="background-image: url(http://acm.hdu.edu.cn/images/panel-bottom.png); margin: 0px; background-repeat: no-repeat; background-position: 0% 0%; height: auto; -webkit-background-clip: initial; -webkit-background-origin: initial" class="panel_bottom">&nbsp;</div>
<br />
<div style="background-image: url(http://acm.hdu.edu.cn/images/panel-title.png); padding-bottom: 0px; background-color: transparent; padding-left: 14px; padding-right: 14px; background-repeat: no-repeat; font-family: Arial; background-position: 0% 100%; height: 38px; color: #7ca9ed; font-size: 18px; font-weight: bold; padding-top: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial" class="panel_title" align="left">Input</div>
<div style="background-image: url(http://acm.hdu.edu.cn/images/panel-content.png); text-align: left; padding-bottom: 0px; margin: 0px; padding-left: 20px; padding-right: 20px; background-repeat: repeat-y; font-family: 'Times New Roman'; height: auto; font-size: 14px; padding-top: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial" class="panel_content">The input consists of one or more packets followed by a line containing only # that signals the end of the input. Each packet is on a line by itself, does not begin or end with a space, and contains from 1 to 255 characters.</div>
<div style="background-image: url(http://acm.hdu.edu.cn/images/panel-bottom.png); margin: 0px; background-repeat: no-repeat; background-position: 0% 0%; height: auto; -webkit-background-clip: initial; -webkit-background-origin: initial" class="panel_bottom">&nbsp;</div>
<br />
<div style="background-image: url(http://acm.hdu.edu.cn/images/panel-title.png); padding-bottom: 0px; background-color: transparent; padding-left: 14px; padding-right: 14px; background-repeat: no-repeat; font-family: Arial; background-position: 0% 100%; height: 38px; color: #7ca9ed; font-size: 18px; font-weight: bold; padding-top: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial" class="panel_title" align="left">Output</div>
<div style="background-image: url(http://acm.hdu.edu.cn/images/panel-content.png); text-align: left; padding-bottom: 0px; margin: 0px; padding-left: 20px; padding-right: 20px; background-repeat: repeat-y; font-family: 'Times New Roman'; height: auto; font-size: 14px; padding-top: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial" class="panel_content">For each packet, output its Quicksum on a separate line in the output.<br /></div>
<div style="background-image: url(http://acm.hdu.edu.cn/images/panel-bottom.png); margin: 0px; background-repeat: no-repeat; background-position: 0% 0%; height: auto; -webkit-background-clip: initial; -webkit-background-origin: initial" class="panel_bottom">&nbsp;</div>
<br />
<div style="background-image: url(http://acm.hdu.edu.cn/images/panel-title.png); padding-bottom: 0px; background-color: transparent; padding-left: 14px; padding-right: 14px; background-repeat: no-repeat; font-family: Arial; background-position: 0% 100%; height: 38px; color: #7ca9ed; font-size: 18px; font-weight: bold; padding-top: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial" class="panel_title" align="left">Sample Input</div>
<div style="background-image: url(http://acm.hdu.edu.cn/images/panel-content.png); text-align: left; padding-bottom: 0px; margin: 0px; padding-left: 20px; padding-right: 20px; background-repeat: repeat-y; font-family: 'Times New Roman'; height: auto; font-size: 14px; padding-top: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial" class="panel_content">
<pre style="margin: 0px; font-size: 14px"><div style="font-family: 'Courier New', Courier, monospace">ACM
MID CENTRAL
REGIONAL PROGRAMMING CONTEST
ACN
A C M
ABC
BBC
#</div>
</pre>
</div>
<div style="background-image: url(http://acm.hdu.edu.cn/images/panel-bottom.png); margin: 0px; background-repeat: no-repeat; background-position: 0% 0%; height: auto; -webkit-background-clip: initial; -webkit-background-origin: initial" class="panel_bottom">&nbsp;</div>
<br />
<div style="background-image: url(http://acm.hdu.edu.cn/images/panel-title.png); padding-bottom: 0px; background-color: transparent; padding-left: 14px; padding-right: 14px; background-repeat: no-repeat; font-family: Arial; background-position: 0% 100%; height: 38px; color: #7ca9ed; font-size: 18px; font-weight: bold; padding-top: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial" class="panel_title" align="left">Sample Output</div>
<div style="background-image: url(http://acm.hdu.edu.cn/images/panel-content.png); text-align: left; padding-bottom: 0px; margin: 0px; padding-left: 20px; padding-right: 20px; background-repeat: repeat-y; font-family: 'Times New Roman'; height: auto; font-size: 14px; padding-top: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial" class="panel_content">
<pre style="margin: 0px; font-size: 14px"><div style="font-family: 'Courier New', Courier, monospace">46
650
4690
49
75
14
15</div>
</pre>
</div>
<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"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_69_446_Open_Image" onclick="this.style.display='none'; Codehighlighter1_69_446_Open_Text.style.display='none'; Codehighlighter1_69_446_Closed_Image.style.display='inline'; Codehighlighter1_69_446_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_69_446_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_69_446_Closed_Text.style.display='none'; Codehighlighter1_69_446_Open_Image.style.display='inline'; Codehighlighter1_69_446_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_69_446_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_69_446_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;str[</span><span style="color: #000000">260</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;ans&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 align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;gets(str)&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;str[</span><span style="color: #000000">0</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">#</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;)<br /><img id="Codehighlighter1_151_430_Open_Image" onclick="this.style.display='none'; Codehighlighter1_151_430_Open_Text.style.display='none'; Codehighlighter1_151_430_Closed_Image.style.display='inline'; Codehighlighter1_151_430_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_151_430_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_151_430_Closed_Text.style.display='none'; Codehighlighter1_151_430_Open_Image.style.display='inline'; Codehighlighter1_151_430_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_151_430_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_151_430_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans&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 align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;len&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;strlen(str);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;len;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br /><img id="Codehighlighter1_248_385_Open_Image" onclick="this.style.display='none'; Codehighlighter1_248_385_Open_Text.style.display='none'; Codehighlighter1_248_385_Closed_Image.style.display='inline'; Codehighlighter1_248_385_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_248_385_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_248_385_Closed_Text.style.display='none'; Codehighlighter1_248_385_Open_Image.style.display='inline'; Codehighlighter1_248_385_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_248_385_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_248_385_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;str[i]&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">continue</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;(&nbsp;str[i]&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">64</span><span style="color: #000000">&nbsp;)&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;(&nbsp;i&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;ans&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;std::endl;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span></div>
</span></span><img src ="http://www.cppblog.com/vontroy/aggbug/128420.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-03 10:03 <a href="http://www.cppblog.com/vontroy/archive/2010/10/03/128420.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 3661 Assignments-2010 Harbin Regional</title><link>http://www.cppblog.com/vontroy/archive/2010/10/03/128409.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sun, 03 Oct 2010 00:36:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/03/128409.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128409.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/03/128409.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128409.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128409.html</trackback:ping><description><![CDATA[<h1 style="color: #1a5cc8" align="center">Assignments</h1>
<p align="center"><font size="+0"><strong><span style="font-family: Arial; color: green; font-size: 12px; font-weight: bold">Time Limit: 4000/2000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 32768/32768 K (Java/Others)<br />Total Submission(s): 252&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 125<br /></span></strong></font><br /><br /></p>
<div class="panel_title" align="left"><strong>Problem Description</strong></div>
<div class="panel_content">In a factory, there are N workers to finish two types of tasks (A and B). Each type has N tasks. Each task of type A needs xi time to finish, and each task of type B needs yj time to finish, now, you, as the boss of the factory, need to make an assignment, which makes sure that every worker could get two tasks, one in type A and one in type B, and, what's more, every worker should have task to work with and every task has to be assigned. However, you need to pay extra money to workers who work over the standard working hours, according to the company's rule. The calculation method is described as follow: if someone&#8217; working hour t is more than the standard working hour T, you should pay t-T to him. As a thrifty boss, you want know the minimum total of overtime pay.</div>
<div class="panel_bottom">&nbsp;</div>
<br />
<div class="panel_title" align="left"><strong>Input</strong></div>
<div class="panel_content">There are multiple test cases, in each test case there are 3 lines. First line there are two positive Integers, N (N&lt;=1000) and T (T&lt;=1000), indicating N workers, N task-A and N task-B, standard working hour T. Each of the next two lines has N positive Integers; the first line indicates the needed time for task A1, A2&#8230;An (Ai&lt;=1000), and the second line is for B1, B2&#8230;Bn (Bi&lt;=1000).</div>
<div class="panel_bottom">&nbsp;</div>
<br />
<div class="panel_title" align="left"><strong>Output</strong></div>
<div class="panel_content">For each test case output the minimum Overtime wages by an integer in one line.</div>
<div class="panel_bottom">&nbsp;</div>
<br />
<div class="panel_title" align="left"><strong>Sample Input</strong></div>
<div class="panel_content">
<pre><div style="font-family: Courier New,Courier,monospace">2 5
4 2
3 5</div>
</pre>
</div>
<div class="panel_bottom">&nbsp;</div>
<br />
<div class="panel_title" align="left"><strong>Sample Output</strong></div>
<div class="panel_content">
<pre><div style="font-family: Courier New,Courier,monospace">4</div>
</pre>
</div>
<div class="panel_bottom">&nbsp;<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"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><span style="color: #008000">//</span><span style="color: #008000">简单贪心</span><span style="color: #008000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;maxn&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1000</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">5</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;cmp(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;b&nbsp;)<br /><img id="Codehighlighter1_142_162_Open_Image" onclick="this.style.display='none'; Codehighlighter1_142_162_Open_Text.style.display='none'; Codehighlighter1_142_162_Closed_Image.style.display='inline'; Codehighlighter1_142_162_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_142_162_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_142_162_Closed_Text.style.display='none'; Codehighlighter1_142_162_Open_Image.style.display='inline'; Codehighlighter1_142_162_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_142_162_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_142_162_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;a&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;b;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_176_620_Open_Image" onclick="this.style.display='none'; Codehighlighter1_176_620_Open_Text.style.display='none'; Codehighlighter1_176_620_Closed_Image.style.display='inline'; Codehighlighter1_176_620_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_176_620_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_176_620_Closed_Text.style.display='none'; Codehighlighter1_176_620_Open_Image.style.display='inline'; Codehighlighter1_176_620_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_176_620_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_176_620_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[maxn],&nbsp;b[maxn];<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,&nbsp;t,&nbsp;ans&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 align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;t&nbsp;)<br /><img id="Codehighlighter1_258_604_Open_Image" onclick="this.style.display='none'; Codehighlighter1_258_604_Open_Text.style.display='none'; Codehighlighter1_258_604_Closed_Image.style.display='inline'; Codehighlighter1_258_604_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_258_604_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_258_604_Closed_Text.style.display='none'; Codehighlighter1_258_604_Open_Image.style.display='inline'; Codehighlighter1_258_604_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_258_604_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_258_604_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans&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 align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;a[i];<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;b[i];<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort(&nbsp;a,&nbsp;a&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;n&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort(&nbsp;b,&nbsp;b&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;n,&nbsp;cmp&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;a[i]&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;b[i]&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;t&nbsp;)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;a[i]&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;b[i]&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;t;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;ans&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span></div></div><img src ="http://www.cppblog.com/vontroy/aggbug/128409.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-03 08:36 <a href="http://www.cppblog.com/vontroy/archive/2010/10/03/128409.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 1097 A hard puzzle</title><link>http://www.cppblog.com/vontroy/archive/2010/10/03/128381.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sat, 02 Oct 2010 16:39:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/03/128381.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128381.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/03/128381.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128381.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128381.html</trackback:ping><description><![CDATA[<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"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><span style="color: #008000">//</span><span style="color: #008000">找规律，每4个数循环一次</span><span style="color: #008000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_87_601_Open_Image" onclick="this.style.display='none'; Codehighlighter1_87_601_Open_Text.style.display='none'; Codehighlighter1_87_601_Closed_Image.style.display='inline'; Codehighlighter1_87_601_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_87_601_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_87_601_Closed_Text.style.display='none'; Codehighlighter1_87_601_Open_Image.style.display='inline'; Codehighlighter1_87_601_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_87_601_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_87_601_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;a,&nbsp;b;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;ans[</span><span style="color: #000000">5</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;a&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;b)<br /><img id="Codehighlighter1_154_585_Open_Image" onclick="this.style.display='none'; Codehighlighter1_154_585_Open_Text.style.display='none'; Codehighlighter1_154_585_Closed_Image.style.display='inline'; Codehighlighter1_154_585_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_154_585_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_154_585_Closed_Text.style.display='none'; Codehighlighter1_154_585_Open_Image.style.display='inline'; Codehighlighter1_154_585_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_154_585_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_154_585_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;b&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;)<br /><img id="Codehighlighter1_185_250_Open_Image" onclick="this.style.display='none'; Codehighlighter1_185_250_Open_Text.style.display='none'; Codehighlighter1_185_250_Closed_Image.style.display='inline'; Codehighlighter1_185_250_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_185_250_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_185_250_Closed_Text.style.display='none'; Codehighlighter1_185_250_Open_Image.style.display='inline'; Codehighlighter1_185_250_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_185_250_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_185_250_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">1</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">continue</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;a&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;)<br /><img id="Codehighlighter1_286_351_Open_Image" onclick="this.style.display='none'; Codehighlighter1_286_351_Open_Text.style.display='none'; Codehighlighter1_286_351_Closed_Image.style.display='inline'; Codehighlighter1_286_351_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_286_351_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_286_351_Closed_Text.style.display='none'; Codehighlighter1_286_351_Open_Image.style.display='inline'; Codehighlighter1_286_351_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_286_351_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_286_351_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">0</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">continue</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans[</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;a&nbsp;</span><span style="color: #000000">%</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">10</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans[</span><span style="color: #000000">2</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(ans[</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;a&nbsp;)&nbsp;</span><span style="color: #000000">%</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">10</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans[</span><span style="color: #000000">3</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(ans[</span><span style="color: #000000">2</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;a&nbsp;)&nbsp;</span><span style="color: #000000">%</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">10</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans[</span><span style="color: #000000">4</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(ans[</span><span style="color: #000000">3</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;a&nbsp;)&nbsp;</span><span style="color: #000000">%</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">10</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;tmp&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;b&nbsp;</span><span style="color: #000000">%</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">4</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;tmp&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;)&nbsp;tmp&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">4</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;ans[tmp]&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span></div><img src ="http://www.cppblog.com/vontroy/aggbug/128381.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-03 00:39 <a href="http://www.cppblog.com/vontroy/archive/2010/10/03/128381.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ 1007 DNA Sorting 字符串处理|稳定排序</title><link>http://www.cppblog.com/vontroy/archive/2010/10/02/128354.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sat, 02 Oct 2010 13:23:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/02/128354.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128354.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/02/128354.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128354.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128354.html</trackback:ping><description><![CDATA[<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"><img id="Codehighlighter1_0_48_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_48_Open_Text.style.display='none'; Codehighlighter1_0_48_Closed_Image.style.display='inline'; Codehighlighter1_0_48_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_0_48_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_0_48_Closed_Text.style.display='none'; Codehighlighter1_0_48_Open_Image.style.display='inline'; Codehighlighter1_0_48_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_0_48_Closed_Text">/**/</span><span id="Codehighlighter1_0_48_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">****************<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />字符串处理<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />稳定排序<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />*****************</span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;DNA<br /><img id="Codehighlighter1_144_188_Open_Image" onclick="this.style.display='none'; Codehighlighter1_144_188_Open_Text.style.display='none'; Codehighlighter1_144_188_Closed_Image.style.display='inline'; Codehighlighter1_144_188_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_144_188_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_144_188_Closed_Text.style.display='none'; Codehighlighter1_144_188_Open_Image.style.display='inline'; Codehighlighter1_144_188_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_144_188_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_144_188_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;pos;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;cnt;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;str;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;cmp(</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;DNA&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">a,&nbsp;</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;DNA&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">b)<br /><img id="Codehighlighter1_229_348_Open_Image" onclick="this.style.display='none'; Codehighlighter1_229_348_Open_Text.style.display='none'; Codehighlighter1_229_348_Closed_Image.style.display='inline'; Codehighlighter1_229_348_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_229_348_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_229_348_Closed_Text.style.display='none'; Codehighlighter1_229_348_Open_Image.style.display='inline'; Codehighlighter1_229_348_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_229_348_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_229_348_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(a.cnt&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;b.cnt)<br /><img id="Codehighlighter1_259_295_Open_Image" onclick="this.style.display='none'; Codehighlighter1_259_295_Open_Text.style.display='none'; Codehighlighter1_259_295_Closed_Image.style.display='inline'; Codehighlighter1_259_295_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_259_295_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_259_295_Closed_Text.style.display='none'; Codehighlighter1_259_295_Open_Image.style.display='inline'; Codehighlighter1_259_295_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_259_295_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_259_295_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;a.cnt&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;b.cnt;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img id="Codehighlighter1_310_346_Open_Image" onclick="this.style.display='none'; Codehighlighter1_310_346_Open_Text.style.display='none'; Codehighlighter1_310_346_Closed_Image.style.display='inline'; Codehighlighter1_310_346_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_310_346_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_310_346_Closed_Text.style.display='none'; Codehighlighter1_310_346_Open_Image.style.display='inline'; Codehighlighter1_310_346_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_310_346_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_310_346_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;a.pos&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;b.pos;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_362_870_Open_Image" onclick="this.style.display='none'; Codehighlighter1_362_870_Open_Text.style.display='none'; Codehighlighter1_362_870_Closed_Image.style.display='inline'; Codehighlighter1_362_870_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_362_870_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_362_870_Closed_Text.style.display='none'; Codehighlighter1_362_870_Open_Image.style.display='inline'; Codehighlighter1_362_870_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_362_870_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_362_870_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,&nbsp;m,&nbsp;count;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;DNA&nbsp;ans[</span><span style="color: #000000">110</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;str;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;m;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;m;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_475_754_Open_Image" onclick="this.style.display='none'; Codehighlighter1_475_754_Open_Text.style.display='none'; Codehighlighter1_475_754_Closed_Image.style.display='inline'; Codehighlighter1_475_754_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_475_754_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_475_754_Closed_Text.style.display='none'; Codehighlighter1_475_754_Open_Image.style.display='inline'; Codehighlighter1_475_754_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_475_754_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_475_754_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;str;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count&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 align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;j&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;k&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;j&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;k&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;k</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(str[j]&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;str[k])&nbsp;count</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans[i].str&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;str;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans[i].cnt&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;count;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans[i].pos&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;i;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;sort(ans,&nbsp;ans&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;m,&nbsp;cmp);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;m;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;ans[i].str&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span></div><img src ="http://www.cppblog.com/vontroy/aggbug/128354.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-02 21:23 <a href="http://www.cppblog.com/vontroy/archive/2010/10/02/128354.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ 1006 Biorhythms 中国剩余定理</title><link>http://www.cppblog.com/vontroy/archive/2010/10/02/128347.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sat, 02 Oct 2010 12:18:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/02/128347.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128347.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/02/128347.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128347.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128347.html</trackback:ping><description><![CDATA[<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"><img id="Codehighlighter1_0_261_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_261_Open_Text.style.display='none'; Codehighlighter1_0_261_Closed_Image.style.display='inline'; Codehighlighter1_0_261_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_0_261_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_0_261_Closed_Text.style.display='none'; Codehighlighter1_0_261_Open_Image.style.display='inline'; Codehighlighter1_0_261_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_0_261_Closed_Text">/**/</span><span id="Codehighlighter1_0_261_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">**************************************<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />比较经典的中国剩余定理~~<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />使33&#215;28被23除余1，用33&#215;28&#215;6=5544<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />使23&#215;33被28除余1，用23&#215;33&#215;19=14421<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />使23&#215;28被33除余1，用23&#215;28&#215;2=1288<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />（5544&#215;p+14421&#215;e+1288&#215;i）%（23&#215;28&#215;33）=n+d<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />n=（5544&#215;p+14421&#215;e+1288&#215;i-d）%（23&#215;28&#215;33）<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />***************************************</span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;std&nbsp;::&nbsp;cin;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;std&nbsp;::&nbsp;cout;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;std&nbsp;::&nbsp;endl;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;get__(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;b,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;c&nbsp;)<br /><img id="Codehighlighter1_393_514_Open_Image" onclick="this.style.display='none'; Codehighlighter1_393_514_Open_Text.style.display='none'; Codehighlighter1_393_514_Closed_Image.style.display='inline'; Codehighlighter1_393_514_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_393_514_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_393_514_Closed_Text.style.display='none'; Codehighlighter1_393_514_Open_Image.style.display='inline'; Codehighlighter1_393_514_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_393_514_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_393_514_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;ans;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;cnt&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;(&nbsp;a&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;b&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;cnt&nbsp;)&nbsp;</span><span style="color: #000000">%</span><span style="color: #000000">&nbsp;c&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;)<br /><img id="Codehighlighter1_467_488_Open_Image" onclick="this.style.display='none'; Codehighlighter1_467_488_Open_Text.style.display='none'; Codehighlighter1_467_488_Closed_Image.style.display='inline'; Codehighlighter1_467_488_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_467_488_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_467_488_Closed_Text.style.display='none'; Codehighlighter1_467_488_Open_Image.style.display='inline'; Codehighlighter1_467_488_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_467_488_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_467_488_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cnt</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;a&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;b&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;cnt;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_528_1089_Open_Image" onclick="this.style.display='none'; Codehighlighter1_528_1089_Open_Text.style.display='none'; Codehighlighter1_528_1089_Closed_Image.style.display='inline'; Codehighlighter1_528_1089_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_528_1089_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_528_1089_Closed_Text.style.display='none'; Codehighlighter1_528_1089_Open_Image.style.display='inline'; Codehighlighter1_528_1089_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_528_1089_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_528_1089_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&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;get__(&nbsp;</span><span style="color: #000000">28</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">33</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">23</span><span style="color: #000000">&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;_e&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;get__(&nbsp;</span><span style="color: #000000">23</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">33</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">28</span><span style="color: #000000">&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;_i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;get__(&nbsp;</span><span style="color: #000000">23</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">28</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">33</span><span style="color: #000000">&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;p,&nbsp;e,&nbsp;i,&nbsp;d;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;cas&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;p&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;e&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;d&nbsp;)<br /><img id="Codehighlighter1_711_1073_Open_Image" onclick="this.style.display='none'; Codehighlighter1_711_1073_Open_Text.style.display='none'; Codehighlighter1_711_1073_Closed_Image.style.display='inline'; Codehighlighter1_711_1073_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_711_1073_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_711_1073_Closed_Text.style.display='none'; Codehighlighter1_711_1073_Open_Image.style.display='inline'; Codehighlighter1_711_1073_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_711_1073_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_711_1073_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;p&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;e&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;e&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;d&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;d&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;)&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;ans&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(&nbsp;_p&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;p&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;_e&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;e&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;_i&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;d&nbsp;)&nbsp;</span><span style="color: #000000">%</span><span style="color: #000000">&nbsp;(&nbsp;</span><span style="color: #000000">23</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">28</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">33</span><span style="color: #000000">&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;ans&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">Case&nbsp;%d:&nbsp;the&nbsp;next&nbsp;triple&nbsp;peak&nbsp;occurs&nbsp;in&nbsp;%d&nbsp;days.\n</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;cas</span><span style="color: #000000">++</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">21252</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;ans&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;d);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">Case&nbsp;%d:&nbsp;the&nbsp;next&nbsp;triple&nbsp;peak&nbsp;occurs&nbsp;in&nbsp;%d&nbsp;days.\n</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;cas</span><span style="color: #000000">++</span><span style="color: #000000">,&nbsp;ans);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span></div><img src ="http://www.cppblog.com/vontroy/aggbug/128347.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-02 20:18 <a href="http://www.cppblog.com/vontroy/archive/2010/10/02/128347.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ 1005 I Think I Need a Houseboat</title><link>http://www.cppblog.com/vontroy/archive/2010/10/02/128345.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sat, 02 Oct 2010 11:57:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/02/128345.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128345.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/02/128345.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128345.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128345.html</trackback:ping><description><![CDATA[<p>&nbsp;</p>
<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"><img id="Codehighlighter1_0_223_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_223_Open_Text.style.display='none'; Codehighlighter1_0_223_Closed_Image.style.display='inline'; Codehighlighter1_0_223_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_0_223_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_0_223_Closed_Text.style.display='none'; Codehighlighter1_0_223_Open_Image.style.display='inline'; Codehighlighter1_0_223_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_0_223_Closed_Text">/**/</span><span id="Codehighlighter1_0_223_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">*****************************************<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />设需要n年<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />设半圆面积为&nbsp;S，半径为&nbsp;r<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />S&nbsp;=&nbsp;50&nbsp;*&nbsp;n;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />S&nbsp;=&nbsp;(PI&nbsp;*&nbsp;r&nbsp;*&nbsp;r)&nbsp;/&nbsp;2;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />解得&nbsp;n&nbsp;=&nbsp;(PI&nbsp;*&nbsp;r&nbsp;*&nbsp;r&nbsp;)&nbsp;/&nbsp;100;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />所给点到原点距离&nbsp;len&nbsp;=&nbsp;sqrt(&nbsp;x&nbsp;*&nbsp;x&nbsp;+&nbsp;y&nbsp;*&nbsp;y&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />令len&nbsp;=&nbsp;r即可解出&nbsp;n<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />******************************************</span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cmath</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;PI&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">3.1415927</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_345_699_Open_Image" onclick="this.style.display='none'; Codehighlighter1_345_699_Open_Text.style.display='none'; Codehighlighter1_345_699_Closed_Image.style.display='inline'; Codehighlighter1_345_699_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_345_699_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_345_699_Closed_Text.style.display='none'; Codehighlighter1_345_699_Open_Image.style.display='inline'; Codehighlighter1_345_699_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_345_699_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_345_699_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;x,&nbsp;y;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;cnt;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;cnt;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;pro&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;cnt</span><span style="color: #000000">--</span><span style="color: #000000">&nbsp;)<br /><img id="Codehighlighter1_434_650_Open_Image" onclick="this.style.display='none'; Codehighlighter1_434_650_Open_Text.style.display='none'; Codehighlighter1_434_650_Closed_Image.style.display='inline'; Codehighlighter1_434_650_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_434_650_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_434_650_Closed_Text.style.display='none'; Codehighlighter1_434_650_Open_Image.style.display='inline'; Codehighlighter1_434_650_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_434_650_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_434_650_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;x&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;y;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;len&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;sqrt(&nbsp;x&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;x&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;y&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;y&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(PI&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;len&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;len&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;(</span><span style="color: #000000">100</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1.0</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">Property&nbsp;%d:&nbsp;This&nbsp;property&nbsp;will&nbsp;begin&nbsp;eroding&nbsp;in&nbsp;year&nbsp;%d.\n</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;pro</span><span style="color: #000000">++</span><span style="color: #000000">,&nbsp;n&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">END&nbsp;OF&nbsp;OUTPUT.\n</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span></div><img src ="http://www.cppblog.com/vontroy/aggbug/128345.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-02 19:57 <a href="http://www.cppblog.com/vontroy/archive/2010/10/02/128345.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ 1004 Financial Management</title><link>http://www.cppblog.com/vontroy/archive/2010/10/02/128342.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sat, 02 Oct 2010 11:31:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/02/128342.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128342.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/02/128342.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128342.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128342.html</trackback:ping><description><![CDATA[<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"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;std&nbsp;::&nbsp;cin;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;std&nbsp;::&nbsp;cout;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;std&nbsp;::&nbsp;endl;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_107_292_Open_Image" onclick="this.style.display='none'; Codehighlighter1_107_292_Open_Text.style.display='none'; Codehighlighter1_107_292_Closed_Image.style.display='inline'; Codehighlighter1_107_292_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_107_292_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_107_292_Closed_Text.style.display='none'; Codehighlighter1_107_292_Open_Image.style.display='inline'; Codehighlighter1_107_292_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_107_292_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_107_292_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;ans;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;tmp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;ans&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 align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">12</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br /><img id="Codehighlighter1_192_238_Open_Image" onclick="this.style.display='none'; Codehighlighter1_192_238_Open_Text.style.display='none'; Codehighlighter1_192_238_Closed_Image.style.display='inline'; Codehighlighter1_192_238_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_192_238_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_192_238_Closed_Text.style.display='none'; Codehighlighter1_192_238_Open_Image.style.display='inline'; Codehighlighter1_192_238_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_192_238_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_192_238_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;tmp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;tmp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">$</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;ans&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">12.0</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span></div><img src ="http://www.cppblog.com/vontroy/aggbug/128342.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-02 19:31 <a href="http://www.cppblog.com/vontroy/archive/2010/10/02/128342.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ 1002 487-3279 字符串处理</title><link>http://www.cppblog.com/vontroy/archive/2010/10/02/128340.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sat, 02 Oct 2010 11:21:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/02/128340.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128340.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/02/128340.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128340.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128340.html</trackback:ping><description><![CDATA[<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"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;maxn&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">20000</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;MAXN&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">100000</span><span style="color: #000000">+</span><span style="color: #000000">10</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;std&nbsp;::&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;std&nbsp;::&nbsp;cout;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;std&nbsp;::&nbsp;endl;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_202_2379_Open_Image" onclick="this.style.display='none'; Codehighlighter1_202_2379_Open_Text.style.display='none'; Codehighlighter1_202_2379_Closed_Image.style.display='inline'; Codehighlighter1_202_2379_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_202_2379_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_202_2379_Closed_Text.style.display='none'; Codehighlighter1_202_2379_Open_Image.style.display='inline'; Codehighlighter1_202_2379_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_202_2379_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_202_2379_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;ans[MAXN];<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;tel[maxn];<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;store[maxn];<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;ok;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">~</span><span style="color: #000000">&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">n))<br /><img id="Codehighlighter1_323_2363_Open_Image" onclick="this.style.display='none'; Codehighlighter1_323_2363_Open_Text.style.display='none'; Codehighlighter1_323_2363_Closed_Image.style.display='inline'; Codehighlighter1_323_2363_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_323_2363_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_323_2363_Closed_Text.style.display='none'; Codehighlighter1_323_2363_Open_Image.style.display='inline'; Codehighlighter1_323_2363_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_323_2363_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_323_2363_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ok&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">false</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;count&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 align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(n</span><span style="color: #000000">--</span><span style="color: #000000">)<br /><img id="Codehighlighter1_395_1730_Open_Image" onclick="this.style.display='none'; Codehighlighter1_395_1730_Open_Text.style.display='none'; Codehighlighter1_395_1730_Closed_Image.style.display='inline'; Codehighlighter1_395_1730_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_395_1730_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_395_1730_Closed_Text.style.display='none'; Codehighlighter1_395_1730_Open_Image.style.display='inline'; Codehighlighter1_395_1730_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_395_1730_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_395_1730_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%s</span><span style="color: #000000">"</span><span style="color: #000000">,tel);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&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;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">,j&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;tel[i]&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">\0</span><span style="color: #000000">'</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_512_1686_Open_Image" onclick="this.style.display='none'; Codehighlighter1_512_1686_Open_Text.style.display='none'; Codehighlighter1_512_1686_Closed_Image.style.display='inline'; Codehighlighter1_512_1686_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_512_1686_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_512_1686_Closed_Text.style.display='none'; Codehighlighter1_512_1686_Open_Image.style.display='inline'; Codehighlighter1_512_1686_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_512_1686_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_512_1686_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(tel[i]</span><span style="color: #000000">-</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000">&gt;=</span><span style="color: #000000">0</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">tel[i]</span><span style="color: #000000">-</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000">&lt;=</span><span style="color: #000000">9</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;store[j</span><span style="color: #000000">++</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;tel[i];<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(tel[i]&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">-</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;j&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">3</span><span style="color: #000000">&nbsp;)<br /><img id="Codehighlighter1_672_1628_Open_Image" onclick="this.style.display='none'; Codehighlighter1_672_1628_Open_Text.style.display='none'; Codehighlighter1_672_1628_Closed_Image.style.display='inline'; Codehighlighter1_672_1628_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_672_1628_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_672_1628_Closed_Text.style.display='none'; Codehighlighter1_672_1628_Open_Image.style.display='inline'; Codehighlighter1_672_1628_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_672_1628_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_672_1628_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">ans[count]+='2';</span><span style="color: #008000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">A</span><span style="color: #000000">'</span><span style="color: #000000">||</span><span style="color: #000000">tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">B</span><span style="color: #000000">'</span><span style="color: #000000">||</span><span style="color: #000000">tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">C</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;store[j</span><span style="color: #000000">++</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">2</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">D</span><span style="color: #000000">'</span><span style="color: #000000">||</span><span style="color: #000000">tel[i]</span><span style="color: #000000">==</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">tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">F</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;store[j</span><span style="color: #000000">++</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">3</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">G</span><span style="color: #000000">'</span><span style="color: #000000">||</span><span style="color: #000000">tel[i]</span><span style="color: #000000">==</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">tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">I</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;store[j</span><span style="color: #000000">++</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">4</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">J</span><span style="color: #000000">'</span><span style="color: #000000">||</span><span style="color: #000000">tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">K</span><span style="color: #000000">'</span><span style="color: #000000">||</span><span style="color: #000000">tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">L</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;store[j</span><span style="color: #000000">++</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">5</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">M</span><span style="color: #000000">'</span><span style="color: #000000">||</span><span style="color: #000000">tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">N</span><span style="color: #000000">'</span><span style="color: #000000">||</span><span style="color: #000000">tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">O</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;store[j</span><span style="color: #000000">++</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">6</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">P</span><span style="color: #000000">'</span><span style="color: #000000">||</span><span style="color: #000000">tel[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">||</span><span style="color: #000000">tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">S</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;store[j</span><span style="color: #000000">++</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">7</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">T</span><span style="color: #000000">'</span><span style="color: #000000">||</span><span style="color: #000000">tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">U</span><span style="color: #000000">'</span><span style="color: #000000">||</span><span style="color: #000000">tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">V</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;store[j</span><span style="color: #000000">++</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">8</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">W</span><span style="color: #000000">'</span><span style="color: #000000">||</span><span style="color: #000000">tel[i]</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">tel[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">Y</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;store[j</span><span style="color: #000000">++</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">9</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;j</span><span style="color: #000000">==</span><span style="color: #000000">3</span><span style="color: #000000">&nbsp;)&nbsp;&nbsp;store[j</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">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans[count</span><span style="color: #000000">++</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;store;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std&nbsp;::&nbsp;sort(ans,ans</span><span style="color: #000000">+</span><span style="color: #000000">count);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;ans_count;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&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&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;count;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_1838_2217_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1838_2217_Open_Text.style.display='none'; Codehighlighter1_1838_2217_Closed_Image.style.display='inline'; Codehighlighter1_1838_2217_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1838_2217_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1838_2217_Closed_Text.style.display='none'; Codehighlighter1_1838_2217_Open_Image.style.display='inline'; Codehighlighter1_1838_2217_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1838_2217_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1838_2217_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans_count&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&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&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;j&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;count;&nbsp;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_1929_2022_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1929_2022_Open_Text.style.display='none'; Codehighlighter1_1929_2022_Closed_Image.style.display='inline'; Codehighlighter1_1929_2022_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1929_2022_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1929_2022_Closed_Text.style.display='none'; Codehighlighter1_1929_2022_Open_Image.style.display='inline'; Codehighlighter1_1929_2022_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1929_2022_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1929_2022_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(ans[j]</span><span style="color: #000000">==</span><span style="color: #000000">ans[i])&nbsp;ans_count</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(ans_count&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">)<br /><img id="Codehighlighter1_2068_2207_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2068_2207_Open_Text.style.display='none'; Codehighlighter1_2068_2207_Closed_Image.style.display='inline'; Codehighlighter1_2068_2207_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_2068_2207_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_2068_2207_Closed_Text.style.display='none'; Codehighlighter1_2068_2207_Open_Image.style.display='inline'; Codehighlighter1_2068_2207_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_2068_2207_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_2068_2207_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ok&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;ans[i]&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;ans_count&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i</span><span style="color: #000000">+=</span><span style="color: #000000">(ans_count</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">ok)&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">No&nbsp;duplicates.</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">for(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;count;&nbsp;i++)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">std&nbsp;::&nbsp;cout&nbsp;&lt;&lt;&nbsp;ans[i]&nbsp;&lt;&lt;&nbsp;std&nbsp;::&nbsp;endl;</span><span style="color: #008000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span></div><img src ="http://www.cppblog.com/vontroy/aggbug/128340.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-02 19:21 <a href="http://www.cppblog.com/vontroy/archive/2010/10/02/128340.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 1056 HangOver</title><link>http://www.cppblog.com/vontroy/archive/2010/10/02/128314.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sat, 02 Oct 2010 08:08:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/02/128314.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128314.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/02/128314.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128314.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128314.html</trackback:ping><description><![CDATA[<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"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_72_425_Open_Image" onclick="this.style.display='none'; Codehighlighter1_72_425_Open_Text.style.display='none'; Codehighlighter1_72_425_Closed_Image.style.display='inline'; Codehighlighter1_72_425_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_72_425_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_72_425_Closed_Text.style.display='none'; Codehighlighter1_72_425_Open_Image.style.display='inline'; Codehighlighter1_72_425_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_72_425_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_72_425_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;len;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;tmp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;ans;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;len,&nbsp;len&nbsp;)<br /><img id="Codehighlighter1_153_409_Open_Image" onclick="this.style.display='none'; Codehighlighter1_153_409_Open_Text.style.display='none'; Codehighlighter1_153_409_Closed_Image.style.display='inline'; Codehighlighter1_153_409_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_153_409_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_153_409_Closed_Text.style.display='none'; Codehighlighter1_153_409_Open_Image.style.display='inline'; Codehighlighter1_153_409_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_153_409_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_153_409_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&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 align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;ans</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br /><img id="Codehighlighter1_220_403_Open_Image" onclick="this.style.display='none'; Codehighlighter1_220_403_Open_Text.style.display='none'; Codehighlighter1_220_403_Closed_Image.style.display='inline'; Codehighlighter1_220_403_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_220_403_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_220_403_Closed_Text.style.display='none'; Codehighlighter1_220_403_Open_Image.style.display='inline'; Codehighlighter1_220_403_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_220_403_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_220_403_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;(&nbsp;ans&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1.0</span><span style="color: #000000">&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;tmp&nbsp;</span><span style="color: #000000">&gt;=</span><span style="color: #000000">&nbsp;len&nbsp;)<br /><img id="Codehighlighter1_301_393_Open_Image" onclick="this.style.display='none'; Codehighlighter1_301_393_Open_Text.style.display='none'; Codehighlighter1_301_393_Closed_Image.style.display='inline'; Codehighlighter1_301_393_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_301_393_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_301_393_Closed_Text.style.display='none'; Codehighlighter1_301_393_Open_Image.style.display='inline'; Codehighlighter1_301_393_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_301_393_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_301_393_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;ans&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;card(s)</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span></div><img src ="http://www.cppblog.com/vontroy/aggbug/128314.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-02 16:08 <a href="http://www.cppblog.com/vontroy/archive/2010/10/02/128314.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ 1458 Common Subsequence</title><link>http://www.cppblog.com/vontroy/archive/2010/10/02/128311.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sat, 02 Oct 2010 07:18:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/02/128311.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128311.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/02/128311.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128311.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128311.html</trackback:ping><description><![CDATA[<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"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" />&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" />&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;maxn&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">301</span><span style="color: #000000">;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;str1,&nbsp;str2;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()&nbsp;&nbsp;<br /><img id="Codehighlighter1_147_688_Open_Image" onclick="this.style.display='none'; Codehighlighter1_147_688_Open_Text.style.display='none'; Codehighlighter1_147_688_Closed_Image.style.display='inline'; Codehighlighter1_147_688_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_147_688_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_147_688_Closed_Text.style.display='none'; Codehighlighter1_147_688_Open_Image.style.display='inline'; Codehighlighter1_147_688_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_147_688_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_147_688_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;str1&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;str2&nbsp;)&nbsp;&nbsp;<br /><img id="Codehighlighter1_190_668_Open_Image" onclick="this.style.display='none'; Codehighlighter1_190_668_Open_Text.style.display='none'; Codehighlighter1_190_668_Closed_Image.style.display='inline'; Codehighlighter1_190_668_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_190_668_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_190_668_Closed_Text.style.display='none'; Codehighlighter1_190_668_Open_Image.style.display='inline'; Codehighlighter1_190_668_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_190_668_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_190_668_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;<br /><img id="Codehighlighter1_223_225_Open_Image" onclick="this.style.display='none'; Codehighlighter1_223_225_Open_Text.style.display='none'; Codehighlighter1_223_225_Closed_Image.style.display='inline'; Codehighlighter1_223_225_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_223_225_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_223_225_Closed_Text.style.display='none'; Codehighlighter1_223_225_Open_Image.style.display='inline'; Codehighlighter1_223_225_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;dp[maxn][maxn]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_223_225_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_223_225_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">0</span><span style="color: #000000">}</span></span><span style="color: #000000">;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;len1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;str1.length();&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;len2&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;str2.length();&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;len1;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;j&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;len2;&nbsp;j</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)&nbsp;&nbsp;<br /><img id="Codehighlighter1_404_617_Open_Image" onclick="this.style.display='none'; Codehighlighter1_404_617_Open_Text.style.display='none'; Codehighlighter1_404_617_Closed_Image.style.display='inline'; Codehighlighter1_404_617_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_404_617_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_404_617_Closed_Text.style.display='none'; Codehighlighter1_404_617_Open_Image.style.display='inline'; Codehighlighter1_404_617_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_404_617_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_404_617_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;str1[i&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;str2[j&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;)&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[i][j]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;dp[i&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">][j&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[i][j]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;max(&nbsp;dp[i][j&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">],&nbsp;dp[i&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">][j]&nbsp;);&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;dp[len1][len2]);&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" alt="" />}</span></span><span style="color: #000000">&nbsp;&nbsp;</span></div><img src ="http://www.cppblog.com/vontroy/aggbug/128311.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-02 15:18 <a href="http://www.cppblog.com/vontroy/archive/2010/10/02/128311.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 1788 Chinese remainder theorem again</title><link>http://www.cppblog.com/vontroy/archive/2010/10/02/128310.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sat, 02 Oct 2010 06:58:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/02/128310.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128310.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/02/128310.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128310.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128310.html</trackback:ping><description><![CDATA[<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"><img id="Codehighlighter1_0_165_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_165_Open_Text.style.display='none'; Codehighlighter1_0_165_Closed_Image.style.display='inline'; Codehighlighter1_0_165_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_0_165_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_0_165_Closed_Text.style.display='none'; Codehighlighter1_0_165_Open_Image.style.display='inline'; Codehighlighter1_0_165_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_0_165_Closed_Text">/**/</span><span id="Codehighlighter1_0_165_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">*********************************<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />N&nbsp;%&nbsp;MI&nbsp;=&nbsp;MI&nbsp;-&nbsp;a<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />因为&nbsp;a&nbsp;&lt;&nbsp;MI<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />原式等价于&nbsp;(N&nbsp;+&nbsp;a)&nbsp;%&nbsp;MI&nbsp;=&nbsp;0<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />所以此题为求&nbsp;M0&nbsp;到&nbsp;MI&nbsp;的最小公倍数<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />(注意精度问题,用__int64<img src="http://www.cppblog.com/Images/dot.gif"  alt="" />)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />**********************************</span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />__int64&nbsp;gcd(&nbsp;__int64&nbsp;a,&nbsp;__int64&nbsp;b&nbsp;)<br /><img id="Codehighlighter1_265_322_Open_Image" onclick="this.style.display='none'; Codehighlighter1_265_322_Open_Text.style.display='none'; Codehighlighter1_265_322_Closed_Image.style.display='inline'; Codehighlighter1_265_322_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_265_322_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_265_322_Closed_Text.style.display='none'; Codehighlighter1_265_322_Open_Image.style.display='inline'; Codehighlighter1_265_322_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_265_322_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_265_322_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;b&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;)&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;a;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;gcd(&nbsp;b,&nbsp;a&nbsp;</span><span style="color: #000000">%</span><span style="color: #000000">&nbsp;b&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />__int64&nbsp;lcm(&nbsp;__int64&nbsp;a,&nbsp;__int64&nbsp;b&nbsp;)<br /><img id="Codehighlighter1_361_395_Open_Image" onclick="this.style.display='none'; Codehighlighter1_361_395_Open_Text.style.display='none'; Codehighlighter1_361_395_Closed_Image.style.display='inline'; Codehighlighter1_361_395_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_361_395_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_361_395_Closed_Text.style.display='none'; Codehighlighter1_361_395_Open_Image.style.display='inline'; Codehighlighter1_361_395_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_361_395_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_361_395_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;a&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;b&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;gcd(&nbsp;a,&nbsp;b&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_409_682_Open_Image" onclick="this.style.display='none'; Codehighlighter1_409_682_Open_Text.style.display='none'; Codehighlighter1_409_682_Closed_Image.style.display='inline'; Codehighlighter1_409_682_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_409_682_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_409_682_Closed_Text.style.display='none'; Codehighlighter1_409_682_Open_Image.style.display='inline'; Codehighlighter1_409_682_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_409_682_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_409_682_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,&nbsp;k;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;tmp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;__int64&nbsp;ans;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;k,&nbsp;n&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;k&nbsp;)<br /><img id="Codehighlighter1_494_666_Open_Image" onclick="this.style.display='none'; Codehighlighter1_494_666_Open_Text.style.display='none'; Codehighlighter1_494_666_Closed_Image.style.display='inline'; Codehighlighter1_494_666_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_494_666_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_494_666_Closed_Text.style.display='none'; Codehighlighter1_494_666_Open_Image.style.display='inline'; Codehighlighter1_494_666_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_494_666_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_494_666_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br /><img id="Codehighlighter1_558_627_Open_Image" onclick="this.style.display='none'; Codehighlighter1_558_627_Open_Text.style.display='none'; Codehighlighter1_558_627_Closed_Image.style.display='inline'; Codehighlighter1_558_627_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_558_627_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_558_627_Closed_Text.style.display='none'; Codehighlighter1_558_627_Open_Image.style.display='inline'; Codehighlighter1_558_627_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_558_627_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_558_627_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;tmp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;lcm(&nbsp;ans,&nbsp;tmp&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;ans&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;k&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span></div><img src ="http://www.cppblog.com/vontroy/aggbug/128310.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-02 14:58 <a href="http://www.cppblog.com/vontroy/archive/2010/10/02/128310.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>数论及数学常用知识代码</title><link>http://www.cppblog.com/vontroy/archive/2010/10/02/128304.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sat, 02 Oct 2010 06:28:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/02/128304.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128304.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/02/128304.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128304.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128304.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: //数论模板#include&lt;iostream&gt;#include&lt;cmath&gt;using&nbsp;namespace&nbsp;std;//辗转相除法求最大公约数long&nbsp;gcd(long&nbsp;a,&nbsp;long&nbsp;b){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(b==0)&nbsp;&nbsp;&nbsp;&nbsp...&nbsp;&nbsp;<a href='http://www.cppblog.com/vontroy/archive/2010/10/02/128304.html'>阅读全文</a><img src ="http://www.cppblog.com/vontroy/aggbug/128304.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-02 14:28 <a href="http://www.cppblog.com/vontroy/archive/2010/10/02/128304.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>组合数学常用公式及算法</title><link>http://www.cppblog.com/vontroy/archive/2010/10/02/128303.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sat, 02 Oct 2010 06:25:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/02/128303.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128303.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/02/128303.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128303.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128303.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: /**//**********************************************1.&nbsp;C(m,n)=C(m,m-n)2.&nbsp;C(m,n)=C(m-1,n)+C(m-1,n-1)derangement&nbsp;D(n)&nbsp;=&nbsp;n!(1&nbsp;-&nbsp;1/1!&nbsp;+&nbsp;1/2!&nbsp;-&nbsp;1/3!&nb...&nbsp;&nbsp;<a href='http://www.cppblog.com/vontroy/archive/2010/10/02/128303.html'>阅读全文</a><img src ="http://www.cppblog.com/vontroy/aggbug/128303.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-02 14:25 <a href="http://www.cppblog.com/vontroy/archive/2010/10/02/128303.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 1018 Big Number</title><link>http://www.cppblog.com/vontroy/archive/2010/10/02/128302.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sat, 02 Oct 2010 06:22:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/02/128302.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128302.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/02/128302.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128302.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128302.html</trackback:ping><description><![CDATA[<p sizcache="3" sizset="5"><strong>斯特灵公式</strong>是一条用来取n<font color="#000000">阶乘近似值</font>的<font color="#000000">数学公式</font>。一般来说，当n很大的时候，n阶乘的计算量十分大，所以斯特灵公式十分好用，而且，即使在</p>
<p><a href="http://www.vontroy.tk/data/attachment/portal/201009/24/120206lc4lcpvzkz6hxu4v.jpg" target="_blank"></a>&nbsp;</p>
<p><a href="http://www.vontroy.tk/data/attachment/portal/201009/24/120206lc4lcpvzkz6hxu4v.jpg" target="_blank"></a></p>
<p sizcache="3" sizset="5">n很小的时候，斯特灵公式的取值已经十分准确。</p>
<p>公式为：<img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/vontroy/1.png" width="156" height="49" /><a href="http://www.vontroy.tk/data/attachment/portal/201009/24/120408yfy0cy0b0tbabbpn.png" target="_blank"></a></p>
<p>这就是说，对于足够大的整数<em>n</em>，这两个数互为近似值。更加精确地：<img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/vontroy/2.png" width="194" height="65" /><a href="http://www.vontroy.tk/data/attachment/portal/201009/24/120510g7w603ggyg3vkn76.png" target="_blank"></a></p>
<p>或者：<img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/vontroy/3.png" width="172" height="64" /><a href="http://www.vontroy.tk/data/attachment/portal/201009/24/120556jg3kk1w6mrn9kgr9.png" target="_blank"></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h1 style="color: #1a5cc8" align="center">Big Number</h1>
<p align="center"><font size="+0"><strong><span style="font-family: Arial; color: green; font-size: 12px; font-weight: bold">Time Limit: 20000/10000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 65536/32768 K (Java/Others)<br />Total Submission(s): 8759&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 3879<br /></span></strong></font><br /><br /></p>
<div class="panel_title" align="left"><strong>Problem Description</strong></div>
<div class="panel_content">In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of digits in the factorial of the number.</div>
<div class="panel_bottom">&nbsp;</div>
<div class="panel_title" align="left"><strong>Input</strong></div>
<div class="panel_content">Input consists of several lines of integer numbers. The first line contains an integer n, which is the number of cases to be tested, followed by n lines, one integer 1 &#8804; n &#8804; 10<sup>7</sup> on each line.</div>
<div class="panel_bottom">&nbsp;</div>
<div class="panel_title" align="left"><strong>Output</strong></div>
<div class="panel_content">The output contains the number of digits in the factorial of the integers appearing in the input.</div>
<div class="panel_bottom">&nbsp;</div>
<div class="panel_title" align="left"><strong>Sample Input</strong></div>
<div class="panel_content">
<pre><div style="font-family: Courier New,Courier,monospace">2
10
20</div>
</pre>
</div>
<div class="panel_title" align="left"><strong>Sample Output</strong></div>
<div class="panel_content">
<pre><div style="font-family: Courier New,Courier,monospace">7
19</div>
</pre>
</div>
<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"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><span style="color: #008000">//</span><span style="color: #008000">log10(n!)=(0.5*log(2*PI*n)+n*log(n)-n)/log(10)</span><span style="color: #008000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cmath</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;PI&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">3.1415926</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_147_471_Open_Image" onclick="this.style.display='none'; Codehighlighter1_147_471_Open_Text.style.display='none'; Codehighlighter1_147_471_Closed_Image.style.display='inline'; Codehighlighter1_147_471_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_147_471_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_147_471_Closed_Text.style.display='none'; Codehighlighter1_147_471_Open_Image.style.display='inline'; Codehighlighter1_147_471_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_147_471_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_147_471_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;tmp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;</span><span style="color: #000000">~</span><span style="color: #000000">scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">n&nbsp;)&nbsp;)<br /><img id="Codehighlighter1_208_455_Open_Image" onclick="this.style.display='none'; Codehighlighter1_208_455_Open_Text.style.display='none'; Codehighlighter1_208_455_Closed_Image.style.display='inline'; Codehighlighter1_208_455_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_208_455_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_208_455_Closed_Text.style.display='none'; Codehighlighter1_208_455_Open_Image.style.display='inline'; Codehighlighter1_208_455_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_208_455_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_208_455_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br /><img id="Codehighlighter1_255_449_Open_Image" onclick="this.style.display='none'; Codehighlighter1_255_449_Open_Text.style.display='none'; Codehighlighter1_255_449_Closed_Image.style.display='inline'; Codehighlighter1_255_449_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_255_449_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_255_449_Closed_Text.style.display='none'; Codehighlighter1_255_449_Open_Image.style.display='inline'; Codehighlighter1_255_449_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_255_449_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_255_449_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">tmp);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;cnt&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cnt&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;(</span><span style="color: #000000">0.5</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;log(&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;PI&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;tmp&nbsp;)&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;tmp&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;log(&nbsp;tmp&nbsp;)&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;tmp&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;log(</span><span style="color: #000000">10</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">)(cnt));<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span></div><img src ="http://www.cppblog.com/vontroy/aggbug/128302.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-02 14:22 <a href="http://www.cppblog.com/vontroy/archive/2010/10/02/128302.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>求两个或N个数的最大公约数(gcd)和最小公倍数(lcm)的较优算法</title><link>http://www.cppblog.com/vontroy/archive/2010/10/02/128301.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sat, 02 Oct 2010 06:20:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/02/128301.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128301.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/02/128301.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128301.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128301.html</trackback:ping><description><![CDATA[<p align=center><strong><font color=#f00000><span style="FONT-FAMILY: 宋体; FONT-SIZE: 13.5pt; mso-bidi-font-size: 11.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">求两个或</span><span style="FONT-SIZE: 13.5pt; mso-bidi-font-size: 11.0pt" lang=EN-US><font face=Calibri>N</font></span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 13.5pt; mso-bidi-font-size: 11.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">个数的最大公约数</span><span style="FONT-SIZE: 13.5pt; mso-bidi-font-size: 11.0pt" lang=EN-US><font face=Calibri>(gcd)</font></span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 13.5pt; mso-bidi-font-size: 11.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">和最小公倍数</span><span style="FONT-SIZE: 13.5pt; mso-bidi-font-size: 11.0pt" lang=EN-US><font face=Calibri>(lcm)</font></span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 13.5pt; mso-bidi-font-size: 11.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">的较优算法</span></font></strong><br></p>
<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"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #008000">//</span><span style="COLOR: #008000">两个数的最大公约数--欧几里得算法</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;gcd(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;a,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;b)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img id=Codehighlighter1_44_172_Open_Image onclick="this.style.display='none'; Codehighlighter1_44_172_Open_Text.style.display='none'; Codehighlighter1_44_172_Closed_Image.style.display='inline'; Codehighlighter1_44_172_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_44_172_Closed_Image onclick="this.style.display='none'; Codehighlighter1_44_172_Closed_Text.style.display='none'; Codehighlighter1_44_172_Open_Image.style.display='inline'; Codehighlighter1_44_172_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_44_172_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_44_172_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(a&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;b)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;swap(a,&nbsp;b);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(b&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 align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;a;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;gcd(b,&nbsp;a</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">b);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">n个数的最大公约数算法<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">说明:&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">把n个数保存为一个数组<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">参数为数组的指针和数组的大小(需要计算的数的个数)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">然后先求出gcd(a[0],a[1]),&nbsp;然后将所求的gcd与数组的下一个元素作为gcd的参数继续求gcd<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">这样就产生一个递归的求ngcd的算法</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;ngcd(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">a,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img id=Codehighlighter1_350_421_Open_Image onclick="this.style.display='none'; Codehighlighter1_350_421_Open_Text.style.display='none'; Codehighlighter1_350_421_Closed_Image.style.display='inline'; Codehighlighter1_350_421_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_350_421_Closed_Image onclick="this.style.display='none'; Codehighlighter1_350_421_Closed_Text.style.display='none'; Codehighlighter1_350_421_Open_Image.style.display='inline'; Codehighlighter1_350_421_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_350_421_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_350_421_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(n&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">a;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;gcd(a[n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">],&nbsp;ngcd(a,&nbsp;n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">));<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">两个数的最小公倍数(lcm)算法<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">lcm(a,&nbsp;b)&nbsp;=&nbsp;a*b/gcd(a,&nbsp;b)</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;lcm(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;a,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;b)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img id=Codehighlighter1_498_532_Open_Image onclick="this.style.display='none'; Codehighlighter1_498_532_Open_Text.style.display='none'; Codehighlighter1_498_532_Closed_Image.style.display='inline'; Codehighlighter1_498_532_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_498_532_Closed_Image onclick="this.style.display='none'; Codehighlighter1_498_532_Closed_Text.style.display='none'; Codehighlighter1_498_532_Open_Image.style.display='inline'; Codehighlighter1_498_532_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_498_532_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_498_532_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;a</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">b</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">gcd(a,&nbsp;b);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">n个数的最小公倍数算法<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">算法过程和n个数的最大公约数求法类似<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">求出头两个的最小公倍数,再将欺和大三个数求最小公倍数直到数组末尾<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">这样产生一个递归的求nlcm的算法</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;nlcm(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">a,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img id=Codehighlighter1_657_762_Open_Image onclick="this.style.display='none'; Codehighlighter1_657_762_Open_Text.style.display='none'; Codehighlighter1_657_762_Closed_Image.style.display='inline'; Codehighlighter1_657_762_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_657_762_Closed_Image onclick="this.style.display='none'; Codehighlighter1_657_762_Closed_Text.style.display='none'; Codehighlighter1_657_762_Open_Image.style.display='inline'; Codehighlighter1_657_762_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_657_762_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_657_762_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(n&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">a;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;lcm(a[n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">],&nbsp;nlcm(a,&nbsp;n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">));<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span></div>
<img src ="http://www.cppblog.com/vontroy/aggbug/128301.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-02 14:20 <a href="http://www.cppblog.com/vontroy/archive/2010/10/02/128301.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 1316 How Many Fibs?</title><link>http://www.cppblog.com/vontroy/archive/2010/10/02/128300.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sat, 02 Oct 2010 06:00:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/02/128300.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128300.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/02/128300.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128300.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128300.html</trackback:ping><description><![CDATA[比较水的大数。。。<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"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.util.</span><span style="color: #000000">*</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.math.</span><span style="color: #000000">*</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img id="Codehighlighter1_58_1039_Open_Image" onclick="this.style.display='none'; Codehighlighter1_58_1039_Open_Text.style.display='none'; Codehighlighter1_58_1039_Closed_Image.style.display='inline'; Codehighlighter1_58_1039_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_58_1039_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_58_1039_Closed_Text.style.display='none'; Codehighlighter1_58_1039_Open_Image.style.display='inline'; Codehighlighter1_58_1039_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;Main</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_58_1039_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_58_1039_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&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(&nbsp;String&nbsp;args[]&nbsp;)<br /><img id="Codehighlighter1_109_1037_Open_Image" onclick="this.style.display='none'; Codehighlighter1_109_1037_Open_Text.style.display='none'; Codehighlighter1_109_1037_Closed_Image.style.display='inline'; Codehighlighter1_109_1037_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_109_1037_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_109_1037_Closed_Text.style.display='none'; Codehighlighter1_109_1037_Open_Image.style.display='inline'; Codehighlighter1_109_1037_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_109_1037_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_109_1037_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Scanner&nbsp;in&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Scanner(&nbsp;System.in&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;cnt&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 align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BigInteger&nbsp;fib1,&nbsp;fib2;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BigInteger&nbsp;fla1,&nbsp;fla2;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;in.hasNext()&nbsp;)<br /><img id="Codehighlighter1_279_1031_Open_Image" onclick="this.style.display='none'; Codehighlighter1_279_1031_Open_Text.style.display='none'; Codehighlighter1_279_1031_Closed_Image.style.display='inline'; Codehighlighter1_279_1031_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_279_1031_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_279_1031_Closed_Text.style.display='none'; Codehighlighter1_279_1031_Open_Image.style.display='inline'; Codehighlighter1_279_1031_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_279_1031_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_279_1031_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fib1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;BigInteger.valueOf(</span><span style="color: #000000">1</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fib2&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;BigInteger.valueOf(</span><span style="color: #000000">2</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fla1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;in.nextBigInteger();<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fla2&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;in.nextBigInteger();<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;fla1.equals(BigInteger.valueOf(</span><span style="color: #000000">0</span><span style="color: #000000">))&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;fla2.equals(BigInteger.valueOf(</span><span style="color: #000000">0</span><span style="color: #000000">)))&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cnt&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 align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">&nbsp;)<br /><img id="Codehighlighter1_640_982_Open_Image" onclick="this.style.display='none'; Codehighlighter1_640_982_Open_Text.style.display='none'; Codehighlighter1_640_982_Closed_Image.style.display='inline'; Codehighlighter1_640_982_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_640_982_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_640_982_Closed_Text.style.display='none'; Codehighlighter1_640_982_Open_Image.style.display='inline'; Codehighlighter1_640_982_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_640_982_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_640_982_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;fib1.compareTo(fla1)&nbsp;</span><span style="color: #000000">&gt;=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;fib1.compareTo(fla2)&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;)&nbsp;cnt</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;fib2.compareTo(fla1)&nbsp;</span><span style="color: #000000">&gt;=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;fib2.compareTo(fla2)&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;)&nbsp;cnt</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;fib1.compareTo(fla2)&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;fib2.compareTo(fla2)&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;)&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fib1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;fib1.add(fib2);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fib2&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;fib2.add(fib1);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&nbsp;cnt&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span></div><img src ="http://www.cppblog.com/vontroy/aggbug/128300.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-02 14:00 <a href="http://www.cppblog.com/vontroy/archive/2010/10/02/128300.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ 2488 A Knight's Journey ----- DFS</title><link>http://www.cppblog.com/vontroy/archive/2010/07/29/121524.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Wed, 28 Jul 2010 23:18:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/07/29/121524.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/121524.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/07/29/121524.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/121524.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/121524.html</trackback:ping><description><![CDATA[<div style="padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; border-left-color: #cccccc; word-break: break-all; padding-top: 4px"><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">stdio.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><br /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;maxn&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">50</span><span style="color: #000000">;<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;b[</span><span style="color: #000000">8</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">2</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">2</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">},a[</span><span style="color: #000000">8</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">1</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">2</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">2</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">};<br /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;check[maxn][maxn],&nbsp;flag;<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;ansx[maxn],&nbsp;ansy[maxn];<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;row,&nbsp;col;<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;dfs(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;y,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;sum)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(sum&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;col&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;row)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&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">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">sum;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%c%d</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;ansy[i]</span><span style="color: #000000">+</span><span style="color: #000000">'</span><span style="color: #000000">A</span><span style="color: #000000">'</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;ansx[i]);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flag</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&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">;&nbsp;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">8</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">!</span><span style="color: #000000">flag;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">flag&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">!</span><span style="color: #000000">check[x</span><span style="color: #000000">+</span><span style="color: #000000">a[i]][y</span><span style="color: #000000">+</span><span style="color: #000000">b[i]]&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;x</span><span style="color: #000000">+</span><span style="color: #000000">a[i]</span><span style="color: #000000">&gt;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;x</span><span style="color: #000000">+</span><span style="color: #000000">a[i]</span><span style="color: #000000">&lt;=</span><span style="color: #000000">row&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;y</span><span style="color: #000000">+</span><span style="color: #000000">b[i]</span><span style="color: #000000">&gt;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;y</span><span style="color: #000000">+</span><span style="color: #000000">b[i]</span><span style="color: #000000">&lt;=</span><span style="color: #000000">col)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ansx[sum</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;x</span><span style="color: #000000">+</span><span style="color: #000000">a[i];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ansy[sum</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;y</span><span style="color: #000000">+</span><span style="color: #000000">b[i];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;check[x</span><span style="color: #000000">+</span><span style="color: #000000">a[i]][y</span><span style="color: #000000">+</span><span style="color: #000000">b[i]]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dfs(x</span><span style="color: #000000">+</span><span style="color: #000000">a[i],&nbsp;y</span><span style="color: #000000">+</span><span style="color: #000000">b[i],&nbsp;sum</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;check[x</span><span style="color: #000000">+</span><span style="color: #000000">a[i]][y</span><span style="color: #000000">+</span><span style="color: #000000">b[i]]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;cas;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">~</span><span style="color: #000000">scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">n))<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cas</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(n</span><span style="color: #000000">--</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flag&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(check,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(check));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">Scenario&nbsp;#%d:\n</span><span style="color: #000000">"</span><span style="color: #000000">,cas</span><span style="color: #000000">++</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d%d</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">row,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">col);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;check[</span><span style="color: #000000">1</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">1</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ansx[</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;ansy[</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dfs(</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">flag)&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">impossible\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}</span></div><img src ="http://www.cppblog.com/vontroy/aggbug/121524.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-07-29 07:18 <a href="http://www.cppblog.com/vontroy/archive/2010/07/29/121524.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ 3468 A Simple Problem with Integers</title><link>http://www.cppblog.com/vontroy/archive/2010/07/29/121523.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Wed, 28 Jul 2010 23:16:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/07/29/121523.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/121523.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/07/29/121523.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/121523.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/121523.html</trackback:ping><description><![CDATA[<div style="padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; border-left-color: #cccccc; word-break: break-all; padding-top: 4px"><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><br /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><br /></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;CNode<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;L,&nbsp;R;<br />&nbsp;&nbsp;&nbsp;&nbsp;CNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pLeft,&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pRight;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;nSum,&nbsp;Inc;<br />};<br /><br />CNode&nbsp;Tree[</span><span style="color: #000000">1000000</span><span style="color: #000000">];<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;nCount&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;BuildTree(&nbsp;CNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pRoot,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;L,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;R&nbsp;)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;L;<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;R;<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nSum&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">Inc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;L&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;R&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;nCount</span><span style="color: #000000">++</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pLeft&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Tree&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;nCount;<br />&nbsp;&nbsp;&nbsp;&nbsp;nCount</span><span style="color: #000000">++</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pRight&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Tree&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;nCount;<br />&nbsp;&nbsp;&nbsp;&nbsp;BuildTree(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pLeft,&nbsp;L,&nbsp;(&nbsp;L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;BuildTree(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pRight,&nbsp;(&nbsp;L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;R&nbsp;);<br />}<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;Insert(&nbsp;CNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pRoot,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;v&nbsp;)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;i&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nSum&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;v;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nSum&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;v;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;i&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Insert(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pLeft,&nbsp;i,&nbsp;v&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Insert(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pRight,&nbsp;i,&nbsp;v);<br />}<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;Add(&nbsp;CNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pRoot,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;b,&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;c&nbsp;)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;a&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;b&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">Inc&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;c;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nSum&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;(&nbsp;b&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;a&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;)&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;c;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;b&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pLeft,&nbsp;a,&nbsp;b,&nbsp;c&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(&nbsp;a&nbsp;</span><span style="color: #000000">&gt;=</span><span style="color: #000000">&nbsp;(pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add&nbsp;(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pRight,&nbsp;a,&nbsp;b,&nbsp;c&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pLeft,&nbsp;a,&nbsp;(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">,&nbsp;c&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pRight,&nbsp;(pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;b,&nbsp;c&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;QuerynSum(&nbsp;CNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pRoot,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;b&nbsp;)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(&nbsp;a&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;b&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;(pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nSum&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;(pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;)&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">Inc);<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nSum&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;(pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;)&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">Inc;<br />&nbsp;&nbsp;&nbsp;&nbsp;Add(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pLeft,&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L,&nbsp;(pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">,&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">Inc&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;Add(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pRight,&nbsp;(pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R,&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">Inc&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">Inc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;b&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;(pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;QuerynSum(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pLeft,&nbsp;a,&nbsp;b&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(&nbsp;a&nbsp;</span><span style="color: #000000">&gt;=</span><span style="color: #000000">&nbsp;(pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;QuerynSum&nbsp;(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pRight,&nbsp;a,&nbsp;b);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;QuerynSum(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pLeft,&nbsp;a,&nbsp;(pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;)&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;QuerynSum(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pRight,&nbsp;(pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;b&nbsp;)&nbsp;;<br />}<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,q;<br />&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d%d</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">n,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">q&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;nCount&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;BuildTree(&nbsp;Tree,&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;n);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;temp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">temp);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Insert(&nbsp;Tree,&nbsp;i,&nbsp;temp&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;c_temp[</span><span style="color: #000000">10</span><span style="color: #000000">];<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a,&nbsp;b,&nbsp;c;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;q;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%s</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;c_temp);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;c_temp[</span><span style="color: #000000">0</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">C</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d%d%d</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">a,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">b,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">c&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add(&nbsp;Tree,&nbsp;a,&nbsp;b,&nbsp;c);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d%d</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">a,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">b&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%I64d\n</span><span style="color: #000000">"</span><span style="color: #000000">,QuerynSum(&nbsp;Tree,&nbsp;a,&nbsp;b&nbsp;));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}</span></div><img src ="http://www.cppblog.com/vontroy/aggbug/121523.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-07-29 07:16 <a href="http://www.cppblog.com/vontroy/archive/2010/07/29/121523.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ 3264 Balanced Lineup </title><link>http://www.cppblog.com/vontroy/archive/2010/07/29/121522.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Wed, 28 Jul 2010 23:14:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/07/29/121522.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/121522.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/07/29/121522.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/121522.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/121522.html</trackback:ping><description><![CDATA[<div style="padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; border-left-color: #cccccc; word-break: break-all; padding-top: 4px"><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><br /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;MY_MAX&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">99999999</span><span style="color: #000000">;<br /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;MY_MIN&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">99999999</span><span style="color: #000000">;<br /><br /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><br /></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;CNode<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;R,&nbsp;L;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;nMax,&nbsp;nMin;<br />&nbsp;&nbsp;&nbsp;&nbsp;CNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pLeft,&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pRight;<br />}Tree[</span><span style="color: #000000">1000000</span><span style="color: #000000">];<br /><br /></span><span style="color: #008000">//</span><span style="color: #008000">CNode&nbsp;Tree[1000000];</span><span style="color: #008000"><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;nMax,&nbsp;nMin;<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;nCount&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;BuildTree(&nbsp;CNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pRoot,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;L,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;R&nbsp;)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;L;<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;R;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nMax&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;MY_MAX;<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nMin&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;MY_MIN;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;R&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;L&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nCount</span><span style="color: #000000">++</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pLeft&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Tree&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;nCount;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nCount</span><span style="color: #000000">++</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pRight&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Tree&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;nCount;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BuildTree(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pLeft,&nbsp;L,&nbsp;(&nbsp;L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BuildTree(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pRight,&nbsp;(&nbsp;L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;R&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;Insert(&nbsp;CNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pRoot,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;v&nbsp;)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">&nbsp;R&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;i&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">&nbsp;nMin&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">&nbsp;nMax&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;v;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nMin&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;min(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nMin,v&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nMax&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;max(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nMax,&nbsp;v&nbsp;);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;i&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Insert(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pLeft,&nbsp;i,&nbsp;v&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Insert(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pRight,&nbsp;i,&nbsp;v&nbsp;);<br />}<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;Query(&nbsp;CNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pRoot,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;s,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;e&nbsp;)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nMax&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;nMax&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nMin&nbsp;</span><span style="color: #000000">&gt;=</span><span style="color: #000000">&nbsp;nMin&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;s&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;e&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nMax&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;max(pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nMax,&nbsp;nMax);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nMin&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;min(pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nMin,nMin);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;e&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Query(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pLeft,&nbsp;s,&nbsp;e&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(&nbsp;s&nbsp;</span><span style="color: #000000">&gt;=</span><span style="color: #000000">&nbsp;(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Query(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pRight,&nbsp;s,&nbsp;e&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Query(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pLeft,&nbsp;s,&nbsp;(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Query(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pRight,&nbsp;(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;e&nbsp;)&nbsp;;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,&nbsp;q,&nbsp;s,&nbsp;e;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;h;<br />&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d%d</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">n,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">q);<br />&nbsp;&nbsp;&nbsp;&nbsp;nCount&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;BuildTree(&nbsp;Tree,&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;n);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">h);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Insert(&nbsp;Tree,&nbsp;i,&nbsp;h&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;q;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d%d</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">s,</span><span style="color: #000000">&amp;</span><span style="color: #000000">e&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nMax&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;MY_MAX;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nMin&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;MY_MIN;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Query(&nbsp;Tree,&nbsp;s,&nbsp;e&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;nMax&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;nMin)&nbsp;;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}</span></div><img src ="http://www.cppblog.com/vontroy/aggbug/121522.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-07-29 07:14 <a href="http://www.cppblog.com/vontroy/archive/2010/07/29/121522.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ 1611 The Suspects </title><link>http://www.cppblog.com/vontroy/archive/2010/07/29/121521.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Wed, 28 Jul 2010 23:09:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/07/29/121521.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/121521.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/07/29/121521.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/121521.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/121521.html</trackback:ping><description><![CDATA[<div style="padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; border-left-color: #cccccc; word-break: break-all; padding-top: 4px"><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><br /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;maxn&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">30000</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">5</span><span style="color: #000000">;<br /><br /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;father[maxn],rank[maxn];<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;init(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n&nbsp;)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;father[i]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;i;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rank[i]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;findSet(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n&nbsp;)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(father[n]&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;n)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;father[n]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;findSet(father[n]);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;father[n];<br />}<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;Union(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;b&nbsp;)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;findSet(&nbsp;a&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;y&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;findSet(&nbsp;b&nbsp;);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;x&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;y&nbsp;)&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;rank[x]&nbsp;</span><span style="color: #000000">&gt;=</span><span style="color: #000000">&nbsp;rank[y]&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;father[y]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;x;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rank[x]&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;rank[y];<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;father[x]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;y;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rank[y]&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;rank[x];<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;m,&nbsp;n,&nbsp;count,&nbsp;temp,&nbsp;first;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;</span><span style="color: #000000">~</span><span style="color: #000000">scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d%d</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">n,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">m&nbsp;)&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;n&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;init(n);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;m</span><span style="color: #000000">--</span><span style="color: #000000">&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d%d</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">count,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">first&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;count&nbsp;;i&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&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;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">temp);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Union(&nbsp;first,&nbsp;temp&nbsp;);<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;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,rank[findSet(</span><span style="color: #000000">0</span><span style="color: #000000">)]);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}</span></div><img src ="http://www.cppblog.com/vontroy/aggbug/121521.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-07-29 07:09 <a href="http://www.cppblog.com/vontroy/archive/2010/07/29/121521.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 1198 Farm Irrigation</title><link>http://www.cppblog.com/vontroy/archive/2010/07/29/121520.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Wed, 28 Jul 2010 23:04:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/07/29/121520.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/121520.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/07/29/121520.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/121520.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/121520.html</trackback:ping><description><![CDATA[<div style="padding-bottom: 4px; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; border-left-color: #cccccc; word-break: break-all; padding-top: 4px; background-color: #eeeeee; "><span style="color: #000000; ">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;bin[</span><span style="color: #000000">2500</span><span style="color: #000000">];<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;find(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x)<br />{</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;x</span><span style="color: #000000">==</span><span style="color: #000000">bin[x]</span><span style="color: #000000">?</span><span style="color: #000000">x:find(bin[x]);}<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;merge(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;y)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;x</span><span style="color: #000000">=</span><span style="color: #000000">find(x);<br />&nbsp;&nbsp;&nbsp;&nbsp;y</span><span style="color: #000000">=</span><span style="color: #000000">find(y);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(x</span><span style="color: #000000">!=</span><span style="color: #000000">y)&nbsp;bin[x]</span><span style="color: #000000">=</span><span style="color: #000000">y;<br />}<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[</span><span style="color: #000000">11</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;{</span><span style="color: #000000">9</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">3</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">12</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">6</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">5</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">10</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">11</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">13</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">14</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">7</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">15</span><span style="color: #000000">},&nbsp;m,&nbsp;n,&nbsp;i,&nbsp;j,&nbsp;map[</span><span style="color: #000000">50</span><span style="color: #000000">][</span><span style="color: #000000">50</span><span style="color: #000000">],&nbsp;total;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;c;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d&nbsp;%d</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">m,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">n),&nbsp;m&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getchar();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;m;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">i){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(j&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;j&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">j){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%c</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">c);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;map[i][j]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;c&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">65</span><span style="color: #000000">;<br />&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;getchar();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;m&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;n;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">i)&nbsp;bin[i]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;i;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;m;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">i)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(j&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;j&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">j){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(i&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;m&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;a[map[i][j]]&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0x04</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;a[map[i&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">][j]]&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0x01</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;merge(i&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;j,&nbsp;i&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;j);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(j&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;a[map[i][j]]&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0x02</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;a[map[i][j&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">]]&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0x08</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;merge(i&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;j,&nbsp;i&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;j&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(total&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;m&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;n;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">i)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(i&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;bin[i])&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">total;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;total);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}</span></div><img src ="http://www.cppblog.com/vontroy/aggbug/121520.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-07-29 07:04 <a href="http://www.cppblog.com/vontroy/archive/2010/07/29/121520.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 1010 Tempter of the Bone</title><link>http://www.cppblog.com/vontroy/archive/2010/07/29/121519.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Wed, 28 Jul 2010 22:58:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/07/29/121519.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/121519.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/07/29/121519.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/121519.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/121519.html</trackback:ping><description><![CDATA[<div style="padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; border-left-color: #cccccc; word-break: break-all; padding-top: 4px"><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cmath</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><br /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;maxn&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">10</span><span style="color: #000000">;<br /><br /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><br /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;escape;<br /><br /></span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;map[maxn][maxn];<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;dir[</span><span style="color: #000000">4</span><span style="color: #000000">][</span><span style="color: #000000">2</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;{{</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">},&nbsp;{</span><span style="color: #000000">1</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">},&nbsp;{</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">},&nbsp;{</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">1</span><span style="color: #000000">}};<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,&nbsp;m,&nbsp;t;<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;si,&nbsp;sj,&nbsp;di,&nbsp;dj;<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;dfs(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;y,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;cnt&nbsp;)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;escape&nbsp;)&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;x&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;di&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;y&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;dj&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;cnt&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;t&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;escape&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;temp&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;t&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;cnt&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;(&nbsp;fabs(di&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;x)&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;fabs(dj&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;y&nbsp;)&nbsp;);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;temp&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;temp&nbsp;</span><span style="color: #000000">%</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">;</span><span style="color: #008000">//</span><span style="color: #008000">奇偶剪枝</span><span style="color: #008000"><br /></span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;x&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;y&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;x&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;y&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;m&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">4</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;map[x</span><span style="color: #000000">+</span><span style="color: #000000">dir[i][</span><span style="color: #000000">0</span><span style="color: #000000">]][y</span><span style="color: #000000">+</span><span style="color: #000000">dir[i][</span><span style="color: #000000">1</span><span style="color: #000000">]]&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">X</span><span style="color: #000000">'</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;map[x</span><span style="color: #000000">+</span><span style="color: #000000">dir[i][</span><span style="color: #000000">0</span><span style="color: #000000">]][y</span><span style="color: #000000">+</span><span style="color: #000000">dir[i][</span><span style="color: #000000">1</span><span style="color: #000000">]]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">X</span><span style="color: #000000">'</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dfs(x</span><span style="color: #000000">+</span><span style="color: #000000">dir[i][</span><span style="color: #000000">0</span><span style="color: #000000">],&nbsp;y</span><span style="color: #000000">+</span><span style="color: #000000">dir[i][</span><span style="color: #000000">1</span><span style="color: #000000">],&nbsp;cnt</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;map[x</span><span style="color: #000000">+</span><span style="color: #000000">dir[i][</span><span style="color: #000000">0</span><span style="color: #000000">]][y</span><span style="color: #000000">+</span><span style="color: #000000">dir[i][</span><span style="color: #000000">1</span><span style="color: #000000">]]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">.</span><span style="color: #000000">'</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />}<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;m&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;t,&nbsp;m&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;t&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;wall&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;escape&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;j&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;m;&nbsp;j</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br />&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;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;map[i][j];<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;map[i][j]&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">D</span><span style="color: #000000">'</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;di&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;i;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dj&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;j;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(&nbsp;map[i][j]&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">S</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;si&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;i;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sj&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;j;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(&nbsp;map[i][j]&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">X</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wall&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;m&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;wall&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;t&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">NO\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">continue</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;map[si][sj]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">'</span><span style="color: #000000">X</span><span style="color: #000000">'</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dfs(&nbsp;si,&nbsp;sj,&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%s\n</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;escape&nbsp;</span><span style="color: #000000">?</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">YES</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">NO</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}</span></div><img src ="http://www.cppblog.com/vontroy/aggbug/121519.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-07-29 06:58 <a href="http://www.cppblog.com/vontroy/archive/2010/07/29/121519.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ 2528 Mayor's posters </title><link>http://www.cppblog.com/vontroy/archive/2010/07/28/121507.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Wed, 28 Jul 2010 14:45:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/07/28/121507.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/121507.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/07/28/121507.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/121507.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/121507.html</trackback:ping><description><![CDATA[<div style="padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; border-left-color: #cccccc; word-break: break-all; padding-top: 4px"><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">math.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n;<br /></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;CPost<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;L,R;<br />};<br />CPost&nbsp;posters[</span><span style="color: #000000">10100</span><span style="color: #000000">];<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x[</span><span style="color: #000000">20200</span><span style="color: #000000">];<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;hash[</span><span style="color: #000000">10000010</span><span style="color: #000000">];<br /></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;CNode&nbsp;<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;L,R;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;bCovered;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">本区间是否已经被完全覆盖&nbsp;</span><span style="color: #008000"><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;CNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pLeft,&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pRight;<br />};<br />CNode&nbsp;Tree[</span><span style="color: #000000">100000</span><span style="color: #000000">];<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;nNodeCount&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;Mid(&nbsp;CNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pRoot)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;(pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R)</span><span style="color: #000000">/</span><span style="color: #000000">2</span><span style="color: #000000">;<br />}<br /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;BuildTree(&nbsp;CNode&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pRoot,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;L,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;R)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;L;<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;R;<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">bCovered&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">false</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;L&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;R&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;nNodeCount&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pLeft&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Tree&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;nNodeCount;<br />&nbsp;&nbsp;&nbsp;&nbsp;nNodeCount&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pRight&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Tree&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;nNodeCount;<br />&nbsp;&nbsp;&nbsp;&nbsp;BuildTree(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pLeft,L,(L</span><span style="color: #000000">+</span><span style="color: #000000">R)</span><span style="color: #000000">/</span><span style="color: #000000">2</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;BuildTree(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pRight,(L</span><span style="color: #000000">+</span><span style="color: #000000">R)</span><span style="color: #000000">/</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">,R);<br />}<br /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;Post(&nbsp;CNode&nbsp;&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">pRoot,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;L,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;R)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">bCovered&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">false</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">L&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;L&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">R&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;R)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">bCovered&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;bResult&nbsp;;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;R&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;Mid(pRoot)&nbsp;)&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bResult&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Post(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pLeft,L,R);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;L&nbsp;</span><span style="color: #000000">&gt;=</span><span style="color: #000000">&nbsp;Mid(pRoot)&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bResult&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Post(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pRight,L,R);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;b1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Post(pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pLeft&nbsp;,L,Mid(pRoot));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;b2&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Post(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pRight,Mid(pRoot)&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">,R);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bResult&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;b1&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;b2;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">要更新根节点的覆盖情况</span><span style="color: #008000"><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pLeft</span><span style="color: #000000">-&gt;</span><span style="color: #000000">bCovered&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pRight</span><span style="color: #000000">-&gt;</span><span style="color: #000000">bCovered&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pRoot</span><span style="color: #000000">-&gt;</span><span style="color: #000000">bCovered&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;bResult;<br />}<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;t;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i,j,k;<br />&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">t);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;nCaseNo&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(t</span><span style="color: #000000">--</span><span style="color: #000000">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nCaseNo&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">n);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;nCount&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;i&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d%d</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;posters[i].L,</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;posters[i].R&nbsp;);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x[nCount</span><span style="color: #000000">++</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;posters[i].L;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x[nCount</span><span style="color: #000000">++</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;posters[i].R;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort(x,x</span><span style="color: #000000">+</span><span style="color: #000000">nCount);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nCount&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;unique(x,x</span><span style="color: #000000">+</span><span style="color: #000000">nCount)&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;x;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">去掉重复元素</span><span style="color: #008000"><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;nCount;i&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hash[x[i]]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;i;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nNodeCount&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BuildTree(&nbsp;Tree,</span><span style="color: #000000">0</span><span style="color: #000000">,nCount&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;nSum&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;i&nbsp;</span><span style="color: #000000">&gt;=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;i&nbsp;</span><span style="color: #000000">--</span><span style="color: #000000">&nbsp;)&nbsp;{&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;从后往前看板是否看得见</span><span style="color: #008000"><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;Post(Tree,hash[posters[i].L],hash[posters[i].R]))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nSum&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,nSum);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}</span></div><img src ="http://www.cppblog.com/vontroy/aggbug/121507.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-07-28 22:45 <a href="http://www.cppblog.com/vontroy/archive/2010/07/28/121507.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ACM初学经典题（字符串处理+对字符串的排序与检索）</title><link>http://www.cppblog.com/vontroy/archive/2010/05/26/116411.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Wed, 26 May 2010 10:32:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/05/26/116411.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/116411.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/05/26/116411.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/116411.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/116411.html</trackback:ping><description><![CDATA[输入一个字典（用******结尾），然后再输入若干单词。每输入一个单词w，你都需要在字典中找出所有可以用w的字母重排后得到的单词，并按照字典序从小到大的顺序在一行中输出（如果不存在，输出:( &nbsp;）输入单词之间用空格或空行隔开。注意，字典中的单词不一定按字典排列。<br><br>样例输入：
<div>
<div>tarp given score refund only trap work earn course pepper part<br>******<br>resco nfudre aptr sett oresuc</div>
<div>样例输出：</div>
<div>score</div>
<div>refund</div>
<div>part tarp trap</div>
<div>：(</div>
<div>course</div>
<div>代码：<br>
<div style="PADDING-BOTTOM: 4px; BACKGROUND-COLOR: rgb(238,238,238); PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; BORDER-LEFT-COLOR: rgb(204,204,204); WORD-BREAK: break-all; PADDING-TOP: 4px"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="COLOR: #000000">#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">algorithm</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><br></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;maxn&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1000</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">;<br><br></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000">&nbsp;std&nbsp;::&nbsp;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000">&nbsp;std&nbsp;::&nbsp;sort;<br></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000">&nbsp;std&nbsp;::&nbsp;cin;<br></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000">&nbsp;std&nbsp;::&nbsp;cout;<br></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000">&nbsp;std&nbsp;::&nbsp;endl;<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&nbsp;word[maxn];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">用string类，方便对字符串排序</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;sorted[maxn][maxn],buf[maxn];<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(&nbsp;;&nbsp;;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">&nbsp;word[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(word[i][</span><span style="COLOR: #000000">0</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">)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">把字典存入word[]中</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;sort(word,word</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">先把字典排序</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000"><br>&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;t</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;t</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">i;&nbsp;t</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcpy(sorted[t],word[t].c_str());&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">把字典中的数据存入另一个数组里</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort(sorted[t],sorted[t]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">strlen(sorted[t]));&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">把存储完的字典中每一个单词的字母排序</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%s</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;buf))<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;found&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&nbsp;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort(buf,buf</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">strlen(buf));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">把读入的字符串按字母排序</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000"><br>&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;t</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;t&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;i&nbsp;;&nbsp;t</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">从排序后的字典中查找</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">strcmp(buf,sorted[t]))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">如果找到</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&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;found&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;word[t]&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">输出原字典中对应的单词</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&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="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">found)&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">:(---&gt;&gt;&gt;Not&nbsp;found</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">如果没有找到则输出Not&nbsp;found</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>}<br></span></div>
</div>
</div>
<img src ="http://www.cppblog.com/vontroy/aggbug/116411.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-05-26 18:32 <a href="http://www.cppblog.com/vontroy/archive/2010/05/26/116411.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ 1001 Exponentiation </title><link>http://www.cppblog.com/vontroy/archive/2010/05/26/116341.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Tue, 25 May 2010 23:30:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/05/26/116341.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/116341.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/05/26/116341.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/116341.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/116341.html</trackback:ping><description><![CDATA[<div style="text-align: center; padding-bottom: 32px; padding-left: 32px; padding-right: 32px; font-family: Arial, Helvetica, sans-serif; color: blue; font-size: 18pt; border-left-color: #bbbbbb; font-weight: bold; padding-top: 32px; background-origin: initial; background-clip: initial; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; background-color: #ffffff; " lang="en-US" class="ptt">Exponentiation</div>
<div style="text-align: center; padding-bottom: 32px; background-color: #ffffff; padding-left: 32px; padding-right: 32px; font-family: Arial, Helvetica, sans-serif; font-size: 12pt; border-left-color: #bbbbbb; padding-top: 32px; background-origin: initial; background-clip: initial; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px" class="plm">
<table align="center">
    <tbody>
        <tr>
            <td><strong>Time Limit:</strong>&nbsp;500MS</td>
            <td width="10"></td>
            <td><strong>Memory Limit:</strong>&nbsp;10000K</td>
        </tr>
        <tr>
            <td><strong>Total Submissions:</strong>&nbsp;68964</td>
            <td width="10"></td>
            <td><strong>Accepted:</strong>&nbsp;16146</td>
        </tr>
    </tbody>
</table>
</div>
<p style="text-align: left; padding-bottom: 6px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; color: blue; font-size: 18pt; font-weight: bold; padding-top: 6px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px" class="pst">Description</p>
<div style="padding-bottom: 32px; background-color: #ffffff; padding-left: 32px; padding-right: 32px; font-family: 'Times New Roman', Times, serif; font-size: 12pt; border-left-color: #bbbbbb; padding-top: 32px; background-origin: initial; background-clip: initial; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px" lang="en-US" class="ptx">Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems.&nbsp;<br /><br />This problem requires that you write a program to compute the exact value of R<sup>n</sup>&nbsp;where R is a real number ( 0.0 &lt; R &lt; 99.999 ) and n is an integer such that 0 &lt; n &lt;= 25.</div>
<p style="text-align: left; padding-bottom: 6px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; color: blue; font-size: 18pt; font-weight: bold; padding-top: 6px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px" class="pst">Input</p>
<div style="padding-bottom: 32px; background-color: #ffffff; padding-left: 32px; padding-right: 32px; font-family: 'Times New Roman', Times, serif; font-size: 12pt; border-left-color: #bbbbbb; padding-top: 32px; background-origin: initial; background-clip: initial; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px" lang="en-US" class="ptx">The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9.</div>
<p style="text-align: left; padding-bottom: 6px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; color: blue; font-size: 18pt; font-weight: bold; padding-top: 6px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px" class="pst">Output</p>
<div style="padding-bottom: 32px; background-color: #ffffff; padding-left: 32px; padding-right: 32px; font-family: 'Times New Roman', Times, serif; font-size: 12pt; border-left-color: #bbbbbb; padding-top: 32px; background-origin: initial; background-clip: initial; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px" lang="en-US" class="ptx">The output will consist of one line for each line of input giving the exact value of R^n. Leading zeros should be suppressed in the output. Insignificant trailing zeros must not be printed. Don't print the decimal point if the result is an integer.</div>
<p style="text-align: left; padding-bottom: 6px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; color: blue; font-size: 18pt; font-weight: bold; padding-top: 6px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px" class="pst">Sample Input</p>
<span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px">
<pre style="font-family: 'Courier New', Courier, monospace; font-size: 12pt" class="sio">95.123 12
0.4321 20
5.1234 15
6.7592  9
98.999 10
1.0100 12
</pre>
</span></span>
<p style="text-align: left; padding-bottom: 6px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Arial, Helvetica, sans-serif; color: blue; font-size: 18pt; font-weight: bold; padding-top: 6px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px" class="pst">Sample Output</p>
<span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">
<pre style="font-family: 'Courier New', Courier, monospace; font-size: 12pt" class="sio">548815620517731830194541.899025343415715973535967221869852721
.00000005148554641076956121994511276767154838481760200726351203835429763013462401
43992025569.928573701266488041146654993318703707511666295476720493953024
29448126.764121021618164430206909037173276672
90429072743629540498.107596019456651774561044010001
1.126825030131969720661201</pre>
<pre style="font-family: 'Courier New', Courier, monospace; font-size: 12pt; " class="sio">虽然效率低点儿，但代码非常简单，容易实现，真正比赛还是很好用的。。。<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->import&nbsp;java.io.*;<br />import&nbsp;java.util.*;<br />import&nbsp;java.math.*;<br /><br /><span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;Main{<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;main(&nbsp;String&nbsp;args[]&nbsp;)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BigDecimal&nbsp;num;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;n;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;r;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Scanner&nbsp;cin&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;Scanner(System.<span style="color: #0000FF; ">in</span>);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">while</span>(cin.hasNextBigDecimal())<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num&nbsp;=&nbsp;cin.nextBigDecimal();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n&nbsp;=&nbsp;cin.nextInt();<br />&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;num&nbsp;=&nbsp;num.pow(n);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r&nbsp;=&nbsp;num.stripTrailingZeros().toPlainString();<span style="color: #008000; ">//</span><span style="color: #008000; ">BigDecimal.toPlainString&nbsp;避免输出时产生科学计数法形式</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(r.startsWith("0."))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r&nbsp;=&nbsp;r.substring(1);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.<span style="color: #0000FF; ">out</span>.println(r);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}</div></pre>
</span></span><img src ="http://www.cppblog.com/vontroy/aggbug/116341.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-05-26 07:30 <a href="http://www.cppblog.com/vontroy/archive/2010/05/26/116341.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ACM中Java的应用</title><link>http://www.cppblog.com/vontroy/archive/2010/05/24/116233.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Mon, 24 May 2010 08:42:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/05/24/116233.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/116233.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/05/24/116233.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/116233.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/116233.html</trackback:ping><description><![CDATA[<p>先说一下Java对于ACM的一些优点吧：<br>(1) 对于熟悉C/C++的程序员来说Java 并不难学，两周时间基本可以搞定一般的编程，再用些时间了解一下Java库就行了。Java的语法和C++非常类似，可以说是C++的升级版，只是更加强调面向对象思想而已。（个人见解。。。）</p>
<p>(2) 在一般比赛中，Java程序会有额外的时间和空间，但真正进行大规模运算时Java并不比C/C++慢，输入输出效率比较低而已<br>(3) Java 代码简单且功能强大，有些像高精度之类的算法用Java实现起来更为简洁方便（ACM真正比赛时是讲究做题速度的，任何题只要能过就行，而不必过于要求程序的速度有多高，不超时就好）。<br><br>***小技巧：某些题目用Java超时的话可以用Java打表然后用C/C++提交<br></p>
<p>(4) 用Java不易犯细微的错误，比如C/C++中的指针， &#8220;if (n = m) ... &#8221; 等。</p>
<p>(5) 目前Eclipse已成基本配置，写Java程序反而比C/C++更方便调试。在具体竞赛时也算多一种选择。<br></p>
关于ACM中应用的一些问题：<br>(1) JDK 1.5.0 及其以上版本提供的Scanner类为输入提供了良好的基础，很好地优化Java的输入问题。<br>&nbsp;&nbsp;&nbsp;&nbsp; 代码如下：<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"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000">&nbsp;java.io.</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000">&nbsp;java.util.</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;<br><img id=Codehighlighter1_55_185_Open_Image onclick="this.style.display='none'; Codehighlighter1_55_185_Open_Text.style.display='none'; Codehighlighter1_55_185_Closed_Image.style.display='inline'; Codehighlighter1_55_185_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_55_185_Closed_Image onclick="this.style.display='none'; Codehighlighter1_55_185_Closed_Text.style.display='none'; Codehighlighter1_55_185_Open_Image.style.display='inline'; Codehighlighter1_55_185_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Main&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_55_185_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_55_185_Open_Text><span style="COLOR: #000000">{&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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;<br><img id=Codehighlighter1_100_182_Open_Image onclick="this.style.display='none'; Codehighlighter1_100_182_Open_Text.style.display='none'; Codehighlighter1_100_182_Closed_Image.style.display='inline'; Codehighlighter1_100_182_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_100_182_Closed_Image onclick="this.style.display='none'; Codehighlighter1_100_182_Closed_Text.style.display='none'; Codehighlighter1_100_182_Open_Image.style.display='inline'; Codehighlighter1_100_182_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_100_182_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_100_182_Open_Text><span style="COLOR: #000000">{&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Scanner&nbsp;cin&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;Scanner(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;BufferedInputStream(System.in));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="http://www.cppblog.com/Images/dot.gif">&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000">&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000">&nbsp;</span></div>
<br>
<p>也可以直接 Scanner cin = new Scanner(System.in); 加Buffer可能会快一些。<br><br>(2)&nbsp;读一个整数：&nbsp;&nbsp; int n = cin.nextInt();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 相当于&nbsp;&nbsp; scanf("%d", &amp;n);&nbsp;&nbsp; 或 cin &gt;&gt; n; <br>&nbsp; &nbsp;&nbsp; 读一个字符串：String s = cin.next();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 相当于&nbsp;&nbsp; scanf("%s", s);&nbsp;&nbsp;&nbsp; 或 cin &gt;&gt; s;&nbsp;<br>&nbsp;&nbsp; &nbsp; 读一个浮点数：double t = cin.nextDouble();&nbsp;&nbsp; 相当于&nbsp;&nbsp; scanf("%lf", &amp;t); 或 cin &gt;&gt; t; <br>&nbsp;&nbsp; &nbsp; 读一整行：&nbsp;&nbsp;&nbsp;&nbsp; String s = cin.nextLine();&nbsp;&nbsp;&nbsp;&nbsp; 相当于&nbsp;&nbsp; gets(s);&nbsp; 或 cin.getline(...); <br>&nbsp;&nbsp; &nbsp; 判断是否有下一个输入可以用 cin.hasNext() 或 cin.hasNextInt() 或 cin.hasNextDouble() </p>
<br>(3)&nbsp;输出一般可以直接用 System.out.print() 和 System.out.println()，前者不输出换行，而后者输出。 <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"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">System.out.println(n);&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;n&nbsp;为&nbsp;int&nbsp;型&nbsp;同一行输出多个整数可以用&nbsp;</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">System.out.println(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;Integer(n).toString()&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;Integer(m).toString());&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">也可重新定义：&nbsp;</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;PrintWriter&nbsp;cout&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;PrintWriter(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;BufferedOutputStream(System.out));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">cout.println(n);&nbsp;</span></div>
<br>(4)对于输出浮点数保留几位小数的问题，可以使用DecimalFormat类， <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"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000">&nbsp;java.text.</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">;&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;DecimalFormat&nbsp;f&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;DecimalFormat(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">#.00#</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;DecimalFormat&nbsp;g&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;DecimalFormat(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">0.000</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;a&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">123.45678</span><span style="COLOR: #000000">,&nbsp;b&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0.12</span><span style="COLOR: #000000">;&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(f.format(a));&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(f.format(b));&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(g.format(b));&nbsp;</span></div>
<p><strong>大数：</strong></p>
<p>BigInteger 和 BigDecimal 是在java.math包中已有的类，前者表示整数，后者表示浮点数 <br></p>
<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"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000">&nbsp;java.math.</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;需要引入&nbsp;java.math&nbsp;包&nbsp;</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #000000">BigInteger&nbsp;a&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;BigInteger.valueOf(</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">);&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">BigInteger&nbsp;b&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;BigInteger.valueOf(</span><span style="COLOR: #000000">50</span><span style="COLOR: #000000">);&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">BigInteger&nbsp;c&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;a.add(b)&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;c&nbsp;=&nbsp;a&nbsp;+&nbsp;b;&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">主要有以下方法可以使用：&nbsp;</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #000000">BigInteger&nbsp;add(BigInteger&nbsp;other)&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">BigInteger&nbsp;subtract(BigInteger&nbsp;other)&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">BigInteger&nbsp;multiply(BigInteger&nbsp;other)&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">BigInteger&nbsp;divide(BigInteger&nbsp;other)&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">BigInteger&nbsp;mod(BigInteger&nbsp;other)&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;compareTo(BigInteger&nbsp;other)&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;BigInteger&nbsp;valueOf(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;x)&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">输出数字时直接使用&nbsp;System.out.println(a)&nbsp;即可</span></div>
<strong><br>字符串：<br></strong>
<p><br>String 类用来存储字符串，可以用charAt方法来取出其中某一字节，计数从0开始： </p>
<p>String a = "Hello";&nbsp;&nbsp;&nbsp; // a.charAt(1) = 'e' </p>
<p>用substring方法可得到子串，如上例</p>
<p>System.out.println(a.substring(0, 4))&nbsp;&nbsp;&nbsp;&nbsp; // output "Hell" </p>
<p>注意第2个参数位置上的字符不包括进来。这样做使得 s.substring(a, b) 总是有 b-a个字符。 </p>
<p>字符串连接可以直接用 + 号，如 </p>
<p>String a = "Hello"; <br>String b = "world"; <br>System.out.println(a + ", " + b + "!");&nbsp;&nbsp;&nbsp; // output "Hello, world!" </p>
<p>如想直接将字符串中的某字节改变，可以使用另外的StringBuffer类。 </p>
<strong><br>调用递归（或其他动态方法）</strong>
<p>在主类中 main 方法必须是 public static void 的，在 main 中调用非static类时会有警告信息， <br>可以先建立对象，然后通过对象调用方法：<br></p>
<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"><img id=Codehighlighter1_18_227_Open_Image onclick="this.style.display='none'; Codehighlighter1_18_227_Open_Text.style.display='none'; Codehighlighter1_18_227_Closed_Image.style.display='inline'; Codehighlighter1_18_227_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_18_227_Closed_Image onclick="this.style.display='none'; Codehighlighter1_18_227_Closed_Text.style.display='none'; Codehighlighter1_18_227_Open_Image.style.display='inline'; Codehighlighter1_18_227_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Main&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_18_227_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_18_227_Open_Text><span style="COLOR: #000000">{&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="http://www.cppblog.com/Images/dot.gif">&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;dfs(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;a)&nbsp;<br><img id=Codehighlighter1_47_111_Open_Image onclick="this.style.display='none'; Codehighlighter1_47_111_Open_Text.style.display='none'; Codehighlighter1_47_111_Closed_Image.style.display='inline'; Codehighlighter1_47_111_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_47_111_Closed_Image onclick="this.style.display='none'; Codehighlighter1_47_111_Closed_Text.style.display='none'; Codehighlighter1_47_111_Open_Image.style.display='inline'; Codehighlighter1_47_111_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_47_111_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_47_111_Open_Text><span style="COLOR: #000000">{&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(<img src="http://www.cppblog.com/Images/dot.gif">)&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">;&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="http://www.cppblog.com/Images/dot.gif">&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dfs(a</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000">&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&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;<br><img id=Codehighlighter1_156_224_Open_Image onclick="this.style.display='none'; Codehighlighter1_156_224_Open_Text.style.display='none'; Codehighlighter1_156_224_Closed_Image.style.display='inline'; Codehighlighter1_156_224_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_156_224_Closed_Image onclick="this.style.display='none'; Codehighlighter1_156_224_Closed_Text.style.display='none'; Codehighlighter1_156_224_Open_Image.style.display='inline'; Codehighlighter1_156_224_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_156_224_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_156_224_Open_Text><span style="COLOR: #000000">{&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="http://www.cppblog.com/Images/dot.gif">&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Main&nbsp;e&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;Main();&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.dfs(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="http://www.cppblog.com/Images/dot.gif">&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000">&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000">&nbsp;</span></div>
<br>
<p><strong>其他注意的事项：</strong></p>
<p>(1) Java 是面向对象的语言，思考方法需要变换一下，里面的函数统称为方法，不要搞错。 </p>
<p>(2) Java 里的数组有些变动，多维数组的内部其实都是指针，所以Java不支持fill多维数组。 <br>数组定义后必须初始化，如 int[] a = new int[100]; </p>
<p>(3) 布尔类型为 boolean，只有true和false二值，在 if (...) / while (...) 等语句的条件中必须为boolean类型。 <br>在C/C++中的 if (n % 2) ... 在Java中无法编译通过。 </p>
<p>(4) 下面在java.util包里Arrays类的几个方法可替代C/C++里的memset、qsort/sort 和 bsearch: </p>
<p>Arrays.fill() <br>Arrays.sort() <br>Arrays.binarySearch()&nbsp;&nbsp; <br><br>虽然Java功能很强大，但不能完全依赖他，毕竟C和C++还是ACM/ICPC的主流语言，适当地使用才能有效提高比赛中的成绩。。。<br><br>附：<br>例题：POJ 1001<br></p>
<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: #008080">&nbsp;1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000">&nbsp;java.io.</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000">&nbsp;java.util.</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000">&nbsp;java.math.BigDecimal;<br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img id=Codehighlighter1_86_488_Open_Image onclick="this.style.display='none'; Codehighlighter1_86_488_Open_Text.style.display='none'; Codehighlighter1_86_488_Closed_Image.style.display='inline'; Codehighlighter1_86_488_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_86_488_Closed_Image onclick="this.style.display='none'; Codehighlighter1_86_488_Closed_Text.style.display='none'; Codehighlighter1_86_488_Open_Image.style.display='inline'; Codehighlighter1_86_488_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Main&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_86_488_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_86_488_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"></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[])<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img id=Codehighlighter1_128_486_Open_Image onclick="this.style.display='none'; Codehighlighter1_128_486_Open_Text.style.display='none'; Codehighlighter1_128_486_Closed_Image.style.display='inline'; Codehighlighter1_128_486_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_128_486_Closed_Image onclick="this.style.display='none'; Codehighlighter1_128_486_Closed_Text.style.display='none'; Codehighlighter1_128_486_Open_Image.style.display='inline'; Codehighlighter1_128_486_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_128_486_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_128_486_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;Scanner&nbsp;cin&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;Scanner(System.in);<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;BigDecimal&nbsp;num;<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n;<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;String&nbsp;r;<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(cin.hasNextBigDecimal())<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img id=Codehighlighter1_257_484_Open_Image onclick="this.style.display='none'; Codehighlighter1_257_484_Open_Text.style.display='none'; Codehighlighter1_257_484_Closed_Image.style.display='inline'; Codehighlighter1_257_484_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_257_484_Closed_Image onclick="this.style.display='none'; Codehighlighter1_257_484_Closed_Text.style.display='none'; Codehighlighter1_257_484_Open_Image.style.display='inline'; Codehighlighter1_257_484_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_257_484_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_257_484_Open_Text><span style="COLOR: #000000">{&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;cin.nextBigDecimal();<br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;cin.nextInt();<br></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;num.pow(n);<br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;num.stripTrailingZeros().toPlainString();<br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(r.startsWith(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">0.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">))&nbsp;&nbsp;r&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;r.substring(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(r);<br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span></div>
<img src ="http://www.cppblog.com/vontroy/aggbug/116233.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-05-24 16:42 <a href="http://www.cppblog.com/vontroy/archive/2010/05/24/116233.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>