﻿<?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++博客-Loading......Next.</title><link>http://www.cppblog.com/bersaty/</link><description>生来介为忙一场</description><language>zh-cn</language><lastBuildDate>Mon, 06 Apr 2026 22:49:58 GMT</lastBuildDate><pubDate>Mon, 06 Apr 2026 22:49:58 GMT</pubDate><ttl>60</ttl><item><title>简单的贪心（最优）</title><link>http://www.cppblog.com/bersaty/archive/2011/12/11/161924.html</link><dc:creator>bersaty</dc:creator><author>bersaty</author><pubDate>Sun, 11 Dec 2011 08:37:00 GMT</pubDate><guid>http://www.cppblog.com/bersaty/archive/2011/12/11/161924.html</guid><wfw:comment>http://www.cppblog.com/bersaty/comments/161924.html</wfw:comment><comments>http://www.cppblog.com/bersaty/archive/2011/12/11/161924.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bersaty/comments/commentRss/161924.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bersaty/services/trackbacks/161924.html</trackback:ping><description><![CDATA[<p><font color="#000000" face="Verdana">http://acm.nyist.net/JudgeOnline/problem.php?pid=6</font><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"><!--<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">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</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</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="" /></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="" /></span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;ri[</span><span style="color: #000000">600</span><span style="color: #000000">],sum;<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_351_Open_Image" onclick="this.style.display='none'; Codehighlighter1_107_351_Open_Text.style.display='none'; Codehighlighter1_107_351_Closed_Image.style.display='inline'; Codehighlighter1_107_351_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_107_351_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_107_351_Closed_Text.style.display='none'; Codehighlighter1_107_351_Open_Image.style.display='inline'; Codehighlighter1_107_351_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_351_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_107_351_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i,n,m;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">m;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(m</span><span style="color: #000000">--</span><span style="color: #000000">)<br /><img id="Codehighlighter1_143_338_Open_Image" onclick="this.style.display='none'; Codehighlighter1_143_338_Open_Text.style.display='none'; Codehighlighter1_143_338_Closed_Image.style.display='inline'; Codehighlighter1_143_338_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_143_338_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_143_338_Closed_Text.style.display='none'; Codehighlighter1_143_338_Open_Image.style.display='inline'; Codehighlighter1_143_338_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&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_143_338_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_143_338_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;sum</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;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">n;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&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">n;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_185_204_Open_Image" onclick="this.style.display='none'; Codehighlighter1_185_204_Open_Text.style.display='none'; Codehighlighter1_185_204_Closed_Image.style.display='inline'; Codehighlighter1_185_204_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_185_204_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_185_204_Closed_Text.style.display='none'; Codehighlighter1_185_204_Open_Image.style.display='inline'; Codehighlighter1_185_204_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_185_204_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_185_204_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">ri[i];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;sort(ri,ri</span><span style="color: #000000">+</span><span style="color: #000000">n);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</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">;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_247_316_Open_Image" onclick="this.style.display='none'; Codehighlighter1_247_316_Open_Text.style.display='none'; Codehighlighter1_247_316_Closed_Image.style.display='inline'; Codehighlighter1_247_316_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_247_316_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_247_316_Closed_Text.style.display='none'; Codehighlighter1_247_316_Open_Image.style.display='inline'; Codehighlighter1_247_316_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_247_316_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_247_316_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;sum</span><span style="color: #000000">+=</span><span style="color: #000000">sqrt(ri[i]</span><span style="color: #000000">*</span><span style="color: #000000">ri[i]</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;</span><span style="color: #0000ff">if</span><span style="color: #000000">(sum</span><span style="color: #000000">&gt;=</span><span style="color: #000000">10</span><span style="color: #000000">)<br /><img id="Codehighlighter1_296_312_Open_Image" onclick="this.style.display='none'; Codehighlighter1_296_312_Open_Text.style.display='none'; Codehighlighter1_296_312_Closed_Image.style.display='inline'; Codehighlighter1_296_312_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_296_312_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_296_312_Closed_Text.style.display='none'; Codehighlighter1_296_312_Open_Image.style.display='inline'; Codehighlighter1_296_312_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&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_296_312_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_296_312_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">break</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&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;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">n</span><span style="color: #000000">-</span><span style="color: #000000">i</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&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>
<p>&nbsp;</p><img src ="http://www.cppblog.com/bersaty/aggbug/161924.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-12-11 16:37 <a href="http://www.cppblog.com/bersaty/archive/2011/12/11/161924.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>欧拉回路问题~</title><link>http://www.cppblog.com/bersaty/archive/2011/12/11/161923.html</link><dc:creator>bersaty</dc:creator><author>bersaty</author><pubDate>Sun, 11 Dec 2011 08:33:00 GMT</pubDate><guid>http://www.cppblog.com/bersaty/archive/2011/12/11/161923.html</guid><wfw:comment>http://www.cppblog.com/bersaty/comments/161923.html</wfw:comment><comments>http://www.cppblog.com/bersaty/archive/2011/12/11/161923.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bersaty/comments/commentRss/161923.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bersaty/services/trackbacks/161923.html</trackback:ping><description><![CDATA[hdoj 1878 和 <a href="http://acm.nyist.net/JudgeOnline/problem.php?pid=42">http://acm.nyist.net/JudgeOnline/problem.php?pid=42</a><br />主要是将一小块一小块的东西合起来<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"><!--<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: #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;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">];<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;w;<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;find(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x)<br /><img id="Codehighlighter1_83_204_Open_Image" onclick="this.style.display='none'; Codehighlighter1_83_204_Open_Text.style.display='none'; Codehighlighter1_83_204_Closed_Image.style.display='inline'; Codehighlighter1_83_204_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_83_204_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_83_204_Closed_Text.style.display='none'; Codehighlighter1_83_204_Open_Image.style.display='inline'; Codehighlighter1_83_204_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_83_204_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_83_204_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;i,j,r</span><span style="color: #000000">=</span><span style="color: #000000">x;<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">(r</span><span style="color: #000000">!=</span><span style="color: #0000ff">set</span><span style="color: #000000">[r])&nbsp;r</span><span style="color: #000000">=</span><span style="color: #0000ff">set</span><span style="color: #000000">[r];</span><span style="color: #008000">//</span><span style="color: #008000">根节点&nbsp;</span><span style="color: #008000"><br /><img id="Codehighlighter1_133_191_Open_Image" onclick="this.style.display='none'; Codehighlighter1_133_191_Open_Text.style.display='none'; Codehighlighter1_133_191_Closed_Image.style.display='inline'; Codehighlighter1_133_191_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_133_191_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_133_191_Closed_Text.style.display='none'; Codehighlighter1_133_191_Open_Image.style.display='inline'; Codehighlighter1_133_191_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_133_191_Closed_Text">/**/</span><span id="Codehighlighter1_133_191_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;i=x;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;while(i!=r)<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;&nbsp;&nbsp;&nbsp;&nbsp;j=set[i];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set[i]=r;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i=j;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="color: #008000">*/</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;r;<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">void</span><span style="color: #000000">&nbsp;unio(</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 /><img id="Codehighlighter1_229_305_Open_Image" onclick="this.style.display='none'; Codehighlighter1_229_305_Open_Text.style.display='none'; Codehighlighter1_229_305_Closed_Image.style.display='inline'; Codehighlighter1_229_305_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_229_305_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_229_305_Closed_Text.style.display='none'; Codehighlighter1_229_305_Open_Image.style.display='inline'; Codehighlighter1_229_305_Open_Text.style.display='inline';" 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_305_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_229_305_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;x</span><span style="color: #000000">=</span><span style="color: #000000">find(x);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;y</span><span style="color: #000000">=</span><span style="color: #000000">find(y);<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">(x</span><span style="color: #000000">&gt;</span><span style="color: #000000">y)&nbsp;</span><span style="color: #0000ff">set</span><span style="color: #000000">[x]</span><span style="color: #000000">=</span><span style="color: #000000">y;<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">set</span><span style="color: #000000">[y]</span><span style="color: #000000">=</span><span style="color: #000000">x;<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">(x</span><span style="color: #000000">!=</span><span style="color: #000000">y)&nbsp;w</span><span style="color: #000000">--</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><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_318_785_Open_Image" onclick="this.style.display='none'; Codehighlighter1_318_785_Open_Text.style.display='none'; Codehighlighter1_318_785_Closed_Image.style.display='inline'; Codehighlighter1_318_785_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_318_785_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_318_785_Closed_Text.style.display='none'; Codehighlighter1_318_785_Open_Image.style.display='inline'; Codehighlighter1_318_785_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_318_785_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_318_785_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,p,q,i;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a,b,flag,k,j;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&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 /><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">(n</span><span style="color: #000000">--</span><span style="color: #000000">)<br /><img id="Codehighlighter1_393_773_Open_Image" onclick="this.style.display='none'; Codehighlighter1_393_773_Open_Text.style.display='none'; Codehighlighter1_393_773_Closed_Image.style.display='inline'; Codehighlighter1_393_773_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_393_773_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_393_773_Closed_Text.style.display='none'; Codehighlighter1_393_773_Open_Image.style.display='inline'; Codehighlighter1_393_773_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&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_393_773_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_393_773_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d&nbsp;%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">p,</span><span style="color: #000000">&amp;</span><span style="color: #000000">q);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;w</span><span style="color: #000000">=</span><span style="color: #000000">p;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;memset(d,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(d));<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;flag</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;</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">p;i</span><span style="color: #000000">++</span><span style="color: #000000">)&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 /><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">(q</span><span style="color: #000000">--</span><span style="color: #000000">)<br /><img id="Codehighlighter1_513_602_Open_Image" onclick="this.style.display='none'; Codehighlighter1_513_602_Open_Text.style.display='none'; Codehighlighter1_513_602_Closed_Image.style.display='inline'; Codehighlighter1_513_602_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_513_602_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_513_602_Closed_Text.style.display='none'; Codehighlighter1_513_602_Open_Image.style.display='inline'; Codehighlighter1_513_602_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_513_602_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_513_602_Open_Text"><span style="color: #000000">{<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&nbsp;%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">a,</span><span style="color: #000000">&amp;</span><span style="color: #000000">b);<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">(a</span><span style="color: #000000">!=</span><span style="color: #000000">b)<br /><img id="Codehighlighter1_558_598_Open_Image" onclick="this.style.display='none'; Codehighlighter1_558_598_Open_Text.style.display='none'; Codehighlighter1_558_598_Closed_Image.style.display='inline'; Codehighlighter1_558_598_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_558_598_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_558_598_Closed_Text.style.display='none'; Codehighlighter1_558_598_Open_Image.style.display='inline'; Codehighlighter1_558_598_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_558_598_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_558_598_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;d[a]</span><span style="color: #000000">++</span><span style="color: #000000">;d[b]</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;unio(a,b);<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/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;k</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;</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">p;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_633_702_Open_Image" onclick="this.style.display='none'; Codehighlighter1_633_702_Open_Text.style.display='none'; Codehighlighter1_633_702_Closed_Image.style.display='inline'; Codehighlighter1_633_702_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_633_702_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_633_702_Closed_Text.style.display='none'; Codehighlighter1_633_702_Open_Image.style.display='inline'; Codehighlighter1_633_702_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_633_702_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_633_702_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&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">)&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;</span><span style="color: #0000ff">if</span><span style="color: #000000">(d[i]</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)&nbsp;<br /><img id="Codehighlighter1_673_698_Open_Image" onclick="this.style.display='none'; Codehighlighter1_673_698_Open_Text.style.display='none'; Codehighlighter1_673_698_Closed_Image.style.display='inline'; Codehighlighter1_673_698_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_673_698_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_673_698_Closed_Text.style.display='none'; Codehighlighter1_673_698_Open_Image.style.display='inline'; Codehighlighter1_673_698_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&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_673_698_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_673_698_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;k</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">break</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&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;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #0000ff">if</span><span style="color: #000000">(flag</span><span style="color: #000000">||</span><span style="color: #000000">(k</span><span style="color: #000000">!=</span><span style="color: #000000">0</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">k</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">w</span><span style="color: #000000">!=</span><span style="color: #000000">1</span><span style="color: #000000">)&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 /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">Yes\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="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></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 /><br /><img src ="http://www.cppblog.com/bersaty/aggbug/161923.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-12-11 16:33 <a href="http://www.cppblog.com/bersaty/archive/2011/12/11/161923.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>STL（map）</title><link>http://www.cppblog.com/bersaty/archive/2011/12/03/161349.html</link><dc:creator>bersaty</dc:creator><author>bersaty</author><pubDate>Sat, 03 Dec 2011 04:07:00 GMT</pubDate><guid>http://www.cppblog.com/bersaty/archive/2011/12/03/161349.html</guid><wfw:comment>http://www.cppblog.com/bersaty/comments/161349.html</wfw:comment><comments>http://www.cppblog.com/bersaty/archive/2011/12/03/161349.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bersaty/comments/commentRss/161349.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bersaty/services/trackbacks/161349.html</trackback:ping><description><![CDATA[发现做ACM题用STL 就像开挂，很多写了一堆代码的东西一下就KO了，不过还是要学习本质的东西~<br />PS：C++手册真好用~<br />
<p><strong>Map</strong></p>
<p>Maps are a kind of associative containers that stores elements formed by the combination of a <em>key value</em> and a <em>mapped value</em>. 
<p>In a <tt>map</tt>, the <em>key value</em> is generally used to uniquely identify the element, while the <em>mapped value</em> is some sort of value associated to this <em>key</em>. Types of <em>key</em> and <em>mapped</em> value may differ. For example, a typical example of a map is a telephone guide where the name is the <em>key</em> and the telephone number is the <em>mapped value</em>. 
<p>Internally, the elements in the map are sorted from lower to higher <em>key value</em> following a specific strict weak ordering criterion set on construction. 
<p>As associative containers, they are especially designed to be efficient accessing its elements by their <em>key</em> (unlike sequence containers, which are more efficient accessing elements by their relative or absolute position). 
<p>Therefore, the main characteristics of a <tt>map</tt> as an associative container are:<br />
<ul><li>Unique key values: no two elements in the <tt>map</tt> have keys that compare equal to each other. For a similar associative container allowing for multiple elements with equivalent keys, see <a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/multimap">multimap</a>.</li><li>Each element is composed of a <em>key</em> and a <em>mapped</em> value. For a simpler associative container where the element value itself is its key, see <a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/set">set</a>.</li><li>Elements follow a strict weak ordering at all times. Unordered associative arrays, like <tt>unordered_map</tt>, are available in implementations following TR1. </li></ul>
<p>Maps are also unique among associative containers in that the implement the direct access operator (<tt>operator[]</tt>) which allows for direct access of the mapped value. 
<p>In their implementation in the C++ Standard Template Library, <tt>map</tt> containers take four template parameters:<br />
<table class="snippet">
<tbody>
<tr>
<td class="code"><pre><span class="kw">template</span> &lt; <span class="kw">class</span> Key, <span class="kw">class</span> T, <span class="kw">class</span> Compare = less&lt;Key&gt;,
           <span class="kw">class</span> Allocator = allocator&lt;pair&lt;<span class="kw">const</span> Key,T&gt; &gt; &gt; <span class="kw">class</span> map;
