﻿<?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++博客-wyh123</title><link>http://www.cppblog.com/wyh123/</link><description>解题思路记录和牢骚</description><language>zh-cn</language><lastBuildDate>Sun, 19 Apr 2026 12:16:43 GMT</lastBuildDate><pubDate>Sun, 19 Apr 2026 12:16:43 GMT</pubDate><ttl>60</ttl><item><title>poj 1042（DP）</title><link>http://www.cppblog.com/wyh123/archive/2011/08/10/152984.html</link><dc:creator>wyh</dc:creator><author>wyh</author><pubDate>Wed, 10 Aug 2011 13:16:00 GMT</pubDate><guid>http://www.cppblog.com/wyh123/archive/2011/08/10/152984.html</guid><wfw:comment>http://www.cppblog.com/wyh123/comments/152984.html</wfw:comment><comments>http://www.cppblog.com/wyh123/archive/2011/08/10/152984.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wyh123/comments/commentRss/152984.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wyh123/services/trackbacks/152984.html</trackback:ping><description><![CDATA[题目大意：<span>john现有h个小时的空闲时间，他打算去钓鱼。john钓鱼的地方共有n个湖，所有的湖沿着一条单向路顺序排列（john每在一个湖钓完鱼后，他只能走到下一个湖继续钓），john必须从1号湖开始钓起，但是他可以在任何一个湖结束他此次钓鱼的行程。输入给出john在每个湖中每5分钟钓的鱼数（此题中以5分钟作为单位时间），随时间的增长而线性递减。而每个湖中头5分钟可以钓到的鱼数以及每个湖中相邻5分钟钓鱼数的减少量，John从任意一个湖走到它下一个湖的时间。 <br /><br />解题思路：1）设fish[i][j]表示到了第i个池塘用了j*5分钟所钓到的雨的数目<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2）转移：fish[i][j]=Max{fish[i-1][j-k-t[i]],fish[i][j]+sum}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum是呆着这个池塘经过k*5分钟所钓到的鱼的数目~sum=f[i]*(k+1)-(k+1)*k/2*d[i]<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 />--><span style="color: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cmath</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><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 /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">10</span><span style="color: #000000"><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;f[</span><span style="color: #000000">30</span><span style="color: #000000">],d[</span><span style="color: #000000">30</span><span style="color: #000000">],t[</span><span style="color: #000000">30</span><span style="color: #000000">],path[</span><span style="color: #000000">30</span><span style="color: #000000">];<br /></span><span style="color: #008080">11</span><span style="color: #000000"><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;fish[</span><span style="color: #000000">30</span><span style="color: #000000">][</span><span style="color: #000000">400</span><span style="color: #000000">];<br /></span><span style="color: #008080">12</span><span style="color: #000000"><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;n,h,maxx,k;<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">14</span><span style="color: #000000"><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;init()<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img id="Codehighlighter1_217_288_Open_Image" onclick="this.style.display='none'; Codehighlighter1_217_288_Open_Text.style.display='none'; Codehighlighter1_217_288_Closed_Image.style.display='inline'; Codehighlighter1_217_288_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_217_288_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_217_288_Closed_Text.style.display='none'; Codehighlighter1_217_288_Open_Image.style.display='inline'; Codehighlighter1_217_288_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_217_288_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_217_288_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;memset(path,&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(path));<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;memset(fish,</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(fish));<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">19</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">20</span><span style="color: #000000"><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;find_Path(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;time)<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img id="Codehighlighter1_323_576_Open_Image" onclick="this.style.display='none'; Codehighlighter1_323_576_Open_Text.style.display='none'; Codehighlighter1_323_576_Closed_Image.style.display='inline'; Codehighlighter1_323_576_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_323_576_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_323_576_Closed_Text.style.display='none'; Codehighlighter1_323_576_Open_Image.style.display='inline'; Codehighlighter1_323_576_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_323_576_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_323_576_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(i</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">;<br /></span><span style="color: #008080">23</span><span style="color: #000000"><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;summ</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">24</span><span style="color: #000000"><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">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;k</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;k</span><span style="color: #000000">&lt;=</span><span style="color: #000000">12</span><span style="color: #000000">*</span><span style="color: #000000">h;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">k)<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img id="Codehighlighter1_385_574_Open_Image" onclick="this.style.display='none'; Codehighlighter1_385_574_Open_Text.style.display='none'; Codehighlighter1_385_574_Closed_Image.style.display='inline'; Codehighlighter1_385_574_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_385_574_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_385_574_Closed_Text.style.display='none'; Codehighlighter1_385_574_Open_Image.style.display='inline'; Codehighlighter1_385_574_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_385_574_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_385_574_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(fish[i</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">][time</span><span style="color: #000000">-</span><span style="color: #000000">k</span><span style="color: #000000">-</span><span style="color: #000000">t[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">summ</span><span style="color: #000000">==</span><span style="color: #000000">fish[i][time])<br /></span><span style="color: #008080">27</span><span style="color: #000000"><img id="Codehighlighter1_440_500_Open_Image" onclick="this.style.display='none'; Codehighlighter1_440_500_Open_Text.style.display='none'; Codehighlighter1_440_500_Closed_Image.style.display='inline'; Codehighlighter1_440_500_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_440_500_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_440_500_Closed_Text.style.display='none'; Codehighlighter1_440_500_Open_Image.style.display='inline'; Codehighlighter1_440_500_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_440_500_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_440_500_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">28</span><span style="color: #000000"><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;path[i]</span><span style="color: #000000">=</span><span style="color: #000000">k</span><span style="color: #000000">*</span><span style="color: #000000">5</span><span style="color: #000000">;<br /></span><span style="color: #008080">29</span><span style="color: #000000"><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">return</span><span style="color: #000000">&nbsp;find_Path(i</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">,time</span><span style="color: #000000">-</span><span style="color: #000000">k</span><span style="color: #000000">-</span><span style="color: #000000">t[i</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 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 /></span><span style="color: #008080">31</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(f[i]</span><span style="color: #000000">-</span><span style="color: #000000">k</span><span style="color: #000000">*</span><span style="color: #000000">d[i]</span><span style="color: #000000">&gt;</span><span style="color: #000000">0</span><span style="color: #000000">)<br /></span><span style="color: #008080">32</span><span style="color: #000000"><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;summ</span><span style="color: #000000">=</span><span style="color: #000000">f[i]</span><span style="color: #000000">*</span><span style="color: #000000">(k</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">(k</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">k</span><span style="color: #000000">/</span><span style="color: #000000">2</span><span style="color: #000000">*</span><span style="color: #000000">d[i];<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">34</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">35</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">36</span><span style="color: #000000"><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;get_DP()<br /></span><span style="color: #008080">37</span><span style="color: #000000"><img id="Codehighlighter1_593_1233_Open_Image" onclick="this.style.display='none'; Codehighlighter1_593_1233_Open_Text.style.display='none'; Codehighlighter1_593_1233_Closed_Image.style.display='inline'; Codehighlighter1_593_1233_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_593_1233_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_593_1233_Closed_Text.style.display='none'; Codehighlighter1_593_1233_Open_Image.style.display='inline'; Codehighlighter1_593_1233_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_593_1233_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_593_1233_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">38</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;fish[</span><span style="color: #000000">0</span><span style="color: #000000">][</span><span style="color: #000000">0</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">39</span><span style="color: #000000"><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">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">i)<br /></span><span style="color: #008080">40</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;j</span><span style="color: #000000">&lt;=</span><span style="color: #000000">12</span><span style="color: #000000">*</span><span style="color: #000000">h;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">j)<br /></span><span style="color: #008080">41</span><span style="color: #000000"><img id="Codehighlighter1_668_1046_Open_Image" onclick="this.style.display='none'; Codehighlighter1_668_1046_Open_Text.style.display='none'; Codehighlighter1_668_1046_Closed_Image.style.display='inline'; Codehighlighter1_668_1046_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_668_1046_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_668_1046_Closed_Text.style.display='none'; Codehighlighter1_668_1046_Open_Image.style.display='inline'; Codehighlighter1_668_1046_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_668_1046_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_668_1046_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">42</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;summ</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">43</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;k</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;k</span><span style="color: #000000">&lt;=</span><span style="color: #000000">12</span><span style="color: #000000">*</span><span style="color: #000000">h&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;fish[i][j]</span><span style="color: #000000">!=-</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">k)<br /></span><span style="color: #008080">44</span><span style="color: #000000"><img id="Codehighlighter1_763_1036_Open_Image" onclick="this.style.display='none'; Codehighlighter1_763_1036_Open_Text.style.display='none'; Codehighlighter1_763_1036_Closed_Image.style.display='inline'; Codehighlighter1_763_1036_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_763_1036_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_763_1036_Closed_Text.style.display='none'; Codehighlighter1_763_1036_Open_Image.style.display='inline'; Codehighlighter1_763_1036_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_763_1036_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_763_1036_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">45</span><span style="color: #000000"><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">(j</span><span style="color: #000000">+</span><span style="color: #000000">k</span><span style="color: #000000">+</span><span style="color: #000000">t[i]</span><span style="color: #000000">&lt;=</span><span style="color: #000000">12</span><span style="color: #000000">*</span><span style="color: #000000">h)<br /></span><span style="color: #008080">46</span><span style="color: #000000"><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;fish[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">][j</span><span style="color: #000000">+</span><span style="color: #000000">k</span><span style="color: #000000">+</span><span style="color: #000000">t[i]]</span><span style="color: #000000">=</span><span style="color: #000000">max(fish[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">][j</span><span style="color: #000000">+</span><span style="color: #000000">k</span><span style="color: #000000">+</span><span style="color: #000000">t[i]],fish[i][j]</span><span style="color: #000000">+</span><span style="color: #000000">summ);<br /></span><span style="color: #008080">47</span><span style="color: #000000"><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 /></span><span style="color: #008080">48</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /></span><span style="color: #008080">49</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(f[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">k</span><span style="color: #000000">*</span><span style="color: #000000">d[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">&gt;</span><span style="color: #000000">0</span><span style="color: #000000">)<br /></span><span style="color: #008080">50</span><span style="color: #000000"><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;summ</span><span style="color: #000000">=</span><span style="color: #000000">f[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">(k</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">(k</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">k</span><span style="color: #000000">/</span><span style="color: #000000">2</span><span style="color: #000000">*</span><span style="color: #000000">d[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">];<br /></span><span style="color: #008080">51</span><span style="color: #000000"><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 /></span><span style="color: #008080">52</span><span style="color: #000000"><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 /></span><span style="color: #008080">53</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maxx</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">54</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">55</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;n;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">i)<br /></span><span style="color: #008080">56</span><span style="color: #000000"><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">(maxx</span><span style="color: #000000">&lt;</span><span style="color: #000000">fish[i][</span><span style="color: #000000">12</span><span style="color: #000000">*</span><span style="color: #000000">h])<br /></span><span style="color: #008080">57</span><span style="color: #000000"><img id="Codehighlighter1_1160_1231_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1160_1231_Open_Text.style.display='none'; Codehighlighter1_1160_1231_Closed_Image.style.display='inline'; Codehighlighter1_1160_1231_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1160_1231_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1160_1231_Closed_Text.style.display='none'; Codehighlighter1_1160_1231_Open_Image.style.display='inline'; Codehighlighter1_1160_1231_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_1160_1231_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1160_1231_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">58</span><span style="color: #000000"><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;maxx</span><span style="color: #000000">=</span><span style="color: #000000">fish[i][</span><span style="color: #000000">12</span><span style="color: #000000">*</span><span style="color: #000000">h];<br /></span><span style="color: #008080">59</span><span style="color: #000000"><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;k</span><span style="color: #000000">=</span><span style="color: #000000">i;<br /></span><span style="color: #008080">60</span><span style="color: #000000"><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 /></span><span style="color: #008080">61</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">62</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">63</span><span style="color: #000000"><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 /></span><span style="color: #008080">64</span><span style="color: #000000"><img id="Codehighlighter1_1247_1767_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1247_1767_Open_Text.style.display='none'; Codehighlighter1_1247_1767_Closed_Image.style.display='inline'; Codehighlighter1_1247_1767_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_1247_1767_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1247_1767_Closed_Text.style.display='none'; Codehighlighter1_1247_1767_Open_Image.style.display='inline'; Codehighlighter1_1247_1767_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_1247_1767_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1247_1767_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">65</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;(</span><span style="color: #000000">~</span><span style="color: #000000">scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">n))<br /></span><span style="color: #008080">66</span><span style="color: #000000"><img id="Codehighlighter1_1281_1751_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1281_1751_Open_Text.style.display='none'; Codehighlighter1_1281_1751_Closed_Image.style.display='inline'; Codehighlighter1_1281_1751_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1281_1751_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1281_1751_Closed_Text.style.display='none'; Codehighlighter1_1281_1751_Open_Image.style.display='inline'; Codehighlighter1_1281_1751_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_1281_1751_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1281_1751_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">67</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(n</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /></span><span style="color: #008080">68</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">h);<br /></span><span style="color: #008080">69</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">f[i]);<br /></span><span style="color: #008080">70</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">d[i]);<br /></span><span style="color: #008080">71</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">t[i]);<br /></span><span style="color: #008080">72</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;init();<br /></span><span style="color: #008080">73</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;get_DP();<br /></span><span style="color: #008080">74</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;find_Path(k,&nbsp;</span><span style="color: #000000">12</span><span style="color: #000000">*</span><span style="color: #000000">h);<br /></span><span style="color: #008080">75</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;n</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">i)<br /></span><span style="color: #008080">76</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,path[i]);<br /></span><span style="color: #008080">77</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,path[n]);<br /></span><span style="color: #008080">78</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">Number&nbsp;of&nbsp;fish&nbsp;expected:&nbsp;%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;fish[k][</span><span style="color: #000000">12</span><span style="color: #000000">*</span><span style="color: #000000">h]);<br /></span><span style="color: #008080">79</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /></span><span style="color: #008080">80</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">81</span><span style="color: #000000"><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 /></span><span style="color: #008080">82</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">83</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div><br /><br /><br /></span><img src ="http://www.cppblog.com/wyh123/aggbug/152984.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wyh123/" target="_blank">wyh</a> 2011-08-10 21:16 <a href="http://www.cppblog.com/wyh123/archive/2011/08/10/152984.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>poj 1036（DP）</title><link>http://www.cppblog.com/wyh123/archive/2011/08/09/152890.html</link><dc:creator>wyh</dc:creator><author>wyh</author><pubDate>Tue, 09 Aug 2011 12:40:00 GMT</pubDate><guid>http://www.cppblog.com/wyh123/archive/2011/08/09/152890.html</guid><wfw:comment>http://www.cppblog.com/wyh123/comments/152890.html</wfw:comment><comments>http://www.cppblog.com/wyh123/archive/2011/08/09/152890.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wyh123/comments/commentRss/152890.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wyh123/services/trackbacks/152890.html</trackback:ping><description><![CDATA[题目大意： 宾馆有个伸缩门，其开放状态用[0,k]之间某个数来表示，每秒钟它至多可以伸长或减少1个单位。现在有n个强盗，他们会在ti的时间到达宾馆，如果此时门的开放度和他的身材si恰好相同，他就会进来，并得到pi的加分。一开始门是关闭的(开放度为0)，请你求出时刻t的最大加分。<br /><br /><br />解题思路：1）这道题的状态很容易就可以找出来：dp[i][j]表示在第i秒钟门的宽度为j所取得的最大加分。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2）那么转移就是：dp[i][j]=Max{dp[i-1][j+1],dp[i-1][j-1],dp[i][j]}+dp[i][j]~前一个时刻可以由三个状态转变而来，直接求最大值就可以了<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3)&nbsp;这道题的空间限制是10000K~，完整的数组开不了，只能开滚动数组~（WA了之后才发现的）<br /><br />~~本以为改为滚动数组后就过了~~，没想到果断T了~~，没办法，又加了张hash记录强盗在什么时刻到达宾馆来稍微稍微降低复杂度。<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 />--><span style="color: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cmath</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><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 /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">10</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;Person<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img id="Codehighlighter1_150_167_Open_Image" onclick="this.style.display='none'; Codehighlighter1_150_167_Open_Text.style.display='none'; Codehighlighter1_150_167_Closed_Image.style.display='inline'; Codehighlighter1_150_167_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_150_167_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_150_167_Closed_Text.style.display='none'; Codehighlighter1_150_167_Open_Image.style.display='inline'; Codehighlighter1_150_167_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_150_167_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_150_167_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">12</span><span style="color: #000000"><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;t,s,p;<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000">num[</span><span style="color: #000000">110</span><span style="color: #000000">];<br /></span><span style="color: #008080">14</span><span style="color: #000000"><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;dp[</span><span style="color: #000000">3</span><span style="color: #000000">][</span><span style="color: #000000">110</span><span style="color: #000000">];<br /></span><span style="color: #008080">15</span><span style="color: #000000"><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;hash[</span><span style="color: #000000">30100</span><span style="color: #000000">];<br /></span><span style="color: #008080">16</span><span style="color: #000000"><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;n,t,k,summ;<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">18</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">19</span><span style="color: #000000"><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;init()<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img id="Codehighlighter1_241_305_Open_Image" onclick="this.style.display='none'; Codehighlighter1_241_305_Open_Text.style.display='none'; Codehighlighter1_241_305_Closed_Image.style.display='inline'; Codehighlighter1_241_305_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_241_305_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_241_305_Closed_Text.style.display='none'; Codehighlighter1_241_305_Open_Image.style.display='inline'; Codehighlighter1_241_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_241_305_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_241_305_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;memset(dp,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(dp));<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;memset(hash,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(hash));<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">24</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">25</span><span style="color: #000000"><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;get_DP()<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img id="Codehighlighter1_322_875_Open_Image" onclick="this.style.display='none'; Codehighlighter1_322_875_Open_Text.style.display='none'; Codehighlighter1_322_875_Closed_Image.style.display='inline'; Codehighlighter1_322_875_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_322_875_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_322_875_Closed_Text.style.display='none'; Codehighlighter1_322_875_Open_Image.style.display='inline'; Codehighlighter1_322_875_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_322_875_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_322_875_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">27</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">t;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img id="Codehighlighter1_357_873_Open_Image" onclick="this.style.display='none'; Codehighlighter1_357_873_Open_Text.style.display='none'; Codehighlighter1_357_873_Closed_Image.style.display='inline'; Codehighlighter1_357_873_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_357_873_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_357_873_Closed_Text.style.display='none'; Codehighlighter1_357_873_Open_Image.style.display='inline'; Codehighlighter1_357_873_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_357_873_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_357_873_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;j</span><span style="color: #000000">&lt;=</span><span style="color: #000000">k&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">&lt;=</span><span style="color: #000000">i;&nbsp;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img id="Codehighlighter1_408_867_Open_Image" onclick="this.style.display='none'; Codehighlighter1_408_867_Open_Text.style.display='none'; Codehighlighter1_408_867_Closed_Image.style.display='inline'; Codehighlighter1_408_867_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_408_867_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_408_867_Closed_Text.style.display='none'; Codehighlighter1_408_867_Open_Image.style.display='inline'; Codehighlighter1_408_867_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_408_867_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_408_867_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">31</span><span style="color: #000000"><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;summ</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(hash[i]</span><span style="color: #000000">!=</span><span style="color: #000000">0</span><span style="color: #000000">)<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img id="Codehighlighter1_470_592_Open_Image" onclick="this.style.display='none'; Codehighlighter1_470_592_Open_Text.style.display='none'; Codehighlighter1_470_592_Closed_Image.style.display='inline'; Codehighlighter1_470_592_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_470_592_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_470_592_Closed_Text.style.display='none'; Codehighlighter1_470_592_Open_Image.style.display='inline'; Codehighlighter1_470_592_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_470_592_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_470_592_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">34</span><span style="color: #000000"><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">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;l</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;l</span><span style="color: #000000">&lt;</span><span style="color: #000000">n;&nbsp;l</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">35</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(i</span><span style="color: #000000">==</span><span style="color: #000000">num[l].t&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">==</span><span style="color: #000000">num[l].s)&nbsp;summ</span><span style="color: #000000">+=</span><span style="color: #000000">num[l].p;<br /></span><span style="color: #008080">36</span><span style="color: #000000"><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 /></span><span style="color: #008080">37</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(j</span><span style="color: #000000">==</span><span style="color: #000000">k)&nbsp;dp[i</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][j]</span><span style="color: #000000">=</span><span style="color: #000000">max(dp[(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">3</span><span style="color: #000000">][j</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">],dp[(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">3</span><span style="color: #000000">][j]);<br /></span><span style="color: #008080">38</span><span style="color: #000000"><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">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(j</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)&nbsp;dp[i</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][j]</span><span style="color: #000000">=</span><span style="color: #000000">max(dp[(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">3</span><span style="color: #000000">][j</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">],dp[(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">3</span><span style="color: #000000">][j]);<br /></span><span style="color: #008080">39</span><span style="color: #000000"><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">&nbsp;dp[i</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][j]</span><span style="color: #000000">=</span><span style="color: #000000">max(max(dp[(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">3</span><span style="color: #000000">][j</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">],dp[(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">3</span><span style="color: #000000">][j]),dp[(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">3</span><span style="color: #000000">][j</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">]);<br /></span><span style="color: #008080">40</span><span style="color: #000000"><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;dp[i</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][j]</span><span style="color: #000000">+=</span><span style="color: #000000">summ;<br /></span><span style="color: #008080">41</span><span style="color: #000000"><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 /></span><span style="color: #008080">42</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">43</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">44</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">45</span><span style="color: #000000"><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;cmp(</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;Person&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">a,</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;Person&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">b)<br /></span><span style="color: #008080">46</span><span style="color: #000000"><img id="Codehighlighter1_919_976_Open_Image" onclick="this.style.display='none'; Codehighlighter1_919_976_Open_Text.style.display='none'; Codehighlighter1_919_976_Closed_Image.style.display='inline'; Codehighlighter1_919_976_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_919_976_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_919_976_Closed_Text.style.display='none'; Codehighlighter1_919_976_Open_Image.style.display='inline'; Codehighlighter1_919_976_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_919_976_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_919_976_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">47</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(a.t</span><span style="color: #000000">==</span><span style="color: #000000">b.t)&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;a.s</span><span style="color: #000000">&lt;</span><span style="color: #000000">b.s;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;a.t</span><span style="color: #000000">&lt;</span><span style="color: #000000">b.t;<br /></span><span style="color: #008080">48</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">49</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">50</span><span style="color: #000000"><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 /></span><span style="color: #008080">51</span><span style="color: #000000"><img id="Codehighlighter1_990_1441_Open_Image" onclick="this.style.display='none'; Codehighlighter1_990_1441_Open_Text.style.display='none'; Codehighlighter1_990_1441_Closed_Image.style.display='inline'; Codehighlighter1_990_1441_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_990_1441_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_990_1441_Closed_Text.style.display='none'; Codehighlighter1_990_1441_Open_Image.style.display='inline'; Codehighlighter1_990_1441_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_990_1441_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_990_1441_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">52</span><span style="color: #000000"><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%d%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">k,</span><span style="color: #000000">&amp;</span><span style="color: #000000">t);<br /></span><span style="color: #008080">53</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">54</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">55</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">(num[i].t));<br /></span><span style="color: #008080">56</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">57</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">(num[i].p));<br /></span><span style="color: #008080">58</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">59</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">(num[i].s));<br /></span><span style="color: #008080">60</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;sort(num,num</span><span style="color: #000000">+</span><span style="color: #000000">n,cmp);<br /></span><span style="color: #008080">61</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;init();<br /></span><span style="color: #008080">62</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">63</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hash[num[i].t]</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">64</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;get_DP();<br /></span><span style="color: #008080">65</span><span style="color: #000000"><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;maxx</span><span style="color: #000000">=-</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">66</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">k;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">67</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(maxx</span><span style="color: #000000">&lt;</span><span style="color: #000000">dp[t</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][i])&nbsp;&nbsp;maxx</span><span style="color: #000000">=</span><span style="color: #000000">dp[t</span><span style="color: #000000">%</span><span style="color: #000000">3</span><span style="color: #000000">][i];<br /></span><span style="color: #008080">68</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,maxx);<br /></span><span style="color: #008080">69</span><span style="color: #000000"><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 /></span><span style="color: #008080">70</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">71</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div><br /><img src ="http://www.cppblog.com/wyh123/aggbug/152890.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wyh123/" target="_blank">wyh</a> 2011-08-09 20:40 <a href="http://www.cppblog.com/wyh123/archive/2011/08/09/152890.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>poj 1029（模拟）</title><link>http://www.cppblog.com/wyh123/archive/2011/08/09/152874.html</link><dc:creator>wyh</dc:creator><author>wyh</author><pubDate>Tue, 09 Aug 2011 09:08:00 GMT</pubDate><guid>http://www.cppblog.com/wyh123/archive/2011/08/09/152874.html</guid><wfw:comment>http://www.cppblog.com/wyh123/comments/152874.html</wfw:comment><comments>http://www.cppblog.com/wyh123/archive/2011/08/09/152874.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wyh123/comments/commentRss/152874.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wyh123/services/trackbacks/152874.html</trackback:ping><description><![CDATA[题目大意：给出n个硬币（真币和假币质量不同），和k次比较。每次比较去p个硬币置于天平左盘，p个至于右盘，先给出每次比较的硬币编号和比较结果，要求找出假币的编号。找不到就输出&#8220;0&#8221;<br /><br /><br />解题思路：根据题意可以知道一下几点：<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1）每次出现"="，一定是真币<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2）真币一定不会出现在不等式中<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3）如果假币唯一则一定出现在每一次不等式中。&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4）因为不知道假币是比真币重还是轻，但是不管是轻还是重，它都只会出现在不等式小的一边（或者大的一边）<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;基于上面几点：我们可以将=号左右出现的真币先排除，然后统一大于小于号，统计硬币在重的一方，轻的一方出现的次数。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果存在且仅存在一个硬币在不等号一个方向出现的次数等于不等式出现的次数，那个硬币就一定是假币。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*_*。。。。。。在写这道程序之前写了一道多达150行的按操作模拟的程序，虽然A了，但是看起来好恶心！！<br /><br />代码：&nbsp;
<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 />--><span style="color: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cmath</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><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 /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;MAX</span><span style="color: #000000">=</span><span style="color: #000000">1001</span><span style="color: #000000">;<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">11</span><span style="color: #000000"><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;n,k,p,total</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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;temp;<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img id="Codehighlighter1_180_182_Open_Image" onclick="this.style.display='none'; Codehighlighter1_180_182_Open_Text.style.display='none'; Codehighlighter1_180_182_Closed_Image.style.display='inline'; Codehighlighter1_180_182_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_180_182_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_180_182_Closed_Text.style.display='none'; Codehighlighter1_180_182_Open_Image.style.display='inline'; Codehighlighter1_180_182_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[MAX]</span><span style="color: #000000">=</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_180_182_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_180_182_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">0</span><span style="color: #000000">}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img id="Codehighlighter1_196_198_Open_Image" onclick="this.style.display='none'; Codehighlighter1_196_198_Open_Text.style.display='none'; Codehighlighter1_196_198_Closed_Image.style.display='inline'; Codehighlighter1_196_198_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_196_198_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_196_198_Closed_Text.style.display='none'; Codehighlighter1_196_198_Open_Image.style.display='inline'; Codehighlighter1_196_198_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;r[MAX]</span><span style="color: #000000">=</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_196_198_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_196_198_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">0</span><span style="color: #000000">}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img id="Codehighlighter1_216_218_Open_Image" onclick="this.style.display='none'; Codehighlighter1_216_218_Open_Text.style.display='none'; Codehighlighter1_216_218_Closed_Image.style.display='inline'; Codehighlighter1_216_218_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_216_218_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_216_218_Closed_Text.style.display='none'; Codehighlighter1_216_218_Open_Image.style.display='inline'; Codehighlighter1_216_218_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;times[MAX]</span><span style="color: #000000">=</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_216_218_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_216_218_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">0</span><span style="color: #000000">}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">17</span><span style="color: #000000"><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 /></span><span style="color: #008080">18</span><span style="color: #000000"><img id="Codehighlighter1_233_1335_Open_Image" onclick="this.style.display='none'; Codehighlighter1_233_1335_Open_Text.style.display='none'; Codehighlighter1_233_1335_Closed_Image.style.display='inline'; Codehighlighter1_233_1335_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_233_1335_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_233_1335_Closed_Text.style.display='none'; Codehighlighter1_233_1335_Open_Image.style.display='inline'; Codehighlighter1_233_1335_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_233_1335_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_233_1335_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;k;<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;(k</span><span style="color: #000000">--</span><span style="color: #000000">)<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img id="Codehighlighter1_274_1048_Open_Image" onclick="this.style.display='none'; Codehighlighter1_274_1048_Open_Text.style.display='none'; Codehighlighter1_274_1048_Closed_Image.style.display='inline'; Codehighlighter1_274_1048_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_274_1048_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_274_1048_Closed_Text.style.display='none'; Codehighlighter1_274_1048_Open_Image.style.display='inline'; Codehighlighter1_274_1048_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_274_1048_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_274_1048_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;p;<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">2</span><span style="color: #000000">*</span><span style="color: #000000">p;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img id="Codehighlighter1_336_371_Open_Image" onclick="this.style.display='none'; Codehighlighter1_336_371_Open_Text.style.display='none'; Codehighlighter1_336_371_Closed_Image.style.display='inline'; Codehighlighter1_336_371_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_336_371_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_336_371_Closed_Text.style.display='none'; Codehighlighter1_336_371_Open_Image.style.display='inline'; Codehighlighter1_336_371_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_336_371_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_336_371_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;a[i];<br /></span><span style="color: #008080">26</span><span style="color: #000000"><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 /></span><span style="color: #008080">27</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;temp;<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(temp</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">=</span><span style="color: #000000">'</span><span style="color: #000000">)<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img id="Codehighlighter1_425_528_Open_Image" onclick="this.style.display='none'; Codehighlighter1_425_528_Open_Text.style.display='none'; Codehighlighter1_425_528_Closed_Image.style.display='inline'; Codehighlighter1_425_528_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_425_528_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_425_528_Closed_Text.style.display='none'; Codehighlighter1_425_528_Open_Image.style.display='inline'; Codehighlighter1_425_528_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_425_528_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_425_528_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">2</span><span style="color: #000000">*</span><span style="color: #000000">p;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">31</span><span style="color: #000000"><img id="Codehighlighter1_477_518_Open_Image" onclick="this.style.display='none'; Codehighlighter1_477_518_Open_Text.style.display='none'; Codehighlighter1_477_518_Closed_Image.style.display='inline'; Codehighlighter1_477_518_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_477_518_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_477_518_Closed_Text.style.display='none'; Codehighlighter1_477_518_Open_Image.style.display='inline'; Codehighlighter1_477_518_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_477_518_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_477_518_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">32</span><span style="color: #000000"><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;r[a[i]]</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">33</span><span style="color: #000000"><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 /></span><span style="color: #008080">34</span><span style="color: #000000"><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 /></span><span style="color: #008080">35</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(temp</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">&lt;</span><span style="color: #000000">'</span><span style="color: #000000">)<br /></span><span style="color: #008080">36</span><span style="color: #000000"><img id="Codehighlighter1_561_786_Open_Image" onclick="this.style.display='none'; Codehighlighter1_561_786_Open_Text.style.display='none'; Codehighlighter1_561_786_Closed_Image.style.display='inline'; Codehighlighter1_561_786_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_561_786_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_561_786_Closed_Text.style.display='none'; Codehighlighter1_561_786_Open_Image.style.display='inline'; Codehighlighter1_561_786_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_561_786_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_561_786_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">37</span><span style="color: #000000"><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;total</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">38</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">p;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">39</span><span style="color: #000000"><img id="Codehighlighter1_632_677_Open_Image" onclick="this.style.display='none'; Codehighlighter1_632_677_Open_Text.style.display='none'; Codehighlighter1_632_677_Closed_Image.style.display='inline'; Codehighlighter1_632_677_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_632_677_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_632_677_Closed_Text.style.display='none'; Codehighlighter1_632_677_Open_Image.style.display='inline'; Codehighlighter1_632_677_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_632_677_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_632_677_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">40</span><span style="color: #000000"><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;times[a[i]]</span><span style="color: #000000">--</span><span style="color: #000000">;<br /></span><span style="color: #008080">41</span><span style="color: #000000"><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 /></span><span style="color: #008080">42</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;p;&nbsp;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">2</span><span style="color: #000000">*</span><span style="color: #000000">p;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">43</span><span style="color: #000000"><img id="Codehighlighter1_731_776_Open_Image" onclick="this.style.display='none'; Codehighlighter1_731_776_Open_Text.style.display='none'; Codehighlighter1_731_776_Closed_Image.style.display='inline'; Codehighlighter1_731_776_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_731_776_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_731_776_Closed_Text.style.display='none'; Codehighlighter1_731_776_Open_Image.style.display='inline'; Codehighlighter1_731_776_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_731_776_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_731_776_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">44</span><span style="color: #000000"><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;times[a[i]]</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">45</span><span style="color: #000000"><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 /></span><span style="color: #008080">46</span><span style="color: #000000"><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 /></span><span style="color: #008080">47</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(temp</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">&gt;</span><span style="color: #000000">'</span><span style="color: #000000">)<br /></span><span style="color: #008080">48</span><span style="color: #000000"><img id="Codehighlighter1_819_1042_Open_Image" onclick="this.style.display='none'; Codehighlighter1_819_1042_Open_Text.style.display='none'; Codehighlighter1_819_1042_Closed_Image.style.display='inline'; Codehighlighter1_819_1042_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_819_1042_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_819_1042_Closed_Text.style.display='none'; Codehighlighter1_819_1042_Open_Image.style.display='inline'; Codehighlighter1_819_1042_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_819_1042_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_819_1042_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">49</span><span style="color: #000000"><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;total</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">50</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">p;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">51</span><span style="color: #000000"><img id="Codehighlighter1_890_935_Open_Image" onclick="this.style.display='none'; Codehighlighter1_890_935_Open_Text.style.display='none'; Codehighlighter1_890_935_Closed_Image.style.display='inline'; Codehighlighter1_890_935_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_890_935_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_890_935_Closed_Text.style.display='none'; Codehighlighter1_890_935_Open_Image.style.display='inline'; Codehighlighter1_890_935_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_890_935_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_890_935_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">52</span><span style="color: #000000"><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;times[a[i]]</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">53</span><span style="color: #000000"><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 /></span><span style="color: #008080">54</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">p;&nbsp;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">2</span><span style="color: #000000">*</span><span style="color: #000000">p;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">55</span><span style="color: #000000"><img id="Codehighlighter1_987_1032_Open_Image" onclick="this.style.display='none'; Codehighlighter1_987_1032_Open_Text.style.display='none'; Codehighlighter1_987_1032_Closed_Image.style.display='inline'; Codehighlighter1_987_1032_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_987_1032_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_987_1032_Closed_Text.style.display='none'; Codehighlighter1_987_1032_Open_Image.style.display='inline'; Codehighlighter1_987_1032_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_987_1032_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_987_1032_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">56</span><span style="color: #000000"><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;times[a[i]]</span><span style="color: #000000">--</span><span style="color: #000000">;<br /></span><span style="color: #008080">57</span><span style="color: #000000"><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 /></span><span style="color: #008080">58</span><span style="color: #000000"><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 /></span><span style="color: #008080">59</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">60</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;cnt</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">,s</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">61</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">62</span><span style="color: #000000"><img id="Codehighlighter1_1103_1255_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1103_1255_Open_Text.style.display='none'; Codehighlighter1_1103_1255_Closed_Image.style.display='inline'; Codehighlighter1_1103_1255_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1103_1255_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1103_1255_Closed_Text.style.display='none'; Codehighlighter1_1103_1255_Open_Image.style.display='inline'; Codehighlighter1_1103_1255_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_1103_1255_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1103_1255_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">63</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(r[i]</span><span style="color: #000000">!=</span><span style="color: #000000">1</span><span style="color: #000000">)<br /></span><span style="color: #008080">64</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(times[i]</span><span style="color: #000000">==</span><span style="color: #000000">total&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;times[i]</span><span style="color: #000000">==-</span><span style="color: #000000">total)<br /></span><span style="color: #008080">65</span><span style="color: #000000"><img id="Codehighlighter1_1191_1249_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1191_1249_Open_Text.style.display='none'; Codehighlighter1_1191_1249_Closed_Image.style.display='inline'; Codehighlighter1_1191_1249_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1191_1249_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1191_1249_Closed_Text.style.display='none'; Codehighlighter1_1191_1249_Open_Image.style.display='inline'; Codehighlighter1_1191_1249_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_1191_1249_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1191_1249_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">66</span><span style="color: #000000"><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;cnt</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">67</span><span style="color: #000000"><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;s</span><span style="color: #000000">=</span><span style="color: #000000">i;<br /></span><span style="color: #008080">68</span><span style="color: #000000"><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 /></span><span style="color: #008080">69</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">70</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(cnt</span><span style="color: #000000">==</span><span style="color: #000000">1</span><span style="color: #000000">)&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;s&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /></span><span style="color: #008080">71</span><span style="color: #000000"><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;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /></span><span style="color: #008080">72</span><span style="color: #000000"><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 /></span><span style="color: #008080">73</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">74</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div><br /><img src ="http://www.cppblog.com/wyh123/aggbug/152874.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wyh123/" target="_blank">wyh</a> 2011-08-09 17:08 <a href="http://www.cppblog.com/wyh123/archive/2011/08/09/152874.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>poj 1015（DP）</title><link>http://www.cppblog.com/wyh123/archive/2011/08/09/152857.html</link><dc:creator>wyh</dc:creator><author>wyh</author><pubDate>Tue, 09 Aug 2011 06:47:00 GMT</pubDate><guid>http://www.cppblog.com/wyh123/archive/2011/08/09/152857.html</guid><wfw:comment>http://www.cppblog.com/wyh123/comments/152857.html</wfw:comment><comments>http://www.cppblog.com/wyh123/archive/2011/08/09/152857.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wyh123/comments/commentRss/152857.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wyh123/services/trackbacks/152857.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 题目大意：&nbsp;在遥远的国家佛罗布尼亚，嫌犯是否有罪，须由陪审团决定。陪审团是由法官从公众中挑选的。先随机挑选n 个人作为陪审团的候选人，然后再从这n 个人中选m 人组成陪审团。选m 人的办法是：控方和辩方会根据对候选人的喜欢程度，给所有候选人打分，分值从0 到20。为了公平起见，法官选出陪审团的原则是：选出的m 个人，必须满足辩方总分和控方总分的差的绝对值最小。如果有多种选择方案的辩方总分...&nbsp;&nbsp;<a href='http://www.cppblog.com/wyh123/archive/2011/08/09/152857.html'>阅读全文</a><img src ="http://www.cppblog.com/wyh123/aggbug/152857.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wyh123/" target="_blank">wyh</a> 2011-08-09 14:47 <a href="http://www.cppblog.com/wyh123/archive/2011/08/09/152857.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>poj 1971（数学题）</title><link>http://www.cppblog.com/wyh123/archive/2011/08/09/152826.html</link><dc:creator>wyh</dc:creator><author>wyh</author><pubDate>Mon, 08 Aug 2011 16:05:00 GMT</pubDate><guid>http://www.cppblog.com/wyh123/archive/2011/08/09/152826.html</guid><wfw:comment>http://www.cppblog.com/wyh123/comments/152826.html</wfw:comment><comments>http://www.cppblog.com/wyh123/archive/2011/08/09/152826.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wyh123/comments/commentRss/152826.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wyh123/services/trackbacks/152826.html</trackback:ping><description><![CDATA[题目大意：给出n个点，求出这n个点能够组成平行四边形的个数。<br /><br />解题思路：1）平行四边形的对角线的中点一定相交。&lt;=&gt;&nbsp; 如果有两条不同线段的中点相交，就是一个平行四边形<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2）利用点坐标求出中点的集合，离散化后求出同个中点的出现的个数k。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3）对于每一个k ，利用组合公式C(k,2)的答案就是平行四边行的个数<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 />--><span style="color: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cmath</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><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 /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">10</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;Node<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img id="Codehighlighter1_148_162_Open_Image" onclick="this.style.display='none'; Codehighlighter1_148_162_Open_Text.style.display='none'; Codehighlighter1_148_162_Closed_Image.style.display='inline'; Codehighlighter1_148_162_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_148_162_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_148_162_Closed_Text.style.display='none'; Codehighlighter1_148_162_Open_Image.style.display='inline'; Codehighlighter1_148_162_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_148_162_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_148_162_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">12</span><span style="color: #000000"><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;x,y;<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000">node[</span><span style="color: #000000">1010</span><span style="color: #000000">],mid[</span><span style="color: #000000">1001000</span><span style="color: #000000">];<br /></span><span style="color: #008080">14</span><span style="color: #000000"><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;T,n,summ,num;<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">16</span><span style="color: #000000"><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;cmp(</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;Node&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">a,</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;Node&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">b)<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img id="Codehighlighter1_244_301_Open_Image" onclick="this.style.display='none'; Codehighlighter1_244_301_Open_Text.style.display='none'; Codehighlighter1_244_301_Closed_Image.style.display='inline'; Codehighlighter1_244_301_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_244_301_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_244_301_Closed_Text.style.display='none'; Codehighlighter1_244_301_Open_Image.style.display='inline'; Codehighlighter1_244_301_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_244_301_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_244_301_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(a.x</span><span style="color: #000000">==</span><span style="color: #000000">b.x)&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;a.y</span><span style="color: #000000">&lt;</span><span style="color: #000000">b.y;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;a.x</span><span style="color: #000000">&lt;</span><span style="color: #000000">b.x;<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">20</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">21</span><span style="color: #000000"><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;count(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;k)<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img id="Codehighlighter1_321_394_Open_Image" onclick="this.style.display='none'; Codehighlighter1_321_394_Open_Text.style.display='none'; Codehighlighter1_321_394_Closed_Image.style.display='inline'; Codehighlighter1_321_394_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_321_394_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_321_394_Closed_Text.style.display='none'; Codehighlighter1_321_394_Open_Image.style.display='inline'; Codehighlighter1_321_394_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_321_394_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_321_394_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(k</span><span style="color: #000000">==</span><span style="color: #000000">1</span><span style="color: #000000">)&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">24</span><span style="color: #000000"><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 /></span><span style="color: #008080">25</span><span style="color: #000000"><img id="Codehighlighter1_360_392_Open_Image" onclick="this.style.display='none'; Codehighlighter1_360_392_Open_Text.style.display='none'; Codehighlighter1_360_392_Closed_Image.style.display='inline'; Codehighlighter1_360_392_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_360_392_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_360_392_Closed_Text.style.display='none'; Codehighlighter1_360_392_Open_Image.style.display='inline'; Codehighlighter1_360_392_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_360_392_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_360_392_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;k</span><span style="color: #000000">*</span><span style="color: #000000">(k</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">2</span><span style="color: #000000">;<br /></span><span style="color: #008080">27</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">28</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">29</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">30</span><span style="color: #000000"><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 /></span><span style="color: #008080">31</span><span style="color: #000000"><img id="Codehighlighter1_408_1234_Open_Image" onclick="this.style.display='none'; Codehighlighter1_408_1234_Open_Text.style.display='none'; Codehighlighter1_408_1234_Closed_Image.style.display='inline'; Codehighlighter1_408_1234_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_408_1234_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_408_1234_Closed_Text.style.display='none'; Codehighlighter1_408_1234_Open_Image.style.display='inline'; Codehighlighter1_408_1234_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_408_1234_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_408_1234_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;T;<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;(T</span><span style="color: #000000">--</span><span style="color: #000000">)<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img id="Codehighlighter1_444_1218_Open_Image" onclick="this.style.display='none'; Codehighlighter1_444_1218_Open_Text.style.display='none'; Codehighlighter1_444_1218_Closed_Image.style.display='inline'; Codehighlighter1_444_1218_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_444_1218_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_444_1218_Closed_Text.style.display='none'; Codehighlighter1_444_1218_Open_Image.style.display='inline'; Codehighlighter1_444_1218_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_444_1218_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_444_1218_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">35</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;summ</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">36</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">n);<br /></span><span style="color: #008080">37</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">38</span><span style="color: #000000"><img id="Codehighlighter1_529_596_Open_Image" onclick="this.style.display='none'; Codehighlighter1_529_596_Open_Text.style.display='none'; Codehighlighter1_529_596_Closed_Image.style.display='inline'; Codehighlighter1_529_596_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_529_596_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_529_596_Closed_Text.style.display='none'; Codehighlighter1_529_596_Open_Image.style.display='inline'; Codehighlighter1_529_596_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;</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_529_596_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_529_596_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">39</span><span style="color: #000000"><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;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">(node[i].x),</span><span style="color: #000000">&amp;</span><span style="color: #000000">(node[i].y));<br /></span><span style="color: #008080">40</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">41</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num</span><span style="color: #000000">=-</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">42</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">43</span><span style="color: #000000"><img id="Codehighlighter1_655_861_Open_Image" onclick="this.style.display='none'; Codehighlighter1_655_861_Open_Text.style.display='none'; Codehighlighter1_655_861_Closed_Image.style.display='inline'; Codehighlighter1_655_861_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_655_861_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_655_861_Closed_Text.style.display='none'; Codehighlighter1_655_861_Open_Image.style.display='inline'; Codehighlighter1_655_861_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_655_861_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_655_861_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">44</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j</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">;&nbsp;j</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n;&nbsp;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">45</span><span style="color: #000000"><img id="Codehighlighter1_710_851_Open_Image" onclick="this.style.display='none'; Codehighlighter1_710_851_Open_Text.style.display='none'; Codehighlighter1_710_851_Closed_Image.style.display='inline'; Codehighlighter1_710_851_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_710_851_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_710_851_Closed_Text.style.display='none'; Codehighlighter1_710_851_Open_Image.style.display='inline'; Codehighlighter1_710_851_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;</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_710_851_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_710_851_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">46</span><span style="color: #000000"><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;num</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">47</span><span style="color: #000000"><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;mid[num].x</span><span style="color: #000000">=</span><span style="color: #000000">node[i].x</span><span style="color: #000000">+</span><span style="color: #000000">node[j].x;<br /></span><span style="color: #008080">48</span><span style="color: #000000"><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;mid[num].y</span><span style="color: #000000">=</span><span style="color: #000000">node[i].y</span><span style="color: #000000">+</span><span style="color: #000000">node[j].y;<br /></span><span style="color: #008080">49</span><span style="color: #000000"><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;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">50</span><span style="color: #000000"><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 /></span><span style="color: #008080">51</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort(mid,mid</span><span style="color: #000000">+</span><span style="color: #000000">num</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">,cmp);<br /></span><span style="color: #008080">52</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Node&nbsp;temp;<br /></span><span style="color: #008080">53</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;k;<br /></span><span style="color: #008080">54</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">55</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">num;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">56</span><span style="color: #000000"><img id="Codehighlighter1_986_1181_Open_Image" onclick="this.style.display='none'; Codehighlighter1_986_1181_Open_Text.style.display='none'; Codehighlighter1_986_1181_Closed_Image.style.display='inline'; Codehighlighter1_986_1181_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_986_1181_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_986_1181_Closed_Text.style.display='none'; Codehighlighter1_986_1181_Open_Image.style.display='inline'; Codehighlighter1_986_1181_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_986_1181_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_986_1181_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">57</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(mid[i].x</span><span style="color: #000000">==</span><span style="color: #000000">mid[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">].x&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;mid[i].y</span><span style="color: #000000">==</span><span style="color: #000000">mid[i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">].y)&nbsp;k</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">58</span><span style="color: #000000"><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 /></span><span style="color: #008080">59</span><span style="color: #000000"><img id="Codehighlighter1_1092_1171_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1092_1171_Open_Text.style.display='none'; Codehighlighter1_1092_1171_Closed_Image.style.display='inline'; Codehighlighter1_1092_1171_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1092_1171_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1092_1171_Closed_Text.style.display='none'; Codehighlighter1_1092_1171_Open_Image.style.display='inline'; Codehighlighter1_1092_1171_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_1092_1171_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1092_1171_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">60</span><span style="color: #000000"><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;summ</span><span style="color: #000000">+=</span><span style="color: #000000">count(k);<br /></span><span style="color: #008080">61</span><span style="color: #000000"><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;k</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">62</span><span style="color: #000000"><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 /></span><span style="color: #008080">63</span><span style="color: #000000"><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 /></span><span style="color: #008080">64</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;summ&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /></span><span style="color: #008080">65</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">66</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">67</span><span style="color: #000000"><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 /></span><span style="color: #008080">68</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">69</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div><br /><img src ="http://www.cppblog.com/wyh123/aggbug/152826.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wyh123/" target="_blank">wyh</a> 2011-08-09 00:05 <a href="http://www.cppblog.com/wyh123/archive/2011/08/09/152826.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDOJ 3823(素数)</title><link>http://www.cppblog.com/wyh123/archive/2011/08/07/152700.html</link><dc:creator>wyh</dc:creator><author>wyh</author><pubDate>Sun, 07 Aug 2011 01:39:00 GMT</pubDate><guid>http://www.cppblog.com/wyh123/archive/2011/08/07/152700.html</guid><wfw:comment>http://www.cppblog.com/wyh123/comments/152700.html</wfw:comment><comments>http://www.cppblog.com/wyh123/archive/2011/08/07/152700.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wyh123/comments/commentRss/152700.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wyh123/services/trackbacks/152700.html</trackback:ping><description><![CDATA[题目大意：给出两个数，a,b（均小于等于150），让他们加上一个数使得他们得到的数是素数，并且两个素数相邻，如果存在这样的数，则输出，否则，输出-1<br /><br /><br />解题思路：1）a,b均小于或等于150，那么加上后素数的差值绝对小于150<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2）存在相邻素数小于150的素数范围感觉应该不大...暴力筛一下，看到哪里的间隔会大于150；<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3）开一个数组，dis[i][j]，表示两个差距为i的两个相邻素数中，较小的那个素数是dis[i]中第j小的<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4）接下来就是枚举了，先算差值m，然后套到dis[m]中求不比给定的数a,b小的最小素数，有就输出，没有就输出-1<br /><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;第一次用vector&nbsp;~~~&nbsp; <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 />--><span style="color: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdlib</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">vector</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cmath</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><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 /></span><span style="color: #008080">10</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">11</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;pri[</span><span style="color: #000000">20000000</span><span style="color: #000000">];<br /></span><span style="color: #008080">12</span><span style="color: #000000"><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;pr[</span><span style="color: #000000">1500000</span><span style="color: #000000">];<br /></span><span style="color: #008080">13</span><span style="color: #000000"><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;summ,T,a,b,m,maxx;<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;f;<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />vector</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">int</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;dis[</span><span style="color: #000000">150</span><span style="color: #000000">];<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">17</span><span style="color: #000000"><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;prime()<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img id="Codehighlighter1_259_505_Open_Image" onclick="this.style.display='none'; Codehighlighter1_259_505_Open_Text.style.display='none'; Codehighlighter1_259_505_Closed_Image.style.display='inline'; Codehighlighter1_259_505_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_259_505_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_259_505_Closed_Text.style.display='none'; Codehighlighter1_259_505_Open_Image.style.display='inline'; Codehighlighter1_259_505_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_259_505_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_259_505_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;memset(pri,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(pri));<br /></span><span style="color: #008080">20</span><span style="color: #000000"><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">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">2</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">20000000</span><span style="color: #000000">;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img id="Codehighlighter1_319_410_Open_Image" onclick="this.style.display='none'; Codehighlighter1_319_410_Open_Text.style.display='none'; Codehighlighter1_319_410_Closed_Image.style.display='inline'; Codehighlighter1_319_410_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_319_410_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_319_410_Closed_Text.style.display='none'; Codehighlighter1_319_410_Open_Image.style.display='inline'; Codehighlighter1_319_410_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_319_410_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_319_410_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(pri[i]</span><span style="color: #000000">==</span><span style="color: #0000ff">true</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">continue</span><span style="color: #000000">;<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">=</span><span style="color: #000000">i</span><span style="color: #000000">+</span><span style="color: #000000">i;j</span><span style="color: #000000">&lt;</span><span style="color: #000000">20000000</span><span style="color: #000000">;j</span><span style="color: #000000">+=</span><span style="color: #000000">i)<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img id="Codehighlighter1_385_407_Open_Image" onclick="this.style.display='none'; Codehighlighter1_385_407_Open_Text.style.display='none'; Codehighlighter1_385_407_Closed_Image.style.display='inline'; Codehighlighter1_385_407_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_385_407_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_385_407_Closed_Text.style.display='none'; Codehighlighter1_385_407_Open_Image.style.display='inline'; Codehighlighter1_385_407_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_385_407_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_385_407_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pri[j]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">27</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">28</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;summ</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">29</span><span style="color: #000000"><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">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">2</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">20000000</span><span style="color: #000000">;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img id="Codehighlighter1_451_503_Open_Image" onclick="this.style.display='none'; Codehighlighter1_451_503_Open_Text.style.display='none'; Codehighlighter1_451_503_Closed_Image.style.display='inline'; Codehighlighter1_451_503_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_451_503_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_451_503_Closed_Text.style.display='none'; Codehighlighter1_451_503_Open_Image.style.display='inline'; Codehighlighter1_451_503_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_451_503_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_451_503_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">31</span><span style="color: #000000"><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">(pri[i])&nbsp;</span><span style="color: #0000ff">continue</span><span style="color: #000000">;<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pr[summ]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;i;<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;summ</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">35</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">36</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">37</span><span style="color: #000000"><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 /></span><span style="color: #008080">38</span><span style="color: #000000"><img id="Codehighlighter1_519_954_Open_Image" onclick="this.style.display='none'; Codehighlighter1_519_954_Open_Text.style.display='none'; Codehighlighter1_519_954_Closed_Image.style.display='inline'; Codehighlighter1_519_954_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_519_954_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_519_954_Closed_Text.style.display='none'; Codehighlighter1_519_954_Open_Image.style.display='inline'; Codehighlighter1_519_954_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_519_954_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_519_954_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">39</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">40</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;prime();<br /></span><span style="color: #008080">41</span><span style="color: #000000"><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">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">summ</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">42</span><span style="color: #000000"><img id="Codehighlighter1_560_636_Open_Image" onclick="this.style.display='none'; Codehighlighter1_560_636_Open_Text.style.display='none'; Codehighlighter1_560_636_Closed_Image.style.display='inline'; Codehighlighter1_560_636_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_560_636_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_560_636_Closed_Text.style.display='none'; Codehighlighter1_560_636_Open_Image.style.display='inline'; Codehighlighter1_560_636_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_560_636_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_560_636_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">43</span><span style="color: #000000"><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">(pr[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">pr[i]</span><span style="color: #000000">&gt;</span><span style="color: #000000">149</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">continue</span><span style="color: #000000">;<br /></span><span style="color: #008080">44</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dis[pr[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">pr[i]].push_back(pr[i]);<br /></span><span style="color: #008080">45</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">46</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;T;<br /></span><span style="color: #008080">47</span><span style="color: #000000"><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">(</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">T;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">48</span><span style="color: #000000"><img id="Codehighlighter1_673_952_Open_Image" onclick="this.style.display='none'; Codehighlighter1_673_952_Open_Text.style.display='none'; Codehighlighter1_673_952_Closed_Image.style.display='inline'; Codehighlighter1_673_952_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_673_952_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_673_952_Closed_Text.style.display='none'; Codehighlighter1_673_952_Open_Image.style.display='inline'; Codehighlighter1_673_952_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_673_952_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_673_952_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">49</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;a&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;b;<br /></span><span style="color: #008080">50</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m</span><span style="color: #000000">=</span><span style="color: #000000">abs(a</span><span style="color: #000000">-</span><span style="color: #000000">b);<br /></span><span style="color: #008080">51</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(a</span><span style="color: #000000">&gt;</span><span style="color: #000000">b)&nbsp;maxx</span><span style="color: #000000">=</span><span style="color: #000000">b;<br /></span><span style="color: #008080">52</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;maxx</span><span style="color: #000000">=</span><span style="color: #000000">a;<br /></span><span style="color: #008080">53</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f</span><span style="color: #000000">=</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br /></span><span style="color: #008080">54</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">Case&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">;<br /></span><span style="color: #008080">55</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;j</span><span style="color: #000000">&lt;</span><span style="color: #000000">dis[m].size();j</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">56</span><span style="color: #000000"><img id="Codehighlighter1_821_913_Open_Image" onclick="this.style.display='none'; Codehighlighter1_821_913_Open_Text.style.display='none'; Codehighlighter1_821_913_Closed_Image.style.display='inline'; Codehighlighter1_821_913_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_821_913_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_821_913_Closed_Text.style.display='none'; Codehighlighter1_821_913_Open_Image.style.display='inline'; Codehighlighter1_821_913_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_821_913_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_821_913_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">57</span><span style="color: #000000"><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">(dis[m][j]</span><span style="color: #000000">&lt;</span><span style="color: #000000">maxx)&nbsp;</span><span style="color: #0000ff">continue</span><span style="color: #000000">;<br /></span><span style="color: #008080">58</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;dis[m][j]</span><span style="color: #000000">-</span><span style="color: #000000">maxx</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /></span><span style="color: #008080">59</span><span style="color: #000000"><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;f</span><span style="color: #000000">=</span><span style="color: #0000ff">false</span><span style="color: #000000">;<br /></span><span style="color: #008080">60</span><span style="color: #000000"><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">break</span><span style="color: #000000">;<br /></span><span style="color: #008080">61</span><span style="color: #000000"><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 /></span><span style="color: #008080">62</span><span style="color: #000000"><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">(f</span><span style="color: #000000">==</span><span style="color: #0000ff">true</span><span style="color: #000000">)&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">-1</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /></span><span style="color: #008080">63</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">64</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">65</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div><br /><br /><img src ="http://www.cppblog.com/wyh123/aggbug/152700.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wyh123/" target="_blank">wyh</a> 2011-08-07 09:39 <a href="http://www.cppblog.com/wyh123/archive/2011/08/07/152700.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDOJ 3826(素数)</title><link>http://www.cppblog.com/wyh123/archive/2011/08/07/152685.html</link><dc:creator>wyh</dc:creator><author>wyh</author><pubDate>Sat, 06 Aug 2011 16:04:00 GMT</pubDate><guid>http://www.cppblog.com/wyh123/archive/2011/08/07/152685.html</guid><wfw:comment>http://www.cppblog.com/wyh123/comments/152685.html</wfw:comment><comments>http://www.cppblog.com/wyh123/archive/2011/08/07/152685.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wyh123/comments/commentRss/152685.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wyh123/services/trackbacks/152685.html</trackback:ping><description><![CDATA[题目大意：给出一个数，判断其是否有含有平方因子<br /><br />解题思路：1）10^18这是一个很大的数据，暴力是绝对不可行的。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2）如果其含有平方因子，则有n=a^2*b，这里的n&lt;=10^18，所以a,b中必定有一个是小于10^6~。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3）筛10^6以内的素数，然后用n去除以这些质数的平方，如果能除，返回NO，否则，则看是否能够除以这个素数。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4）10^6以内的素数除光了，如果是1返回YES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5）剩下的也就只有三种可能，素数，素数的平方和，或者两个素数的积。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; （证明：首先，剩下的肯定是比10^6大的素数，这个是毫无疑问的，而且这些素数因子的个数不可能超过3个，所以只有以上三种情况）<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6）是两个素数的积返回NO，其他的YES<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 />--><span style="color: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdlib</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cmath</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><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 /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><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;prime[</span><span style="color: #000000">80000</span><span style="color: #000000">];<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;p[</span><span style="color: #000000">1000002</span><span style="color: #000000">];<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">12</span><span style="color: #000000"><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;PRIME(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;M)<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img id="Codehighlighter1_172_633_Open_Image" onclick="this.style.display='none'; Codehighlighter1_172_633_Open_Text.style.display='none'; Codehighlighter1_172_633_Closed_Image.style.display='inline'; Codehighlighter1_172_633_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_172_633_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_172_633_Closed_Text.style.display='none'; Codehighlighter1_172_633_Open_Image.style.display='inline'; Codehighlighter1_172_633_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_172_633_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_172_633_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">14</span><span style="color: #000000"><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,i2,k;<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img id="Codehighlighter1_212_222_Open_Image" onclick="this.style.display='none'; Codehighlighter1_212_222_Open_Text.style.display='none'; Codehighlighter1_212_222_Closed_Image.style.display='inline'; Codehighlighter1_212_222_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_212_222_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_212_222_Closed_Text.style.display='none'; Codehighlighter1_212_222_Open_Image.style.display='inline'; Codehighlighter1_212_222_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&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">M;i</span><span style="color: #000000">+=</span><span style="color: #000000">2</span><span style="color: #000000">)</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_212_222_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_212_222_Open_Text"><span style="color: #000000">{&nbsp;p[i]</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">16</span><span style="color: #000000"><img id="Codehighlighter1_246_256_Open_Image" onclick="this.style.display='none'; Codehighlighter1_246_256_Open_Text.style.display='none'; Codehighlighter1_246_256_Closed_Image.style.display='inline'; Codehighlighter1_246_256_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_246_256_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_246_256_Closed_Text.style.display='none'; Codehighlighter1_246_256_Open_Image.style.display='inline'; Codehighlighter1_246_256_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&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">M;i</span><span style="color: #000000">+=</span><span style="color: #000000">2</span><span style="color: #000000">)</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_246_256_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_246_256_Open_Text"><span style="color: #000000">{&nbsp;p[i]</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">17</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;p[</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">;<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;p[</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">19</span><span style="color: #000000"><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">3</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">1000</span><span style="color: #000000">;i</span><span style="color: #000000">+=</span><span style="color: #000000">2</span><span style="color: #000000">)<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img id="Codehighlighter1_312_516_Open_Image" onclick="this.style.display='none'; Codehighlighter1_312_516_Open_Text.style.display='none'; Codehighlighter1_312_516_Closed_Image.style.display='inline'; Codehighlighter1_312_516_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_312_516_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_312_516_Closed_Text.style.display='none'; Codehighlighter1_312_516_Open_Image.style.display='inline'; Codehighlighter1_312_516_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_312_516_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_312_516_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">21</span><span style="color: #000000"><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">(p[i]</span><span style="color: #000000">==</span><span style="color: #000000">1</span><span style="color: #000000">)<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img id="Codehighlighter1_344_509_Open_Image" onclick="this.style.display='none'; Codehighlighter1_344_509_Open_Text.style.display='none'; Codehighlighter1_344_509_Closed_Image.style.display='inline'; Codehighlighter1_344_509_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_344_509_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_344_509_Closed_Text.style.display='none'; Codehighlighter1_344_509_Open_Image.style.display='inline'; Codehighlighter1_344_509_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;</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_344_509_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_344_509_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">23</span><span style="color: #000000"><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;i2</span><span style="color: #000000">=</span><span style="color: #000000">i</span><span style="color: #000000">+</span><span style="color: #000000">i;<br /></span><span style="color: #008080">24</span><span style="color: #000000"><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;k</span><span style="color: #000000">=</span><span style="color: #000000">i</span><span style="color: #000000">*</span><span style="color: #000000">i;<br /></span><span style="color: #008080">25</span><span style="color: #000000"><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;</span><span style="color: #0000ff">while</span><span style="color: #000000">(k</span><span style="color: #000000">&lt;=</span><span style="color: #000000">M)<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img id="Codehighlighter1_429_496_Open_Image" onclick="this.style.display='none'; Codehighlighter1_429_496_Open_Text.style.display='none'; Codehighlighter1_429_496_Closed_Image.style.display='inline'; Codehighlighter1_429_496_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_429_496_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_429_496_Closed_Text.style.display='none'; Codehighlighter1_429_496_Open_Image.style.display='inline'; Codehighlighter1_429_496_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;</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_429_496_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_429_496_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">27</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p[k]</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">28</span><span style="color: #000000"><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;k</span><span style="color: #000000">+=</span><span style="color: #000000">i2;<br /></span><span style="color: #008080">29</span><span style="color: #000000"><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;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">30</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">31</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">32</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prime[</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">2</span><span style="color: #000000">;<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  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">3</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">M;i</span><span style="color: #000000">+=</span><span style="color: #000000">2</span><span style="color: #000000">)<br /></span><span style="color: #008080">35</span><span style="color: #000000"><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">(p[i])&nbsp;&nbsp;&nbsp;prime[</span><span style="color: #000000">++</span><span style="color: #000000">k]</span><span style="color: #000000">=</span><span style="color: #000000">i;<br /></span><span style="color: #008080">36</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prime[</span><span style="color: #000000">0</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">k;<br /></span><span style="color: #008080">37</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;;<br /></span><span style="color: #008080">38</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">39</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">40</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">41</span><span style="color: #000000"><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;Int(</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;n)<br /></span><span style="color: #008080">42</span><span style="color: #000000"><img id="Codehighlighter1_658_1114_Open_Image" onclick="this.style.display='none'; Codehighlighter1_658_1114_Open_Text.style.display='none'; Codehighlighter1_658_1114_Closed_Image.style.display='inline'; Codehighlighter1_658_1114_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_658_1114_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_658_1114_Closed_Text.style.display='none'; Codehighlighter1_658_1114_Open_Image.style.display='inline'; Codehighlighter1_658_1114_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_658_1114_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_658_1114_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">43</span><span style="color: #000000"><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,s,k;<br /></span><span style="color: #008080">44</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;d,e;<br /></span><span style="color: #008080">45</span><span style="color: #000000"><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">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">46</span><span style="color: #000000"><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">prime[</span><span style="color: #000000">0</span><span style="color: #000000">];i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">47</span><span style="color: #000000"><img id="Codehighlighter1_736_943_Open_Image" onclick="this.style.display='none'; Codehighlighter1_736_943_Open_Text.style.display='none'; Codehighlighter1_736_943_Closed_Image.style.display='inline'; Codehighlighter1_736_943_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_736_943_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_736_943_Closed_Text.style.display='none'; Codehighlighter1_736_943_Open_Image.style.display='inline'; Codehighlighter1_736_943_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_736_943_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_736_943_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">48</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">49</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(n</span><span style="color: #000000">%</span><span style="color: #000000">prime[i]</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)<br /></span><span style="color: #008080">50</span><span style="color: #000000"><img id="Codehighlighter1_787_842_Open_Image" onclick="this.style.display='none'; Codehighlighter1_787_842_Open_Text.style.display='none'; Codehighlighter1_787_842_Closed_Image.style.display='inline'; Codehighlighter1_787_842_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_787_842_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_787_842_Closed_Text.style.display='none'; Codehighlighter1_787_842_Open_Image.style.display='inline'; Codehighlighter1_787_842_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;</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_787_842_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_787_842_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">51</span><span style="color: #000000"><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;s</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">52</span><span style="color: #000000"><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;n</span><span style="color: #000000">/=</span><span style="color: #000000">prime[i];<br /></span><span style="color: #008080">53</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">54</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">55</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(s</span><span style="color: #000000">&gt;</span><span style="color: #000000">1</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">56</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&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">)&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">57</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&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">prime[i]</span><span style="color: #000000">&lt;</span><span style="color: #000000">prime[i])&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">58</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">59</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d</span><span style="color: #000000">=</span><span style="color: #000000">(</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">)sqrt((</span><span style="color: #0000ff">double</span><span style="color: #000000">)n);<br /></span><span style="color: #008080">60</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d</span><span style="color: #000000">--</span><span style="color: #000000">;<br /></span><span style="color: #008080">61</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">1</span><span style="color: #000000">)<br /></span><span style="color: #008080">62</span><span style="color: #000000"><img id="Codehighlighter1_1009_1097_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1009_1097_Open_Text.style.display='none'; Codehighlighter1_1009_1097_Closed_Image.style.display='inline'; Codehighlighter1_1009_1097_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1009_1097_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1009_1097_Closed_Text.style.display='none'; Codehighlighter1_1009_1097_Open_Image.style.display='inline'; Codehighlighter1_1009_1097_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&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_1009_1097_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1009_1097_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">63</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e</span><span style="color: #000000">=</span><span style="color: #000000">d</span><span style="color: #000000">*</span><span style="color: #000000">d;<br /></span><span style="color: #008080">64</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(e</span><span style="color: #000000">==</span><span style="color: #000000">n)</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">65</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(e</span><span style="color: #000000">&gt;</span><span style="color: #000000">n)</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /></span><span style="color: #008080">66</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">67</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">68</span><span style="color: #000000"><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">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">69</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">70</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">71</span><span style="color: #000000"><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 /></span><span style="color: #008080">72</span><span style="color: #000000"><img id="Codehighlighter1_1129_1374_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1129_1374_Open_Text.style.display='none'; Codehighlighter1_1129_1374_Closed_Image.style.display='inline'; Codehighlighter1_1129_1374_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_1129_1374_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1129_1374_Closed_Text.style.display='none'; Codehighlighter1_1129_1374_Open_Image.style.display='inline'; Codehighlighter1_1129_1374_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.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_1129_1374_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1129_1374_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">73</span><span style="color: #000000"><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;T,i,k;<br /></span><span style="color: #008080">74</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;N,d;<br /></span><span style="color: #008080">75</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;PRIME(</span><span style="color: #000000">1000000</span><span style="color: #000000">);<br /></span><span style="color: #008080">76</span><span style="color: #000000"><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">T);<br /></span><span style="color: #008080">77</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&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">T;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">78</span><span style="color: #000000"><img id="Codehighlighter1_1226_1358_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1226_1358_Open_Text.style.display='none'; Codehighlighter1_1226_1358_Closed_Image.style.display='inline'; Codehighlighter1_1226_1358_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1226_1358_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1226_1358_Closed_Text.style.display='none'; Codehighlighter1_1226_1358_Open_Image.style.display='inline'; Codehighlighter1_1226_1358_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_1226_1358_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1226_1358_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">79</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%I64d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">N);<br /></span><span style="color: #008080">80</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k</span><span style="color: #000000">=</span><span style="color: #000000">Int(N);<br /></span><span style="color: #008080">81</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(k</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">Case&nbsp;%d:&nbsp;Yes\n</span><span style="color: #000000">"</span><span style="color: #000000">,i);<br /></span><span style="color: #008080">82</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">Case&nbsp;%d:&nbsp;No\n</span><span style="color: #000000">"</span><span style="color: #000000">,i);<br /></span><span style="color: #008080">83</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">84</span><span style="color: #000000"><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 /></span><span style="color: #008080">85</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">86</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">87</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div><br /><img src ="http://www.cppblog.com/wyh123/aggbug/152685.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wyh123/" target="_blank">wyh</a> 2011-08-07 00:04 <a href="http://www.cppblog.com/wyh123/archive/2011/08/07/152685.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>poj 1150（求末尾非0数字）</title><link>http://www.cppblog.com/wyh123/archive/2011/08/06/152621.html</link><dc:creator>wyh</dc:creator><author>wyh</author><pubDate>Sat, 06 Aug 2011 02:34:00 GMT</pubDate><guid>http://www.cppblog.com/wyh123/archive/2011/08/06/152621.html</guid><wfw:comment>http://www.cppblog.com/wyh123/comments/152621.html</wfw:comment><comments>http://www.cppblog.com/wyh123/archive/2011/08/06/152621.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wyh123/comments/commentRss/152621.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wyh123/services/trackbacks/152621.html</trackback:ping><description><![CDATA[<p>题目大意：给出n,m，求P(n,m)最后一位末尾非0数字</p><br /><br />解题思路：已知P(n,m)=n!/(n-m)! 由于n,m&lt;=200000000 
<p><br />这里利用到数论中求n！最尾非零数的非零数字的方法（下列数字2，5，1，3，7，9均表示数的个位）：</p>
<p><br />1)因为2，5组成10，故可以删去能配对的2,5，记录下剩余2的个数；（2显然多于5）</p>
<p><br />2)每一个数，在mod2,5之后只有1,3,7,9四种结果，1可以忽略不计，故我们只需要统计3,7,9的个数</p>
<p>统计方法如下：f(n,x)和g(n,x)中的n代表n!中的n，x取3，7，9中的一个</p>
<p>有：f(n,x)=f(n/2,x)+g(n,x)</p>
<p>g(n,x)=n/10+g(n/5,x)+k</p>
<p>if (n&gt;=x) k=1; else k=0;<br /><br />这里面是将阶层中的项分为奇数项和偶数项，其中先对奇数项求3,7或9的个数。这里面，很容易知道，每10个数里面一定有一个以3,7或者9结尾的数，而且当n&gt;=3，7或9时，必存在一个3,7,9（当n=16时，前10个数有一个以3结尾，而13也是以上结尾，所以此处有两个3，不是n/10）；另外由于要约去成对的2和5那么无可避免的会出现其他的数字（2,3,7,9,1,其中2另外考虑），所以此处要加上g(n/5,x)。对于偶数项，不难发现当偶数项除以2（这里的2由于有另外统计，所以除后对结果没有影响）后就变成了n！的前一半（如10！有1，2，3，4，5，6，7，8，9，10，偶数项除以而后可以转化为1,2,3,4,5。）。<br /></p>
<p>3)最后，找规律，如出现几个2的乘积末尾是多少~~<br /><br />代码：</p>
<p>&nbsp;</p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><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 /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><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;n,m,a,b,c,temp,temp1,d;<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><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;p(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x)<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img id="Codehighlighter1_125_172_Open_Image" onclick="this.style.display='none'; Codehighlighter1_125_172_Open_Text.style.display='none'; Codehighlighter1_125_172_Closed_Image.style.display='inline'; Codehighlighter1_125_172_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_125_172_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_125_172_Closed_Text.style.display='none'; Codehighlighter1_125_172_Open_Image.style.display='inline'; Codehighlighter1_125_172_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_125_172_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_125_172_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(n</span><span style="color: #000000">&lt;</span><span style="color: #000000">x)&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">10</span><span style="color: #000000"><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;n</span><span style="color: #000000">/</span><span style="color: #000000">x</span><span style="color: #000000">+</span><span style="color: #000000">p(n</span><span style="color: #000000">/</span><span style="color: #000000">x);<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">12</span><span style="color: #000000"><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;g(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x)<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img id="Codehighlighter1_193_292_Open_Image" onclick="this.style.display='none'; Codehighlighter1_193_292_Open_Text.style.display='none'; Codehighlighter1_193_292_Closed_Image.style.display='inline'; Codehighlighter1_193_292_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_193_292_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_193_292_Closed_Text.style.display='none'; Codehighlighter1_193_292_Open_Image.style.display='inline'; Codehighlighter1_193_292_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_193_292_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_193_292_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(n</span><span style="color: #000000">&lt;</span><span style="color: #000000">1</span><span style="color: #000000">)&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">14</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">15</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(n</span><span style="color: #000000">%</span><span style="color: #000000">10</span><span style="color: #000000">&gt;=</span><span style="color: #000000">x)&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;n</span><span style="color: #000000">/</span><span style="color: #000000">10</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">+</span><span style="color: #000000">g(n</span><span style="color: #000000">/</span><span style="color: #000000">5</span><span style="color: #000000">,x);<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;n</span><span style="color: #000000">/</span><span style="color: #000000">10</span><span style="color: #000000">+</span><span style="color: #000000">g(n</span><span style="color: #000000">/</span><span style="color: #000000">5</span><span style="color: #000000">,x);<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">18</span><span style="color: #000000"><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;f(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x)<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img id="Codehighlighter1_313_367_Open_Image" onclick="this.style.display='none'; Codehighlighter1_313_367_Open_Text.style.display='none'; Codehighlighter1_313_367_Closed_Image.style.display='inline'; Codehighlighter1_313_367_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_313_367_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_313_367_Closed_Text.style.display='none'; Codehighlighter1_313_367_Open_Image.style.display='inline'; Codehighlighter1_313_367_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_313_367_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_313_367_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(n</span><span style="color: #000000">&lt;</span><span style="color: #000000">1</span><span style="color: #000000">)&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">20</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;f(n</span><span style="color: #000000">/</span><span style="color: #000000">2</span><span style="color: #000000">,x)</span><span style="color: #000000">+</span><span style="color: #000000">g(n,x);<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">22</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;working()<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img id="Codehighlighter1_384_921_Open_Image" onclick="this.style.display='none'; Codehighlighter1_384_921_Open_Text.style.display='none'; Codehighlighter1_384_921_Closed_Image.style.display='inline'; Codehighlighter1_384_921_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_384_921_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_384_921_Closed_Text.style.display='none'; Codehighlighter1_384_921_Open_Image.style.display='inline'; Codehighlighter1_384_921_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_384_921_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_384_921_Open_Text"><span style="color: #000000">{&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;k;<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;a</span><span style="color: #000000">=</span><span style="color: #000000">f(n,</span><span style="color: #000000">3</span><span style="color: #000000">)</span><span style="color: #000000">-</span><span style="color: #000000">f(n</span><span style="color: #000000">-</span><span style="color: #000000">m,</span><span style="color: #000000">3</span><span style="color: #000000">);<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;b</span><span style="color: #000000">=</span><span style="color: #000000">f(n,</span><span style="color: #000000">7</span><span style="color: #000000">)</span><span style="color: #000000">-</span><span style="color: #000000">f(n</span><span style="color: #000000">-</span><span style="color: #000000">m,</span><span style="color: #000000">7</span><span style="color: #000000">);<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;c</span><span style="color: #000000">=</span><span style="color: #000000">f(n,</span><span style="color: #000000">9</span><span style="color: #000000">)</span><span style="color: #000000">-</span><span style="color: #000000">f(n</span><span style="color: #000000">-</span><span style="color: #000000">m,</span><span style="color: #000000">9</span><span style="color: #000000">);<br /></span><span style="color: #008080">27</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;temp</span><span style="color: #000000">=</span><span style="color: #000000">p(n,</span><span style="color: #000000">5</span><span style="color: #000000">)</span><span style="color: #000000">-</span><span style="color: #000000">p(n</span><span style="color: #000000">-</span><span style="color: #000000">m,</span><span style="color: #000000">5</span><span style="color: #000000">);<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;temp1</span><span style="color: #000000">=</span><span style="color: #000000">p(n,</span><span style="color: #000000">2</span><span style="color: #000000">)</span><span style="color: #000000">-</span><span style="color: #000000">p(n</span><span style="color: #000000">-</span><span style="color: #000000">m,</span><span style="color: #000000">2</span><span style="color: #000000">);<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;d</span><span style="color: #000000">=</span><span style="color: #000000">temp1</span><span style="color: #000000">-</span><span style="color: #000000">temp;<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(a</span><span style="color: #000000">%</span><span style="color: #000000">4</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)&nbsp;a</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">31</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(a</span><span style="color: #000000">%</span><span style="color: #000000">4</span><span style="color: #000000">==</span><span style="color: #000000">1</span><span style="color: #000000">)&nbsp;a</span><span style="color: #000000">=</span><span style="color: #000000">3</span><span style="color: #000000">;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">32</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(a</span><span style="color: #000000">%</span><span style="color: #000000">4</span><span style="color: #000000">==</span><span style="color: #000000">2</span><span style="color: #000000">)&nbsp;a</span><span style="color: #000000">=</span><span style="color: #000000">9</span><span style="color: #000000">;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">33</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(a</span><span style="color: #000000">%</span><span style="color: #000000">4</span><span style="color: #000000">==</span><span style="color: #000000">3</span><span style="color: #000000">)&nbsp;a</span><span style="color: #000000">=</span><span style="color: #000000">7</span><span style="color: #000000">;<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">35</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(b</span><span style="color: #000000">%</span><span style="color: #000000">4</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)&nbsp;b</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">36</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(b</span><span style="color: #000000">%</span><span style="color: #000000">4</span><span style="color: #000000">==</span><span style="color: #000000">1</span><span style="color: #000000">)&nbsp;b</span><span style="color: #000000">=</span><span style="color: #000000">7</span><span style="color: #000000">;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">37</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(b</span><span style="color: #000000">%</span><span style="color: #000000">4</span><span style="color: #000000">==</span><span style="color: #000000">2</span><span style="color: #000000">)&nbsp;b</span><span style="color: #000000">=</span><span style="color: #000000">9</span><span style="color: #000000">;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">38</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(b</span><span style="color: #000000">%</span><span style="color: #000000">4</span><span style="color: #000000">==</span><span style="color: #000000">3</span><span style="color: #000000">)&nbsp;b</span><span style="color: #000000">=</span><span style="color: #000000">3</span><span style="color: #000000">;<br /></span><span style="color: #008080">39</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">40</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(c</span><span style="color: #000000">%</span><span style="color: #000000">4</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)&nbsp;c</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">41</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(c</span><span style="color: #000000">%</span><span style="color: #000000">4</span><span style="color: #000000">==</span><span style="color: #000000">1</span><span style="color: #000000">)&nbsp;c</span><span style="color: #000000">=</span><span style="color: #000000">9</span><span style="color: #000000">;&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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(c</span><span style="color: #000000">%</span><span style="color: #000000">4</span><span style="color: #000000">==</span><span style="color: #000000">2</span><span style="color: #000000">)&nbsp;c</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">43</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(c</span><span style="color: #000000">%</span><span style="color: #000000">4</span><span style="color: #000000">==</span><span style="color: #000000">3</span><span style="color: #000000">)&nbsp;c</span><span style="color: #000000">=</span><span style="color: #000000">9</span><span style="color: #000000">;<br /></span><span style="color: #008080">44</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">45</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(d</span><span style="color: #000000">%</span><span style="color: #000000">4</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)&nbsp;d</span><span style="color: #000000">=</span><span style="color: #000000">6</span><span style="color: #000000">;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">46</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(d</span><span style="color: #000000">%</span><span style="color: #000000">4</span><span style="color: #000000">==</span><span style="color: #000000">1</span><span style="color: #000000">)&nbsp;d</span><span style="color: #000000">=</span><span style="color: #000000">2</span><span style="color: #000000">;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">47</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(d</span><span style="color: #000000">%</span><span style="color: #000000">4</span><span style="color: #000000">==</span><span style="color: #000000">2</span><span style="color: #000000">)&nbsp;d</span><span style="color: #000000">=</span><span style="color: #000000">4</span><span style="color: #000000">;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">48</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(d</span><span style="color: #000000">%</span><span style="color: #000000">4</span><span style="color: #000000">==</span><span style="color: #000000">3</span><span style="color: #000000">)&nbsp;d</span><span style="color: #000000">=</span><span style="color: #000000">8</span><span style="color: #000000">;&nbsp;<br /></span><span style="color: #008080">49</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">50</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,a</span><span style="color: #000000">*</span><span style="color: #000000">b</span><span style="color: #000000">*</span><span style="color: #000000">c</span><span style="color: #000000">*</span><span style="color: #000000">d</span><span style="color: #000000">%</span><span style="color: #000000">10</span><span style="color: #000000">);<br /></span><span style="color: #008080">51</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">52</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">53</span><span style="color: #000000"><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 /></span><span style="color: #008080">54</span><span style="color: #000000"><img id="Codehighlighter1_934_992_Open_Image" onclick="this.style.display='none'; Codehighlighter1_934_992_Open_Text.style.display='none'; Codehighlighter1_934_992_Closed_Image.style.display='inline'; Codehighlighter1_934_992_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_934_992_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_934_992_Closed_Text.style.display='none'; Codehighlighter1_934_992_Open_Image.style.display='inline'; Codehighlighter1_934_992_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_934_992_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_934_992_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;(scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d%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">m)</span><span style="color: #000000">!=</span><span style="color: #000000">EOF)<br /></span><span style="color: #008080">55</span><span style="color: #000000"><img id="Codehighlighter1_973_989_Open_Image" onclick="this.style.display='none'; Codehighlighter1_973_989_Open_Text.style.display='none'; Codehighlighter1_973_989_Closed_Image.style.display='inline'; Codehighlighter1_973_989_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_973_989_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_973_989_Closed_Text.style.display='none'; Codehighlighter1_973_989_Open_Image.style.display='inline'; Codehighlighter1_973_989_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_973_989_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_973_989_Open_Text"><span style="color: #000000">{&nbsp;working();<br /></span><span style="color: #008080">56</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">57</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">58</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">59</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div>
<p><br /></p><img src ="http://www.cppblog.com/wyh123/aggbug/152621.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wyh123/" target="_blank">wyh</a> 2011-08-06 10:34 <a href="http://www.cppblog.com/wyh123/archive/2011/08/06/152621.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDOJ 1286（欧拉函数）</title><link>http://www.cppblog.com/wyh123/archive/2011/08/06/152620.html</link><dc:creator>wyh</dc:creator><author>wyh</author><pubDate>Sat, 06 Aug 2011 02:30:00 GMT</pubDate><guid>http://www.cppblog.com/wyh123/archive/2011/08/06/152620.html</guid><wfw:comment>http://www.cppblog.com/wyh123/comments/152620.html</wfw:comment><comments>http://www.cppblog.com/wyh123/archive/2011/08/06/152620.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wyh123/comments/commentRss/152620.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wyh123/services/trackbacks/152620.html</trackback:ping><description><![CDATA[题目大意：
<p>新年快到了，&#8220;猪头帮协会&#8221;准备搞一个聚会，已经知道现有会员N人，把会员从1到N编号，其中会长的号码是N号，凡是和会长是老朋友的，那么该会员的号码肯定和N有大于1的公约数，否则都是新朋友，现在会长想知道究竟有几个新朋友？请你编程序帮会长计算出来。<br /><br /><br />解题思路：这是一道裸的欧拉函数题目<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;对正整数n，<a href="http://baike.baidu.com/view/4645.htm" target="_blank"><font color="#136ec2">欧拉</font></a>函数是少于或等于n的数中与n互质的数的数目。此函数以其首名研究者欧拉命名，它又称为Euler's totient function、&#966;函数、欧拉商数等。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<div style="position: relative; padding-bottom: 3px; width: 152px; float: right; visibility: visible; top: 266px; left: 551px; findfakeobj: 1" class="text_pic"><a class=" pic-handle" title="查看图片" href="http://baike.baidu.com/image/adee30dd80a43c938d102997" target="_blank"></a>&nbsp;
<p class="pic-info">Euler函数</p></div>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 欧拉函数通式：&#966;(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)&#8230;..(1-1/pn),其中p1, p2&#8230;&#8230;pn为x的所有质因数，x是不为0的整数。&#966;(1)=1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; （唯 一和1互质的数就是1本身）。&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <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 />--><span style="color: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cmath</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><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 /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><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;n,T;<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">10</span><span style="color: #000000"><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;euler(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x)<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img id="Codehighlighter1_124_352_Open_Image" onclick="this.style.display='none'; Codehighlighter1_124_352_Open_Text.style.display='none'; Codehighlighter1_124_352_Closed_Image.style.display='inline'; Codehighlighter1_124_352_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_124_352_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_124_352_Closed_Text.style.display='none'; Codehighlighter1_124_352_Open_Image.style.display='inline'; Codehighlighter1_124_352_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_124_352_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_124_352_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i,res</span><span style="color: #000000">=</span><span style="color: #000000">x;<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(i</span><span style="color: #000000">=</span><span style="color: #000000">2</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">)sqrt(x</span><span style="color: #000000">*</span><span style="color: #000000">1</span><span style="color: #000000">)</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img id="Codehighlighter1_183_303_Open_Image" onclick="this.style.display='none'; Codehighlighter1_183_303_Open_Text.style.display='none'; Codehighlighter1_183_303_Closed_Image.style.display='inline'; Codehighlighter1_183_303_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_183_303_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_183_303_Closed_Text.style.display='none'; Codehighlighter1_183_303_Open_Image.style.display='inline'; Codehighlighter1_183_303_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&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_183_303_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_183_303_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(x&nbsp;</span><span style="color: #000000">%</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img id="Codehighlighter1_212_296_Open_Image" onclick="this.style.display='none'; Codehighlighter1_212_296_Open_Text.style.display='none'; Codehighlighter1_212_296_Closed_Image.style.display='inline'; Codehighlighter1_212_296_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_212_296_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_212_296_Closed_Text.style.display='none'; Codehighlighter1_212_296_Open_Image.style.display='inline'; Codehighlighter1_212_296_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;</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_212_296_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_212_296_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">15</span><span style="color: #000000"><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;res</span><span style="color: #000000">=</span><span style="color: #000000">res</span><span style="color: #000000">/</span><span style="color: #000000">i</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">);<br /></span><span style="color: #008080">16</span><span style="color: #000000"><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;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;(x&nbsp;</span><span style="color: #000000">%</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)&nbsp;x</span><span style="color: #000000">=</span><span style="color: #000000">x</span><span style="color: #000000">/</span><span style="color: #000000">i;<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">18</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">19</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(x</span><span style="color: #000000">&gt;</span><span style="color: #000000">1</span><span style="color: #000000">)&nbsp;res</span><span style="color: #000000">=</span><span style="color: #000000">res</span><span style="color: #000000">/</span><span style="color: #000000">x</span><span style="color: #000000">*</span><span style="color: #000000">(x</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">);<br /></span><span style="color: #008080">20</span><span style="color: #000000"><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;res;<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">22</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">23</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">24</span><span style="color: #000000"><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 /></span><span style="color: #008080">25</span><span style="color: #000000"><img id="Codehighlighter1_366_466_Open_Image" onclick="this.style.display='none'; Codehighlighter1_366_466_Open_Text.style.display='none'; Codehighlighter1_366_466_Closed_Image.style.display='inline'; Codehighlighter1_366_466_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_366_466_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_366_466_Closed_Text.style.display='none'; Codehighlighter1_366_466_Open_Image.style.display='inline'; Codehighlighter1_366_466_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_366_466_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_366_466_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;T;<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;(T</span><span style="color: #000000">--</span><span style="color: #000000">)<br /></span><span style="color: #008080">27</span><span style="color: #000000"><img id="Codehighlighter1_400_450_Open_Image" onclick="this.style.display='none'; Codehighlighter1_400_450_Open_Text.style.display='none'; Codehighlighter1_400_450_Closed_Image.style.display='inline'; Codehighlighter1_400_450_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_400_450_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_400_450_Closed_Text.style.display='none'; Codehighlighter1_400_450_Open_Image.style.display='inline'; Codehighlighter1_400_450_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_400_450_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_400_450_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;n;<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;euler(n)</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">30</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">31</span><span style="color: #000000"><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 /></span><span style="color: #008080">32</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">33</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div>
<p><br /><a href="http://baike.baidu.com/image/adee30dd80a43c938d102997" target="_blank"></a>&nbsp;</p><img src ="http://www.cppblog.com/wyh123/aggbug/152620.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wyh123/" target="_blank">wyh</a> 2011-08-06 10:30 <a href="http://www.cppblog.com/wyh123/archive/2011/08/06/152620.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDOJ 1163（树根）</title><link>http://www.cppblog.com/wyh123/archive/2011/08/05/152484.html</link><dc:creator>wyh</dc:creator><author>wyh</author><pubDate>Thu, 04 Aug 2011 16:01:00 GMT</pubDate><guid>http://www.cppblog.com/wyh123/archive/2011/08/05/152484.html</guid><wfw:comment>http://www.cppblog.com/wyh123/comments/152484.html</wfw:comment><comments>http://www.cppblog.com/wyh123/archive/2011/08/05/152484.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wyh123/comments/commentRss/152484.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wyh123/services/trackbacks/152484.html</trackback:ping><description><![CDATA[题目大意：给你一个n，输出n^n 的数根。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 树根的定义是求一个数各个位数的和，如果和是多位数，就继续求和，直到和为一位数。<br /><br />解题思路：1）树根要怎么求，每个人都知道，或是递归或是两个while，怎么写都行<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2）这道题的重点在于n^n的计算。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 假设一个数：b*10+c;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;则这个数的树根是: b+c<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 那么：这个数的平方的树根勒，不妨算一下：root((b*10+c)^2)=root(100*b*b+10*2*b*c+c*c)=b^2+2b*c+c^2<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; （是不是很眼熟）&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ~~~&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 没错，root()=(b+c)^2<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .....<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .....<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 推一下，n^n就知道该怎么算啦~~~<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 />--><span style="color: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cmath</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><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 /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><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;n,ro,i,ans,summ;<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">11</span><span style="color: #000000"><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;root(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a)<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img id="Codehighlighter1_156_318_Open_Image" onclick="this.style.display='none'; Codehighlighter1_156_318_Open_Text.style.display='none'; Codehighlighter1_156_318_Closed_Image.style.display='inline'; Codehighlighter1_156_318_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_156_318_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_156_318_Closed_Text.style.display='none'; Codehighlighter1_156_318_Open_Image.style.display='inline'; Codehighlighter1_156_318_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_156_318_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_156_318_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;summ</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">14</span><span style="color: #000000"><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">(a</span><span style="color: #000000">&gt;</span><span style="color: #000000">0</span><span style="color: #000000">)<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img id="Codehighlighter1_189_232_Open_Image" onclick="this.style.display='none'; Codehighlighter1_189_232_Open_Text.style.display='none'; Codehighlighter1_189_232_Closed_Image.style.display='inline'; Codehighlighter1_189_232_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_189_232_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_189_232_Closed_Text.style.display='none'; Codehighlighter1_189_232_Open_Image.style.display='inline'; Codehighlighter1_189_232_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_189_232_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_189_232_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;summ</span><span style="color: #000000">+=</span><span style="color: #000000">(a</span><span style="color: #000000">%</span><span style="color: #000000">10</span><span style="color: #000000">);<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a</span><span style="color: #000000">/=</span><span style="color: #000000">10</span><span style="color: #000000">;<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">19</span><span style="color: #000000"><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">(summ</span><span style="color: #000000">/</span><span style="color: #000000">10</span><span style="color: #000000">!=</span><span style="color: #000000">0</span><span style="color: #000000">)<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img id="Codehighlighter1_257_290_Open_Image" onclick="this.style.display='none'; Codehighlighter1_257_290_Open_Text.style.display='none'; Codehighlighter1_257_290_Closed_Image.style.display='inline'; Codehighlighter1_257_290_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_257_290_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_257_290_Closed_Text.style.display='none'; Codehighlighter1_257_290_Open_Image.style.display='inline'; Codehighlighter1_257_290_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_257_290_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_257_290_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;root(summ);<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">23</span><span style="color: #000000"><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 /></span><span style="color: #008080">24</span><span style="color: #000000"><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;summ;<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">26</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">27</span><span style="color: #000000"><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 /></span><span style="color: #008080">28</span><span style="color: #000000"><img id="Codehighlighter1_332_551_Open_Image" onclick="this.style.display='none'; Codehighlighter1_332_551_Open_Text.style.display='none'; Codehighlighter1_332_551_Closed_Image.style.display='inline'; Codehighlighter1_332_551_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_332_551_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_332_551_Closed_Text.style.display='none'; Codehighlighter1_332_551_Open_Image.style.display='inline'; Codehighlighter1_332_551_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_332_551_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_332_551_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">30</span><span style="color: #000000"><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">(</span><span style="color: #000000">~</span><span style="color: #000000">scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">n))<br /></span><span style="color: #008080">31</span><span style="color: #000000"><img id="Codehighlighter1_366_535_Open_Image" onclick="this.style.display='none'; Codehighlighter1_366_535_Open_Text.style.display='none'; Codehighlighter1_366_535_Closed_Image.style.display='inline'; Codehighlighter1_366_535_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_366_535_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_366_535_Closed_Text.style.display='none'; Codehighlighter1_366_535_Open_Image.style.display='inline'; Codehighlighter1_366_535_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_366_535_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_366_535_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">32</span><span style="color: #000000"><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">(n</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ro</span><span style="color: #000000">=</span><span style="color: #000000">root(n);<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">35</span><span style="color: #000000"><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">n;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">36</span><span style="color: #000000"><img id="Codehighlighter1_460_500_Open_Image" onclick="this.style.display='none'; Codehighlighter1_460_500_Open_Text.style.display='none'; Codehighlighter1_460_500_Closed_Image.style.display='inline'; Codehighlighter1_460_500_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_460_500_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_460_500_Closed_Text.style.display='none'; Codehighlighter1_460_500_Open_Image.style.display='inline'; Codehighlighter1_460_500_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_460_500_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_460_500_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">37</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans</span><span style="color: #000000">=</span><span style="color: #000000">root(ans</span><span style="color: #000000">*</span><span style="color: #000000">ro);<br /></span><span style="color: #008080">38</span><span style="color: #000000"><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 /></span><span style="color: #008080">39</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;ans&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /></span><span style="color: #008080">40</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">41</span><span style="color: #000000"><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 /></span><span style="color: #008080">42</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">43</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div><br /><br /><img src ="http://www.cppblog.com/wyh123/aggbug/152484.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wyh123/" target="_blank">wyh</a> 2011-08-05 00:01 <a href="http://www.cppblog.com/wyh123/archive/2011/08/05/152484.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>