﻿<?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++博客-Next.-随笔分类-HDOJ 做题报告</title><link>http://www.cppblog.com/bersaty/category/18224.html</link><description>生来介为忙一场</description><language>zh-cn</language><lastBuildDate>Fri, 25 Nov 2011 03:15:21 GMT</lastBuildDate><pubDate>Fri, 25 Nov 2011 03:15:21 GMT</pubDate><ttl>60</ttl><item><title>hdoj 1878 欧拉回路</title><link>http://www.cppblog.com/bersaty/archive/2011/11/25/160956.html</link><dc:creator>bersaty</dc:creator><author>bersaty</author><pubDate>Fri, 25 Nov 2011 03:12:00 GMT</pubDate><guid>http://www.cppblog.com/bersaty/archive/2011/11/25/160956.html</guid><wfw:comment>http://www.cppblog.com/bersaty/comments/160956.html</wfw:comment><comments>http://www.cppblog.com/bersaty/archive/2011/11/25/160956.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bersaty/comments/commentRss/160956.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bersaty/services/trackbacks/160956.html</trackback:ping><description><![CDATA[<h1 style="color: #1a5cc8">欧拉回路</h1><font size="+0"><strong><span style="font-weight: bold; font-size: 12px; color: green; font-family: Arial">Time Limit: 2000/1000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 32768/32768 K (Java/Others)<br />Total Submission(s): 5820&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 1987<br /></span></strong></font><br /><br />
<div class="panel_title" align="left">Problem Description</div>
<div class="panel_content">欧拉回路是指不令笔离开纸面，可画过图中每条边仅一次，且可以回到起点的一条回路。现给定一个图，问是否存在欧拉回路？</div>
<div class="panel_bottom">&nbsp;</div><br />
<div class="panel_title" align="left">Input</div>
<div class="panel_content">测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数，分别是节点数N ( 1 &lt; N &lt; 1000 )和边数M；随后的M行对应M条边，每行给出一对正整数，分别是该条边直接连通的两个节点的编号（节点从1到N编号）。当N为0时输入结<br />束。</div>
<div class="panel_bottom">&nbsp;</div><br />
<div class="panel_title" align="left">Output</div>
<div class="panel_content">每个测试用例的输出占一行，若欧拉回路存在则输出1，否则输出0。<br /></div>
<div class="panel_bottom">&nbsp;</div><br />
<div class="panel_title" align="left">Sample Input</div>
<div class="panel_content"><pre><div style="font-family: Courier New,Courier,monospace">3 3
1 2
1 3
2 3
3 2
1 2
2 3
0</div></pre></div>
<div class="panel_bottom">&nbsp;</div><br />
<div class="panel_title" align="left">Sample Output</div>
<div class="panel_content"><pre><div style="font-family: Courier New,Courier,monospace">1
0</div></pre></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>网上说要用并查集,唉~~不懂啊,算法白痴,按自己的思路做,欧拉回路每个节点必有偶数个度(通路可以有0个或2个为基数),基本思路就这样</p>
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><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: #008080">&nbsp;2</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  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 /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;d[</span><span style="color: #000000">1001</span><span style="color: #000000">],</span><span style="color: #0000ff">set</span><span style="color: #000000">[</span><span style="color: #000000">1001</span><span style="color: #000000">],a,b;<br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img id="Codehighlighter1_78_587_Open_Image" onclick="this.style.display='none'; Codehighlighter1_78_587_Open_Text.style.display='none'; Codehighlighter1_78_587_Closed_Image.style.display='inline'; Codehighlighter1_78_587_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_78_587_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_78_587_Closed_Text.style.display='none'; Codehighlighter1_78_587_Open_Image.style.display='inline'; Codehighlighter1_78_587_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_78_587_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_78_587_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,m,flag;<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">n</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">n)<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img id="Codehighlighter1_114_574_Open_Image" onclick="this.style.display='none'; Codehighlighter1_114_574_Open_Text.style.display='none'; Codehighlighter1_114_574_Closed_Image.style.display='inline'; Codehighlighter1_114_574_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_114_574_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_114_574_Closed_Text.style.display='none'; Codehighlighter1_114_574_Open_Image.style.display='inline'; Codehighlighter1_114_574_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_114_574_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_114_574_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  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</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img id="Codehighlighter1_142_170_Open_Image" onclick="this.style.display='none'; Codehighlighter1_142_170_Open_Text.style.display='none'; Codehighlighter1_142_170_Closed_Image.style.display='inline'; Codehighlighter1_142_170_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_142_170_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_142_170_Closed_Text.style.display='none'; Codehighlighter1_142_170_Open_Image.style.display='inline'; Codehighlighter1_142_170_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_142_170_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_142_170_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[i]</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">set</span><span style="color: #000000">[i]</span><span style="color: #000000">=</span><span style="color: #000000">i;<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">14</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">m;<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flag</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(m</span><span style="color: #000000">--</span><span style="color: #000000">)<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img id="Codehighlighter1_209_329_Open_Image" onclick="this.style.display='none'; Codehighlighter1_209_329_Open_Text.style.display='none'; Codehighlighter1_209_329_Closed_Image.style.display='inline'; Codehighlighter1_209_329_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_209_329_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_209_329_Closed_Text.style.display='none'; Codehighlighter1_209_329_Open_Image.style.display='inline'; Codehighlighter1_209_329_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_209_329_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_209_329_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">a</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">b;<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&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: #0000ff">set</span><span style="color: #000000">[a]</span><span style="color: #000000">&gt;</span><span style="color: #0000ff">set</span><span style="color: #000000">[b])&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">判断是否连通用</span><span style="color: #008000"><br /></span><span style="color: #008080">20</span><span style="color: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">set</span><span style="color: #000000">[a]</span><span style="color: #000000">=</span><span style="color: #0000ff">set</span><span style="color: #000000">[b];<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  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 /></span><span style="color: #008080">22</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">set</span><span style="color: #000000">[b]</span><span style="color: #000000">=</span><span style="color: #0000ff">set</span><span style="color: #000000">[a];<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[a]</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[b]</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">26</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n;i</span><span style="color: #000000">++</span><span style="color: #000000">)&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">每个节点都必有偶数个度</span><span style="color: #008000"><br /></span><span style="color: #008080">27</span><span style="color: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></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">(d[i]</span><span style="color: #000000">&amp;</span><span style="color: #000000">1</span><span style="color: #000000">)<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img id="Codehighlighter1_385_413_Open_Image" onclick="this.style.display='none'; Codehighlighter1_385_413_Open_Text.style.display='none'; Codehighlighter1_385_413_Closed_Image.style.display='inline'; Codehighlighter1_385_413_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_385_413_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_385_413_Closed_Text.style.display='none'; Codehighlighter1_385_413_Open_Image.style.display='inline'; Codehighlighter1_385_413_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_385_413_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_385_413_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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 /></span><span style="color: #008080">30</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  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 /></span><span style="color: #008080">31</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">32</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  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">flag)<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  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">(</span><span style="color: #0000ff">set</span><span style="color: #000000">[i]</span><span style="color: #000000">!=</span><span style="color: #000000">1</span><span style="color: #000000">)<br /></span><span style="color: #008080">35</span><span style="color: #000000"><img id="Codehighlighter1_476_507_Open_Image" onclick="this.style.display='none'; Codehighlighter1_476_507_Open_Text.style.display='none'; Codehighlighter1_476_507_Closed_Image.style.display='inline'; Codehighlighter1_476_507_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_476_507_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_476_507_Closed_Text.style.display='none'; Codehighlighter1_476_507_Open_Image.style.display='inline'; Codehighlighter1_476_507_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_476_507_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_476_507_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">36</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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 /></span><span style="color: #008080">37</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  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">;<br /></span><span style="color: #008080">38</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">39</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(flag)<br /></span><span style="color: #008080">40</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">0</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">41</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">42</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">1</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">43</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">44</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  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 /></span><span style="color: #008080">45</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div>
<p><br />&nbsp;</p>
<p>&nbsp;</p><img src ="http://www.cppblog.com/bersaty/aggbug/160956.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bersaty/" target="_blank">bersaty</a> 2011-11-25 11:12 <a href="http://www.cppblog.com/bersaty/archive/2011/11/25/160956.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>F(N) HDOJ 2802</title><link>http://www.cppblog.com/bersaty/archive/2011/06/18/148921.html</link><dc:creator>bersaty</dc:creator><author>bersaty</author><pubDate>Sat, 18 Jun 2011 11:12:00 GMT</pubDate><guid>http://www.cppblog.com/bersaty/archive/2011/06/18/148921.html</guid><wfw:comment>http://www.cppblog.com/bersaty/comments/148921.html</wfw:comment><comments>http://www.cppblog.com/bersaty/archive/2011/06/18/148921.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bersaty/comments/commentRss/148921.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bersaty/services/trackbacks/148921.html</trackback:ping><description><![CDATA[<div>这题明显是有规律的，但那个坑爹啊~~2009啊，多大啊<br />就先看前2009个数，在4018，6027.。。。<br />就在4018发现规律，好咯，可以去吃饭了，感动ing。。
<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"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;f(</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;n)<br /><img id="Codehighlighter1_15_127_Open_Image" onclick="this.style.display='none'; Codehighlighter1_15_127_Open_Text.style.display='none'; Codehighlighter1_15_127_Closed_Image.style.display='inline'; Codehighlighter1_15_127_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_15_127_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_15_127_Closed_Text.style.display='none'; Codehighlighter1_15_127_Open_Image.style.display='inline'; Codehighlighter1_15_127_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_15_127_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_15_127_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;q;<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">(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"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q</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"  alt="" />&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">(n</span><span style="color: #000000">==</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;q</span><span style="color: #000000">=</span><span style="color: #000000">7</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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q</span><span style="color: #000000">=</span><span style="color: #000000">(f(n</span><span style="color: #000000">-</span><span style="color: #000000">2</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">1</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">1</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">1</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">n</span><span style="color: #000000">*</span><span style="color: #000000">n)</span><span style="color: #000000">%</span><span style="color: #000000">2009</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&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;q;<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><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_140_335_Open_Image" onclick="this.style.display='none'; Codehighlighter1_140_335_Open_Text.style.display='none'; Codehighlighter1_140_335_Closed_Image.style.display='inline'; Codehighlighter1_140_335_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_140_335_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_140_335_Closed_Text.style.display='none'; Codehighlighter1_140_335_Open_Image.style.display='inline'; Codehighlighter1_140_335_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_140_335_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_140_335_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;a[</span><span style="color: #000000">4030</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">long</span><span style="color: #000000">&nbsp;n</span><span style="color: #000000">=</span><span style="color: #000000">4020</span><span style="color: #000000">,m,i;<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">(i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">4020</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;a[i]</span><span style="color: #000000">=</span><span style="color: #000000">f(i);<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">(scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%ld</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">m)</span><span style="color: #000000">!=</span><span style="color: #000000">EOF</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">m)<br /><img id="Codehighlighter1_243_322_Open_Image" onclick="this.style.display='none'; Codehighlighter1_243_322_Open_Text.style.display='none'; Codehighlighter1_243_322_Closed_Image.style.display='inline'; Codehighlighter1_243_322_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_243_322_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_243_322_Closed_Text.style.display='none'; Codehighlighter1_243_322_Open_Image.style.display='inline'; Codehighlighter1_243_322_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_243_322_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_243_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;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(m</span><span style="color: #000000">%</span><span style="color: #000000">4018</span><span style="color: #000000">==</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;printf(</span><span style="color: #000000">"</span><span style="color: #000000">0\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;</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">%ld\n</span><span style="color: #000000">"</span><span style="color: #000000">,a[m</span><span style="color: #000000">%</span><span style="color: #000000">4018</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></div><br /></div> <img src ="http://www.cppblog.com/bersaty/aggbug/148921.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bersaty/" target="_blank">bersaty</a> 2011-06-18 19:12 <a href="http://www.cppblog.com/bersaty/archive/2011/06/18/148921.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>大菲波数 hdoj 1715</title><link>http://www.cppblog.com/bersaty/archive/2011/06/18/148916.html</link><dc:creator>bersaty</dc:creator><author>bersaty</author><pubDate>Sat, 18 Jun 2011 09:30:00 GMT</pubDate><guid>http://www.cppblog.com/bersaty/archive/2011/06/18/148916.html</guid><wfw:comment>http://www.cppblog.com/bersaty/comments/148916.html</wfw:comment><comments>http://www.cppblog.com/bersaty/archive/2011/06/18/148916.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bersaty/comments/commentRss/148916.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bersaty/services/trackbacks/148916.html</trackback:ping><description><![CDATA[<p>用了一个下午终于AC了，不过代码很笨拙，不过还是很有成就感~~~~~~~~<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"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include</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 /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">stdlib.h</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</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 /><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_67_1393_Open_Image" onclick="this.style.display='none'; Codehighlighter1_67_1393_Open_Text.style.display='none'; Codehighlighter1_67_1393_Closed_Image.style.display='inline'; Codehighlighter1_67_1393_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_67_1393_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_67_1393_Closed_Text.style.display='none'; Codehighlighter1_67_1393_Open_Image.style.display='inline'; Codehighlighter1_67_1393_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_67_1393_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_67_1393_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;s1[</span><span style="color: #000000">1000</span><span style="color: #000000">],s2[</span><span style="color: #000000">1000</span><span style="color: #000000">],sum[</span><span style="color: #000000">1000</span><span style="color: #000000">][</span><span style="color: #000000">1000</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;n,m,len,len1,len2,i,</span><span style="color: #000000">*</span><span style="color: #000000">p,k</span><span style="color: #000000">=</span><span style="color: #000000">1000</span><span style="color: #000000">,w;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;n</span><span style="color: #000000">=</span><span style="color: #000000">3</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;strcpy(sum[</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">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;strcpy(sum[</span><span style="color: #000000">2</span><span style="color: #000000">],</span><span style="color: #000000">"</span><span style="color: #000000">1</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcpy(s1,</span><span style="color: #000000">"</span><span style="color: #000000">1</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;strcpy(s2,</span><span style="color: #000000">"</span><span style="color: #000000">1</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">while</span><span style="color: #000000">(k</span><span style="color: #000000">--</span><span style="color: #000000">)<br /><img id="Codehighlighter1_249_1223_Open_Image" onclick="this.style.display='none'; Codehighlighter1_249_1223_Open_Text.style.display='none'; Codehighlighter1_249_1223_Closed_Image.style.display='inline'; Codehighlighter1_249_1223_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_249_1223_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_249_1223_Closed_Text.style.display='none'; Codehighlighter1_249_1223_Open_Image.style.display='inline'; Codehighlighter1_249_1223_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_249_1223_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_249_1223_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">while</span><span style="color: #000000">(n</span><span style="color: #000000">&lt;=</span><span style="color: #000000">k)<br /><img id="Codehighlighter1_275_1220_Open_Image" onclick="this.style.display='none'; Codehighlighter1_275_1220_Open_Text.style.display='none'; Codehighlighter1_275_1220_Closed_Image.style.display='inline'; Codehighlighter1_275_1220_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_275_1220_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_275_1220_Closed_Text.style.display='none'; Codehighlighter1_275_1220_Open_Image.style.display='inline'; Codehighlighter1_275_1220_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_275_1220_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_275_1220_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;len1</span><span style="color: #000000">=</span><span style="color: #000000">strlen(s1),len2</span><span style="color: #000000">=</span><span style="color: #000000">strlen(s2);<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;len</span><span style="color: #000000">=</span><span style="color: #000000">len2</span><span style="color: #000000">+</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;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">=</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">)malloc(len</span><span style="color: #000000">*</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(</span><span style="color: #0000ff">int</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">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">len;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;p[i]</span><span style="color: #000000">=</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;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(len1</span><span style="color: #000000">==</span><span style="color: #000000">len2)<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;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">len2;i</span><span style="color: #000000">&gt;</span><span style="color: #000000">0</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;</span><span style="color: #000000">*</span><span style="color: #000000">(p</span><span style="color: #000000">+</span><span style="color: #000000">i)</span><span style="color: #000000">=</span><span style="color: #000000">(</span><span style="color: #000000">*</span><span style="color: #000000">(s1</span><span style="color: #000000">+</span><span style="color: #000000">i</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">)</span><span style="color: #000000">-</span><span style="color: #000000">48</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">(s2</span><span style="color: #000000">+</span><span style="color: #000000">i</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">)</span><span style="color: #000000">-</span><span style="color: #000000">48</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 id="Codehighlighter1_597_734_Open_Image" onclick="this.style.display='none'; Codehighlighter1_597_734_Open_Text.style.display='none'; Codehighlighter1_597_734_Closed_Image.style.display='inline'; Codehighlighter1_597_734_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_597_734_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_597_734_Closed_Text.style.display='none'; Codehighlighter1_597_734_Open_Image.style.display='inline'; Codehighlighter1_597_734_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_597_734_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_597_734_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;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">len2;i</span><span style="color: #000000">&gt;</span><span style="color: #000000">1</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;</span><span style="color: #000000">*</span><span style="color: #000000">(p</span><span style="color: #000000">+</span><span style="color: #000000">i)</span><span style="color: #000000">=</span><span style="color: #000000">(</span><span style="color: #000000">*</span><span style="color: #000000">(s1</span><span style="color: #000000">+</span><span style="color: #000000">i</span><span style="color: #000000">-</span><span style="color: #000000">2</span><span style="color: #000000">)</span><span style="color: #000000">-</span><span style="color: #000000">48</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">(s2</span><span style="color: #000000">+</span><span style="color: #000000">i</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">)</span><span style="color: #000000">-</span><span style="color: #000000">48</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: #000000">*</span><span style="color: #000000">(p</span><span style="color: #000000">+</span><span style="color: #000000">i)</span><span style="color: #000000">=</span><span style="color: #000000">(</span><span style="color: #000000">*</span><span style="color: #000000">(s2</span><span style="color: #000000">+</span><span style="color: #000000">i</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">))</span><span style="color: #000000">-</span><span style="color: #000000">48</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">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">len2;i</span><span style="color: #000000">&gt;</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">--</span><span style="color: #000000">)<br /><img id="Codehighlighter1_773_890_Open_Image" onclick="this.style.display='none'; Codehighlighter1_773_890_Open_Text.style.display='none'; Codehighlighter1_773_890_Closed_Image.style.display='inline'; Codehighlighter1_773_890_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_773_890_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_773_890_Closed_Text.style.display='none'; Codehighlighter1_773_890_Open_Image.style.display='inline'; Codehighlighter1_773_890_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_773_890_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_773_890_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: #000000">*</span><span style="color: #000000">(p</span><span style="color: #000000">+</span><span style="color: #000000">i)</span><span style="color: #000000">+=*</span><span style="color: #000000">(p</span><span style="color: #000000">+</span><span style="color: #000000">i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">)</span><span style="color: #000000">/</span><span style="color: #000000">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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">(p</span><span style="color: #000000">+</span><span style="color: #000000">i</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">)</span><span style="color: #000000">+=*</span><span style="color: #000000">(p</span><span style="color: #000000">+</span><span style="color: #000000">i)</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/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: #000000">*</span><span style="color: #000000">(p</span><span style="color: #000000">+</span><span style="color: #000000">i)</span><span style="color: #000000">=*</span><span style="color: #000000">(p</span><span style="color: #000000">+</span><span style="color: #000000">i)</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/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;strcpy(s1,s2);<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">(p[</span><span style="color: #000000">0</span><span style="color: #000000">]</span><span style="color: #000000">==</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">len2;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_982_1031_Open_Image" onclick="this.style.display='none'; Codehighlighter1_982_1031_Open_Text.style.display='none'; Codehighlighter1_982_1031_Closed_Image.style.display='inline'; Codehighlighter1_982_1031_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_982_1031_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_982_1031_Closed_Text.style.display='none'; Codehighlighter1_982_1031_Open_Image.style.display='inline'; Codehighlighter1_982_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;&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_982_1031_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_982_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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s2[i]</span><span style="color: #000000">=*</span><span style="color: #000000">(p</span><span style="color: #000000">+</span><span style="color: #000000">i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">)</span><span style="color: #000000">+</span><span style="color: #000000">'</span><span style="color: #000000">0</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;&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">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;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">len2;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_1101_1148_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1101_1148_Open_Text.style.display='none'; Codehighlighter1_1101_1148_Closed_Image.style.display='inline'; Codehighlighter1_1101_1148_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1101_1148_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1101_1148_Closed_Text.style.display='none'; Codehighlighter1_1101_1148_Open_Image.style.display='inline'; Codehighlighter1_1101_1148_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;&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_1101_1148_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1101_1148_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;&nbsp;&nbsp;&nbsp;s2[i]</span><span style="color: #000000">=*</span><span style="color: #000000">(p</span><span style="color: #000000">+</span><span style="color: #000000">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">;<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;&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;s2[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">;<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;strcpy(sum[n],s2);<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;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/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">while</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">w)</span><span style="color: #000000">!=</span><span style="color: #000000">EOF)<br /><img id="Codehighlighter1_1254_1380_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1254_1380_Open_Text.style.display='none'; Codehighlighter1_1254_1380_Closed_Image.style.display='inline'; Codehighlighter1_1254_1380_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1254_1380_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1254_1380_Closed_Text.style.display='none'; Codehighlighter1_1254_1380_Open_Image.style.display='inline'; Codehighlighter1_1254_1380_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_1254_1380_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1254_1380_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">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">w;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_1277_1377_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1277_1377_Open_Text.style.display='none'; Codehighlighter1_1277_1377_Closed_Image.style.display='inline'; Codehighlighter1_1277_1377_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1277_1377_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1277_1377_Closed_Text.style.display='none'; Codehighlighter1_1277_1377_Open_Image.style.display='inline'; Codehighlighter1_1277_1377_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_1277_1377_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1277_1377_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">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">m);<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">(m</span><span style="color: #000000">==</span><span style="color: #000000">1</span><span style="color: #000000">||</span><span style="color: #000000">m</span><span style="color: #000000">==</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">1\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;&nbsp;&nbsp;&nbsp;&nbsp;puts(sum[m]);<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>
<p><br />&nbsp;</p> <img src ="http://www.cppblog.com/bersaty/aggbug/148916.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bersaty/" target="_blank">bersaty</a> 2011-06-18 17:30 <a href="http://www.cppblog.com/bersaty/archive/2011/06/18/148916.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDOJ 1003 Max Sum 非递归算法（很巧妙~~~）【转】</title><link>http://www.cppblog.com/bersaty/archive/2011/06/11/148514.html</link><dc:creator>bersaty</dc:creator><author>bersaty</author><pubDate>Sat, 11 Jun 2011 15:21:00 GMT</pubDate><guid>http://www.cppblog.com/bersaty/archive/2011/06/11/148514.html</guid><wfw:comment>http://www.cppblog.com/bersaty/comments/148514.html</wfw:comment><comments>http://www.cppblog.com/bersaty/archive/2011/06/11/148514.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bersaty/comments/commentRss/148514.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bersaty/services/trackbacks/148514.html</trackback:ping><description><![CDATA[<pre><span style="font-family: Lucida Console"><span style="color: #008000">/*Max Sum
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 37083    Accepted Submission(s): 7979

Problem Description
Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate 
the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the 
max sum in this sequence is 6 + (-1) + 5 + 4 = 14.

 

Input
The first line of the input contains an integer T(1&lt;=T&lt;=20) 
which means the number of test cases. Then T lines follow, each line 
starts with a number N(1&lt;=N&lt;=100000),
 then N integers followed(all the integers are between -1000 and 1000).

 

Output
For each test case, you should output two lines. The first line is 
"Case #:", # means the number of the test case. The second line
 contains three integers, the Max Sum in the sequence, the start
 position of the sub-sequence, the end position of the sub-sequence. 
 If there are more than one result, output the first one. Output a blank
 line between two cases.

 

Sample Input
2
5 6 -1 5 4 -7
7 0 6 -1 1 -6 7 -5
 

Sample Output
Case 1:
14 1 4

Case 2:
7 1 6
*/</span>

<span style="color: #ff8000">#include&lt;iostream&gt;
</span><span style="color: #0000ff">using</span> <span style="color: #0000ff">namespace</span> std;
<span style="color: #0000ff">int</span> main(){
    <span style="color: #0000ff">int</span> N;cin&gt;&gt;N;
    <span style="color: #0000ff">for</span>(<span style="color: #0000ff">int</span> k=<span style="color: #ff0000">1</span>;k&lt;=N;k++){
        <span style="color: #0000ff">if</span>(k-<span style="color: #ff0000">1</span>)cout&lt;&lt;endl;
        <span style="color: #0000ff">int</span> n;cin&gt;&gt;n;
        <span style="color: #0000ff">int</span> i,j,beg,end,max=-<span style="color: #ff0000">11111111</span>,sum,fig;
        <span style="color: #0000ff">for</span>(i=j=<span style="color: #ff0000">1</span>,sum=<span style="color: #ff0000">0</span>;j&lt;=n;j++){
            cin&gt;&gt;fig;
            sum+=fig;
            <span style="color: #0000ff">if</span>(sum&gt;max){max=sum;beg=i;end=j;}<span style="color: #008000">//a只在此处改变beg,和end 的大小
</span>            <span style="color: #0000ff">if</span>(sum&lt;<span style="color: #ff0000">0</span>){i=j+<span style="color: #ff0000">1</span>;sum=<span style="color: #ff0000">0</span>;}<span style="color: #008000">//如果sum小于零了，那么说明刚加进来的fig特别的小（小到这种&#8220;特殊&#8221;的程度）
</span>            <span style="color: #008000">//试探性的以次为起点，如果后来的sum 比max 大，则前面的一连串就毫无意义（因为加上一个负值肯定会变小的）
</span>        }
        cout&lt;&lt;<span style="color: #008000">"Case "</span>&lt;&lt;k&lt;&lt;<span style="color: #008000">":\n"</span>;
        cout&lt;&lt;max&lt;&lt;<span style="color: #008000">" "</span>&lt;&lt;beg&lt;&lt;<span style="color: #008000">" "</span>&lt;&lt;end&lt;&lt;endl;
    }
    <span style="color: #0000ff">return</span> <span style="color: #ff0000">0</span>;
}</span></pre><pre><span style="font-family: Lucida Console"></span>&nbsp;</pre><pre><span style="font-family: Lucida Console">说白了是一种贪心算法：</span></pre><pre><span style="font-family: Lucida Console"><p>Int MaxSubsequenceSum(const int A[], int N)</p><p>{</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int ThisSum, MaxSum, j;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisSum = MaxSum = 0;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For(j=0; j &lt; N; j++)</p><p>{</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisSum += A[j];</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If (ThisSum &gt; MaxSum)</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MaxSum = ThisSum;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else if(ThisSum &lt; 0)</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisSum = 0;</p><p>}</p><p>return MaxSum;</p><p>}</span></p></pre>   <img src ="http://www.cppblog.com/bersaty/aggbug/148514.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bersaty/" target="_blank">bersaty</a> 2011-06-11 23:21 <a href="http://www.cppblog.com/bersaty/archive/2011/06/11/148514.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>