</pre></td></tr></tbody></table>Where the template parameters have the following meanings:<br />
<ul><li><strong><tt>Key</tt>:</strong> Type of the key values. Each element in a <tt>map</tt> is uniquely identified by its key value.</li><li><strong><tt>T</tt>:</strong> Type of the mapped value. Each element in a <tt>map</tt> is used to store some data as its mapped value.</li><li><strong><tt>Compare</tt>:</strong> Comparison class: A class that takes two arguments of the <em>key type</em> and returns a <tt>bool</tt>. The expression <tt>comp(a,b)</tt>, where <em>comp</em> is an object of this comparison class and <em>a</em> and <em>b</em> are key values, shall return <tt>true</tt> if <em>a</em> is to be placed at an earlier position than <em>b</em> in a strict weak ordering operation. This can either be a class implementing a <em>function call operator</em> or a pointer to a function (see <a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/map_3A_3Amap">constructor</a> for an example). This defaults to <tt>less&lt;Key&gt;</tt>, which returns the same as applying the <em>less-than operator</em> (<tt>a&lt;b</tt>).<br />The <tt>map</tt> object uses this expression to determine the position of the elements in the container. All elements in a <tt>map</tt> container are ordered following this rule at all times.</li><li><strong><tt>Allocator</tt>:</strong> Type of the allocator object used to define the storage allocation model. By default, the <tt>allocator</tt> class template is used, which defines the simplest memory allocation model and is value-independent. </li></ul>In the reference for the <tt>map</tt> member functions, these same names (<em>Key</em>, <em>T</em>, <em>Compare</em> and <em>Allocator</em>) are assumed for the template parameters. 
<p>This container class supports <em>bidirectional iterators</em>.<br />Iterators to elements of <tt>map</tt> containers access to both the <em>key</em> and the <em>mapped value</em>. For this, the class defines what is called its <tt>value_type</tt>, which is a <a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/pair">pair</a> class with its <tt>first</tt> value corresponding to the <tt>const</tt> version of the <em>key</em> type (template parameter <em>Key</em>) and its <tt>second</tt> value corresponding to the <em>mapped value</em> (template parameter <em>T</em>):<br />
<table class="snippet">
<tbody>
<tr>
<td class="code"><pre><span class="kw">typedef</span> pair&lt;<span class="kw">const</span> Key, T&gt; value_type;
</pre></td></tr></tbody></table>
<p>Iterators of a <tt>map</tt> container point to elements of this <tt>value_type</tt>. Thus, for an iterator called <tt>it</tt> that points to an element of a <tt>map</tt>, its key and mapped value can be accessed respectivelly with:<br />
<table class="snippet">
<tbody>
<tr>
<td class="code"><pre>map&lt;Key,T&gt;::iterator it;
(*it).first;             <span class="comm">// the key value (of type Key)</span>
(*it).second;            <span class="comm">// the mapped value (of type T)</span>
(*it);                   <span class="comm">// the "element value" (of type pair&lt;const Key,T&gt;)</span>
</pre></td></tr></tbody></table>Naturally, any other direct access operator, such as <tt>-&gt;</tt> or <tt>[]</tt> can be used, for example:<br />
<table class="snippet">
<tbody>
<tr>
<td class="code"><pre>it-&gt;first;               <span class="comm">// same as (*it).first   (the key value)</span>
it-&gt;second;              <span class="comm">// same as (*it).second  (the mapped value)</span>
</pre></td></tr></tbody></table>
<p>
<h3>Member functions</h3>
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/map.html"><strong>(constructor)</strong></a></td>
<td class="des">Construct map <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/~map.html"><strong>(destructor)</strong></a></td>
<td class="des">Map destructor <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/operator=.html"><strong>operator=</strong></a></td>
<td class="des">Copy container content <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<p><strong>Iterators</strong>:<br />
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/begin.html"><strong>begin</strong></a></td>
<td class="des">Return iterator to beginning <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/end.html"><strong>end</strong></a></td>
<td class="des">Return iterator to end <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/rbegin.html"><strong>rbegin</strong></a></td>
<td class="des">Return reverse iterator to reverse beginning <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/rend.html"><strong>rend</strong></a></td>
<td class="des">Return reverse iterator to reverse end <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<p><strong>Capacity</strong>:<br />
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/empty.html"><strong>empty</strong></a></td>
<td class="des">Test whether container is empty <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/size.html"><strong>size</strong></a></td>
<td class="des">Return container size <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/max_size.html"><strong>max_size</strong></a></td>
<td class="des">Return maximum size <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<p><strong>Element access</strong>:<br />
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/operator[].html"><strong>operator[]</strong></a></td>
<td class="des">Access element <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<p><strong>Modifiers</strong>:<br />
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/insert.html"><strong>insert</strong></a></td>
<td class="des">Insert element <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/erase.html"><strong>erase</strong></a></td>
<td class="des">Erase elements <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/swap.html"><strong>swap</strong></a></td>
<td class="des">Swap content <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/clear.html"><strong>clear</strong></a></td>
<td class="des">Clear content <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<p><strong>Observers</strong>:<br />
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/key_comp.html"><strong>key_comp</strong></a></td>
<td class="des">Return key comparison object <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/value_comp.html"><strong>value_comp</strong></a></td>
<td class="des">Return value comparison object <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<p><strong>Operations</strong>:<br />
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/find.html"><strong>find</strong></a></td>
<td class="des">Get iterator to element <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/count.html"><strong>count</strong></a></td>
<td class="des">Count elements with a specific key <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/lower_bound.html"><strong>lower_bound</strong></a></td>
<td class="des">Return iterator to lower bound <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/upper_bound.html"><strong>upper_bound</strong></a></td>
<td class="des">Return iterator to upper bound <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/equal_range.html"><strong>equal_range</strong></a></td>
<td class="des">Get range of equal elements <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<p><strong>Allocator</strong>:<br />
<table class="list">
<tbody>
<tr>
<td class="tit"><a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/reference/stl/map/get_allocator.html"><strong>get_allocator</strong></a></td>
<td class="des">Get allocator <small><font color="green">(public member function)</font></small></td></tr></tbody></table>
<p>
<h3>Member types</h3>of <tt>template &lt;class Key, class T, class Compare=less&lt;Key&gt;, class Allocator=allocator&lt;pair &lt;const Key, T&gt; &gt; &gt; class map;</tt> 
<p>
<table class="boxed">
<tbody>
<tr>
<th>member type</th>
<th>definition</th></tr>
<tr>
<td><tt>key_type</tt></td>
<td><tt>Key</tt></td></tr>
<tr>
<td><tt>mapped_type</tt></td>
<td><tt>T</tt></td></tr>
<tr>
<td><tt>value_type</tt></td>
<td><tt>pair&lt;const Key,T&gt;</tt></td></tr>
<tr>
<td><tt>key_compare</tt></td>
<td><tt>Compare</tt></td></tr>
<tr>
<td><tt>value_compare</tt></td>
<td><em>Nested class to compare elements</em> (see member function <a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/map_3A_3Avalue_comp">value_comp</a>)</td></tr>
<tr>
<td><tt>allocator_type</tt></td>
<td><tt>Allocator</tt></td></tr>
<tr>
<td><tt>reference</tt></td>
<td><tt>Allocator::reference</tt></td></tr>
<tr>
<td><tt>const_reference</tt></td>
<td><tt>Allocator::const_reference</tt></td></tr>
<tr>
<td><tt>iterator</tt></td>
<td><em>Bidirectional iterator</em></td></tr>
<tr>
<td><tt>const_iterator</tt></td>
<td><em>Constant bidirectional iterator</em></td></tr>
<tr>
<td><tt>size_type</tt></td>
<td><em>Unsigned integral type</em> (usually same as <a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/size_t">size_t</a>)</td></tr>
<tr>
<td><tt>difference_type</tt></td>
<td><em>Signed integral type</em> (usually same as <a href="mk:@MSITStore:C:\Documents%20and%20Settings\Administrator\桌面\C++函数手册%20(LibraryFunctions).chm::/download/www.cplusplus.com/ptrdiff_t">ptrdiff_t</a>)</td></tr>
<tr>
<td><tt>pointer</tt></td>
<td><tt>Allocator::pointer</tt></td></tr>
<tr>
<td><tt>const_pointer</tt></td>
<td><tt>Allocator::const_pointer</tt></td></tr>
<tr>
<td><tt>reverse_iterator</tt></td>
<td><tt>reverse_iterator&lt;iterator&gt;</tt></td></tr>
<tr>
<td><tt>const_reverse_iterator</tt></td>
<td><tt>reverse_iterator&lt;const_iterator&gt;</tt></td></tr></tbody></table></p><img src ="http://www.cppblog.com/bersaty/aggbug/161349.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-12-03 12:07 <a href="http://www.cppblog.com/bersaty/archive/2011/12/03/161349.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><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>从一堆数中找出连续的若干个的和 能被P整除~</title><link>http://www.cppblog.com/bersaty/archive/2011/11/21/160620.html</link><dc:creator>bersaty</dc:creator><author>bersaty</author><pubDate>Mon, 21 Nov 2011 03:12:00 GMT</pubDate><guid>http://www.cppblog.com/bersaty/archive/2011/11/21/160620.html</guid><wfw:comment>http://www.cppblog.com/bersaty/comments/160620.html</wfw:comment><comments>http://www.cppblog.com/bersaty/archive/2011/11/21/160620.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bersaty/comments/commentRss/160620.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bersaty/services/trackbacks/160620.html</trackback:ping><description><![CDATA[<p align="left"><strong><font color="#333399" size="5">Input</font> </strong>
<p><font face="Times New Roman" size="3">第一行一个整数 T 代表case数。 <br />每个case第一行是两个整数 n（1&#8804; n&#8804; 100000）, p( 1&#8804;p&#8804;1000000),第二行是n个整数 <br />1&#8804;a(k) &#8804;10000( 1&#8804;k&#8804;n). <br /></font></p>
<p align="left"><strong><font color="#333399" size="5">Output</font> </strong>
<p><font face="Times New Roman" size="3">每个case输出一行，存在连续个a，这些a的和能被p整除就输出&#8220;Yes&#8221;,否则输出&#8220;No&#8221;.</font></p>
<p align="left"><strong><font color="#333399" size="5">Sample Input</font> </strong>
<p><font face="Times New Roman" size="3"><pre>2
3 5
1 3 2
3 5
4 4 4
</pre></font>
<p>&nbsp;</p>
<p align="left"><strong><font color="#333399" size="5">Sample Output</font> </strong>
<p><font face="Times New Roman" size="3"><pre>Yes
No
</pre></font><br /><br /><br /><br />一开始直接计算每种情况的值,严重超时 
<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 />--><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><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 id="Codehighlighter1_37_39_Open_Image" onclick="this.style.display='none'; Codehighlighter1_37_39_Open_Text.style.display='none'; Codehighlighter1_37_39_Closed_Image.style.display='inline'; Codehighlighter1_37_39_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_37_39_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_37_39_Closed_Text.style.display='none'; Codehighlighter1_37_39_Open_Image.style.display='inline'; Codehighlighter1_37_39_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;b[</span><span style="color: #000000">100000</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span id="Codehighlighter1_37_39_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 alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_37_39_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">0</span><span style="color: #000000">}</span></span><span style="color: #000000">;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_53_476_Open_Image" onclick="this.style.display='none'; Codehighlighter1_53_476_Open_Text.style.display='none'; Codehighlighter1_53_476_Closed_Image.style.display='inline'; Codehighlighter1_53_476_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_53_476_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_53_476_Closed_Text.style.display='none'; Codehighlighter1_53_476_Open_Image.style.display='inline'; Codehighlighter1_53_476_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_53_476_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 alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_53_476_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;t,n,p,a;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;c,i,j;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&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 /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&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">)<br /><img id="Codehighlighter1_121_463_Open_Image" onclick="this.style.display='none'; Codehighlighter1_121_463_Open_Text.style.display='none'; Codehighlighter1_121_463_Closed_Image.style.display='inline'; Codehighlighter1_121_463_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_121_463_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_121_463_Closed_Text.style.display='none'; Codehighlighter1_121_463_Open_Image.style.display='inline'; Codehighlighter1_121_463_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_121_463_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 alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_121_463_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d&nbsp;%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">n,</span><span style="color: #000000">&amp;</span><span style="color: #000000">p);<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(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">n;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_175_404_Open_Image" onclick="this.style.display='none'; Codehighlighter1_175_404_Open_Text.style.display='none'; Codehighlighter1_175_404_Closed_Image.style.display='inline'; Codehighlighter1_175_404_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_175_404_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_175_404_Closed_Text.style.display='none'; Codehighlighter1_175_404_Open_Image.style.display='inline'; Codehighlighter1_175_404_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_175_404_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 alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_175_404_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&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">a);<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a</span><span style="color: #000000">%=</span><span style="color: #000000">p;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">c)<br /><img id="Codehighlighter1_218_400_Open_Image" onclick="this.style.display='none'; Codehighlighter1_218_400_Open_Text.style.display='none'; Codehighlighter1_218_400_Closed_Image.style.display='inline'; Codehighlighter1_218_400_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_218_400_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_218_400_Closed_Text.style.display='none'; Codehighlighter1_218_400_Open_Image.style.display='inline'; Codehighlighter1_218_400_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_218_400_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 alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_218_400_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(j</span><span style="color: #000000">=</span><span style="color: #000000">i;j</span><span style="color: #000000">&gt;=</span><span style="color: #000000">0</span><span style="color: #000000">;j</span><span style="color: #000000">--</span><span style="color: #000000">)<br /><img id="Codehighlighter1_249_346_Open_Image" onclick="this.style.display='none'; Codehighlighter1_249_346_Open_Text.style.display='none'; Codehighlighter1_249_346_Closed_Image.style.display='inline'; Codehighlighter1_249_346_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_249_346_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_249_346_Closed_Text.style.display='none'; Codehighlighter1_249_346_Open_Image.style.display='inline'; Codehighlighter1_249_346_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_249_346_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 alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_249_346_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">c)<br /><img id="Codehighlighter1_271_340_Open_Image" onclick="this.style.display='none'; Codehighlighter1_271_340_Open_Text.style.display='none'; Codehighlighter1_271_340_Closed_Image.style.display='inline'; Codehighlighter1_271_340_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_271_340_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_271_340_Closed_Text.style.display='none'; Codehighlighter1_271_340_Open_Image.style.display='inline'; Codehighlighter1_271_340_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;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_271_340_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 alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_271_340_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b[j]</span><span style="color: #000000">=</span><span style="color: #000000">b[j</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">a;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(b[j]</span><span style="color: #000000">%</span><span style="color: #000000">p</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&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 alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b[</span><span style="color: #000000">0</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">a;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(b[</span><span style="color: #000000">0</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">0</span><span style="color: #000000">)<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(c)<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">Yes\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&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 /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&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 alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div><br /><br />同学提醒 (sum[i]-sum[j])%p==0和 sum[i]%p==sum[j]%p 相同&nbsp; 顿时开悟<br />sum[i]为前i项和 sum[j]为前j项和<br />
<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 />--><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><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 /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;b[</span><span style="color: #000000">1000000</span><span style="color: #000000">];<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_51_401_Open_Image" onclick="this.style.display='none'; Codehighlighter1_51_401_Open_Text.style.display='none'; Codehighlighter1_51_401_Closed_Image.style.display='inline'; Codehighlighter1_51_401_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_51_401_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_51_401_Closed_Text.style.display='none'; Codehighlighter1_51_401_Open_Image.style.display='inline'; Codehighlighter1_51_401_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_51_401_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 alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_51_401_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;t,n,p,a,s;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;c,i;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&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 /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&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">)<br /><img id="Codehighlighter1_119_388_Open_Image" onclick="this.style.display='none'; Codehighlighter1_119_388_Open_Text.style.display='none'; Codehighlighter1_119_388_Closed_Image.style.display='inline'; Codehighlighter1_119_388_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_119_388_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_119_388_Closed_Text.style.display='none'; Codehighlighter1_119_388_Open_Image.style.display='inline'; Codehighlighter1_119_388_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_119_388_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 alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_119_388_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%ld&nbsp;%ld</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">n,</span><span style="color: #000000">&amp;</span><span style="color: #000000">p);<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s</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 /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(b,</span><span style="color: #000000">0</span><span style="color: #000000">,p</span><span style="color: #000000">*</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">));<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(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">n;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_218_329_Open_Image" onclick="this.style.display='none'; Codehighlighter1_218_329_Open_Text.style.display='none'; Codehighlighter1_218_329_Closed_Image.style.display='inline'; Codehighlighter1_218_329_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_218_329_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_218_329_Closed_Text.style.display='none'; Codehighlighter1_218_329_Open_Image.style.display='inline'; Codehighlighter1_218_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_218_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 alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_218_329_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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">a);<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s</span><span style="color: #000000">+=</span><span style="color: #000000">a</span><span style="color: #000000">%</span><span style="color: #000000">p;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">c)<br /><img id="Codehighlighter1_264_325_Open_Image" onclick="this.style.display='none'; Codehighlighter1_264_325_Open_Text.style.display='none'; Codehighlighter1_264_325_Closed_Image.style.display='inline'; Codehighlighter1_264_325_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_264_325_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_264_325_Closed_Text.style.display='none'; Codehighlighter1_264_325_Open_Image.style.display='inline'; Codehighlighter1_264_325_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_264_325_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 alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_264_325_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(b[s</span><span style="color: #000000">%</span><span style="color: #000000">p]</span><span style="color: #000000">==</span><span style="color: #000000">s</span><span style="color: #000000">%</span><span style="color: #000000">p)<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b[s</span><span style="color: #000000">%</span><span style="color: #000000">p]</span><span style="color: #000000">=</span><span style="color: #000000">s</span><span style="color: #000000">%</span><span style="color: #000000">p;<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(c)<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">Yes\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&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 /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />&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 alt="" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div><br /> <img src ="http://www.cppblog.com/bersaty/aggbug/160620.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-21 11:12 <a href="http://www.cppblog.com/bersaty/archive/2011/11/21/160620.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>第六届itat C语言复赛~~~郁闷</title><link>http://www.cppblog.com/bersaty/archive/2011/11/05/159664.html</link><dc:creator>bersaty</dc:creator><author>bersaty</author><pubDate>Sat, 05 Nov 2011 05:19:00 GMT</pubDate><guid>http://www.cppblog.com/bersaty/archive/2011/11/05/159664.html</guid><wfw:comment>http://www.cppblog.com/bersaty/comments/159664.html</wfw:comment><comments>http://www.cppblog.com/bersaty/archive/2011/11/05/159664.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/bersaty/comments/commentRss/159664.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bersaty/services/trackbacks/159664.html</trackback:ping><description><![CDATA[第二题.........<br />a[742683613984]&nbsp; 删除8个数,使其变为最小的4位数~~<br />当时就写了思路就交了:&nbsp; <br /><br />从前面往后退,a[i]&gt;=a[i+1],就删了a[i],如此重复
<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 />--><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">stdio.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  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 src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_50_496_Open_Image" onclick="this.style.display='none'; Codehighlighter1_50_496_Open_Text.style.display='none'; Codehighlighter1_50_496_Closed_Image.style.display='inline'; Codehighlighter1_50_496_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_50_496_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_50_496_Closed_Text.style.display='none'; Codehighlighter1_50_496_Open_Image.style.display='inline'; Codehighlighter1_50_496_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_50_496_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_50_496_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;n[</span><span style="color: #000000">13</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">742683613984</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[</span><span style="color: #000000">13</span><span style="color: #000000">],i,len,w</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">,j;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;len</span><span style="color: #000000">=</span><span style="color: #000000">strlen(n);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&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 id="Codehighlighter1_146_195_Open_Image" onclick="this.style.display='none'; Codehighlighter1_146_195_Open_Text.style.display='none'; Codehighlighter1_146_195_Closed_Image.style.display='inline'; Codehighlighter1_146_195_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_146_195_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_146_195_Closed_Text.style.display='none'; Codehighlighter1_146_195_Open_Image.style.display='inline'; Codehighlighter1_146_195_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;</span><span id="Codehighlighter1_146_195_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_146_195_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[i]</span><span style="color: #000000">=</span><span style="color: #000000">n[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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,a[i]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&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 /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">do</span><span style="color: #000000"><br /><img id="Codehighlighter1_228_466_Open_Image" onclick="this.style.display='none'; Codehighlighter1_228_466_Open_Text.style.display='none'; Codehighlighter1_228_466_Closed_Image.style.display='inline'; Codehighlighter1_228_466_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_228_466_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_228_466_Closed_Text.style.display='none'; Codehighlighter1_228_466_Open_Image.style.display='inline'; Codehighlighter1_228_466_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;</span><span id="Codehighlighter1_228_466_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_228_466_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(a[i]</span><span style="color: #000000">&gt;</span><span style="color: #000000">a[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">])<br /><img id="Codehighlighter1_258_439_Open_Image" onclick="this.style.display='none'; Codehighlighter1_258_439_Open_Text.style.display='none'; Codehighlighter1_258_439_Closed_Image.style.display='inline'; Codehighlighter1_258_439_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_258_439_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_258_439_Closed_Text.style.display='none'; Codehighlighter1_258_439_Open_Image.style.display='inline'; Codehighlighter1_258_439_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_258_439_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_258_439_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d&nbsp;\n</span><span style="color: #000000">"</span><span style="color: #000000">,a[i]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(j</span><span style="color: #000000">=</span><span style="color: #000000">i;j</span><span style="color: #000000">&lt;</span><span style="color: #000000">len;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[j]</span><span style="color: #000000">=</span><span style="color: #000000">a[j</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;w</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;len</span><span style="color: #000000">--</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&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 id="Codehighlighter1_377_406_Open_Image" onclick="this.style.display='none'; Codehighlighter1_377_406_Open_Text.style.display='none'; Codehighlighter1_377_406_Closed_Image.style.display='inline'; Codehighlighter1_377_406_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_377_406_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_377_406_Closed_Text.style.display='none'; Codehighlighter1_377_406_Open_Image.style.display='inline'; Codehighlighter1_377_406_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_377_406_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_377_406_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,a[i]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&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 /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;}</span></span><span style="color: #0000ff">while</span><span style="color: #000000">(w</span><span style="color: #000000">&lt;</span><span style="color: #000000">8</span><span style="color: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&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 /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div><br /><br /><img src ="http://www.cppblog.com/bersaty/aggbug/159664.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-05 13:19 <a href="http://www.cppblog.com/bersaty/archive/2011/11/05/159664.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>转</title><link>http://www.cppblog.com/bersaty/archive/2011/10/03/157442.html</link><dc:creator>bersaty</dc:creator><author>bersaty</author><pubDate>Mon, 03 Oct 2011 14:10:00 GMT</pubDate><guid>http://www.cppblog.com/bersaty/archive/2011/10/03/157442.html</guid><wfw:comment>http://www.cppblog.com/bersaty/comments/157442.html</wfw:comment><comments>http://www.cppblog.com/bersaty/archive/2011/10/03/157442.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bersaty/comments/commentRss/157442.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bersaty/services/trackbacks/157442.html</trackback:ping><description><![CDATA[<div><font style="background-color: #cffad5">&nbsp;&nbsp;&nbsp;&nbsp; 蜜蜂在爱，而花朵在等待<br />　　<br />　　就这样吧，能多久就多久，如果有一天，峰回路转，如果你还记得我，如果我还爱着你<br />　　<br />　　漫天的星星如同破碎的钻石，明亮光耀，抬头仰望，总觉得他们离我并不遥远，只要登上屋顶，在搭上一张梯子，伸出手就能摘到，闪光灯果实。事实证明，那只是一场美丽的幻觉而已，于是我们哭着说，星星是骗子，在长大以后才渐渐明白，欺骗我们的，从来不是星星，而是自己那颗，被欲望填塞的看不清真相的心！<br />　　<br />　　给我一个微笑，我就跟你千山万水<br />　　<br />　　爱情也总是在患得患失的时候最美好，如果永远没有开始，也永远不会消逝，可是，谁又会按捺得住不去开始呢？<br />　　<br />　　当明天开幕的时候，我总是醒着出场的<br />　　<br />　　生活其实宁静美好，爱情仍只是一切偶然，不乏崎岖，但本来，不必如此的<br />　　<br />　　只要你快乐，我会时时刻刻爱你，我也会保有独立的自己，我是我的爱情最执着的牧者<br />　　<br />　　我在无数个夜里凌晨里把仅有的记忆碎片倒出来，敝帚自珍的数着，如同幸福的小乞丐，甘愿在自欺欺人里沉沦<br />　　<br />　　天黑黑的看我，我嘿嘿的看它<br />　　<br />　　树绿了又黄了，干枯了有复苏了，花开了又谢了，枯萎了又绽放了，生命的规律都是如此，更何况一场爱情<br />　　<br />　　我心的天空，风云莫测，既然无法看透，不妨欣赏<br />　　<br />　　生命的方程式，爱情只是一个未知数，常数是我们自己，一颦一笑一投足，其实总是那么简单，只要不纠缠，不解那个解不开的结<br />　　<br />　　他许给我这么多快乐，我不能不快乐，不能许给我爱情，我便独自收留我的爱情<br />　　<br />　　喜欢还是不喜欢，没有应该还是不应该，只能怪你好运或者不好运，遇见了好人还是坏人<br />　　<br />　　只要时间足够，彼岸亦有花香<br />　　<br />　　铭刻是记忆的方式，遗忘时间的本事<br />　　<br />　　天空是灰色的，好在我穿了彩色的衣裳，所以看起来，还不至于太坏<br />　　<br />　　爱能留是福，啊难守该悟<br />　　<br />　　承袭了我所有寂寞和悲伤的你，可不可以偶尔不要恨我<br />　　<br />　　我想我可以忍住悲伤，假装生命中没有你<br />　　<br />　　未来某一天，想起你说的永远，手中握着你给点誓言，多美<br />　　<br />　　生命是一种缘，不曾期待的灿烂会在你的淡薄从容中不期而至<br />　　<br />　　<br />　　别说爱情会老，别只会在摇头时微笑，甜蜜的时光只有你我知道，风在林梢鸟儿在叫，爱会上瘾，爱是安眠药，梦里花落知多少，可不可以不要醒太早<wbr></font></div><img src ="http://www.cppblog.com/bersaty/aggbug/157442.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-10-03 22:10 <a href="http://www.cppblog.com/bersaty/archive/2011/10/03/157442.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>兼职</title><link>http://www.cppblog.com/bersaty/archive/2011/10/02/157374.html</link><dc:creator>bersaty</dc:creator><author>bersaty</author><pubDate>Sun, 02 Oct 2011 14:59:00 GMT</pubDate><guid>http://www.cppblog.com/bersaty/archive/2011/10/02/157374.html</guid><wfw:comment>http://www.cppblog.com/bersaty/comments/157374.html</wfw:comment><comments>http://www.cppblog.com/bersaty/archive/2011/10/02/157374.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bersaty/comments/commentRss/157374.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bersaty/services/trackbacks/157374.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp; 兼职开始第二天，珊在两个男的陪同下走来，我和几个师姐刚好遇到。是不是女生都容易羡慕妒忌恨，我和师姐聊天，她就和那两个男的聊天，而且越聊越起劲。。。之前面试时遇到珊，长的挺漂亮，感觉人也应该不错。想起了一个故事，一ACMer因看ACM比赛见到一个礼仪小姐很漂亮，就想认识她，经过心理斗争，最后都没定下方法。9大经理说直接当面告诉她因看比赛时看到你，因此对你一见钟情，留下联系电话，结果听天由命了。世界上就三种事，我的事，你的事，老天的事。你的事我管不了，老天的事天说了算，唯一能做的就是我的事，要怎么做就看自己的了。这次我主动了，要了珊的电话，她拿过我的手机，输入了她的手机号码（她是唯一一个这样做的人，我问其他女生拿电话时都是直接说出号码的），然后就一起走了一段路，真的很想拉她的手。但之后我发信息给她她都不回。。。今天她和一个男的一起走，我和那男的一起进更衣室，换完衣服我以为他要等珊的，没想到他马上就走了，当我出来时珊问我那个男的呢，我说他走了，珊不信，叫我喊他的名字，我喊了几次，珊才相信，我和珊走了一小段路，我问她问什么不回我短信，她很不高兴的说&#8220;谁有你那么多流量!&#8221;。。。伤心啊，女生都是见哪个帅就爱哪个吗？.........<img src ="http://www.cppblog.com/bersaty/aggbug/157374.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-10-02 22:59 <a href="http://www.cppblog.com/bersaty/archive/2011/10/02/157374.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></channel></rss>