﻿<?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++博客-MadBrain.Lab-随笔分类-NOIP</title><link>http://www.cppblog.com/superygw/category/20170.html</link><description>Mad Brian , a Super Weak Rookie</description><language>zh-cn</language><lastBuildDate>Sat, 03 Nov 2012 14:23:32 GMT</lastBuildDate><pubDate>Sat, 03 Nov 2012 14:23:32 GMT</pubDate><ttl>60</ttl><item><title>【NOIP2011】选择客栈</title><link>http://www.cppblog.com/superygw/archive/2012/11/03/194209.html</link><dc:creator>Cool Wings</dc:creator><author>Cool Wings</author><pubDate>Sat, 03 Nov 2012 12:45:00 GMT</pubDate><guid>http://www.cppblog.com/superygw/archive/2012/11/03/194209.html</guid><wfw:comment>http://www.cppblog.com/superygw/comments/194209.html</wfw:comment><comments>http://www.cppblog.com/superygw/archive/2012/11/03/194209.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/superygw/comments/commentRss/194209.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/superygw/services/trackbacks/194209.html</trackback:ping><description><![CDATA[<p>这个题据说是水题，有很多种算法<br />算法1 （朴素）：<br />1、顺序检索每一个客栈。<br />2、对于颜色为k的客栈i，搜索在此之前后颜色同为k的客栈j。<br />3、搜索到以后查找区间[i,j]内消费要求小于等于p的客栈，搜索到则总结果数sum+1。</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</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="" /></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&nbsp;;<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="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img id="Codehighlighter1_52_544_Open_Image" onclick="this.style.display='none'; Codehighlighter1_52_544_Open_Text.style.display='none'; Codehighlighter1_52_544_Closed_Image.style.display='inline'; Codehighlighter1_52_544_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_52_544_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_52_544_Closed_Text.style.display='none'; Codehighlighter1_52_544_Open_Image.style.display='inline'; Codehighlighter1_52_544_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_52_544_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_52_544_Open_Text"><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/InBlock.gif"  alt="" />&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;n,&nbsp;k,&nbsp;p&nbsp;;<br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;color[</span><span style="color: #000000">200000</span><span style="color: #000000">],&nbsp;cost[</span><span style="color: #000000">200000</span><span style="color: #000000">]&nbsp;;<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">freopen(&nbsp;"2.in",&nbsp;"r",&nbsp;stdin&nbsp;)&nbsp;;&nbsp;freopen(&nbsp;"2.out",&nbsp;"w",&nbsp;stdout&nbsp;)&nbsp;;</span><span style="color: #008000"><br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000">&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">n&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">k&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;p&nbsp;;<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;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">color[i]&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">cost[i]&nbsp;;<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;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;ans&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;;<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n</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;)<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;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;j&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;j&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n&nbsp;;&nbsp;j</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<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;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(&nbsp;color[i]</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;color[j]&nbsp;)&nbsp;<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img id="Codehighlighter1_374_515_Open_Image" onclick="this.style.display='none'; Codehighlighter1_374_515_Open_Text.style.display='none'; Codehighlighter1_374_515_Closed_Image.style.display='inline'; Codehighlighter1_374_515_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_374_515_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_374_515_Closed_Text.style.display='none'; Codehighlighter1_374_515_Open_Image.style.display='inline'; Codehighlighter1_374_515_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_374_515_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_374_515_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;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;temp&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;;<br /></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;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;cafe&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;i;&nbsp;cafe&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;j&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;temp&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;;&nbsp;cafe</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(&nbsp;cost[cafe]&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;p&nbsp;)&nbsp;temp&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;;<br /></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;ans&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;temp&nbsp;;<br /></span><span style="color: #008080">19</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">20</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;ans&nbsp;;<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;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;;<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></div>
<p><br /><br />预期得分40~60</p>
<p>算法二：<br />当然是DP<br />动态规划，设f[i,j]为前i个客栈中色调为j的可行方案，s[i,j]为前i个客栈中可以与之后色调为j的客栈搭配的客栈数，即有s[i,j]个客栈的色调为j，且该客栈与第i个客栈之间有符合条件的咖啡店，v[i]为第i个客栈的最低消费，c[i]为第i个客栈的色调a[i,j]为前i个客栈中色调为j的客栈的数目，则有<br />s[i,j] = ( v[i] &lt;= p ) ? a[i,j] : s[i-1,j]&nbsp; <br />f[j] = ( c != j ) ? f[j] : f[j]+s[j]</p>
<p>代码：</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="" /></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&nbsp;;<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="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img id="Codehighlighter1_51_560_Open_Image" onclick="this.style.display='none'; Codehighlighter1_51_560_Open_Text.style.display='none'; Codehighlighter1_51_560_Closed_Image.style.display='inline'; Codehighlighter1_51_560_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_51_560_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_51_560_Closed_Text.style.display='none'; Codehighlighter1_51_560_Open_Image.style.display='inline'; Codehighlighter1_51_560_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_51_560_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_51_560_Open_Text"><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/InBlock.gif"  alt="" />&nbsp;freopen(&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">2.in</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">r</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;stdin&nbsp;)&nbsp;;<br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;freopen(&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">2.out</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">w</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;stdout&nbsp;)&nbsp;;<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;n,&nbsp;m,&nbsp;p,&nbsp;i,&nbsp;j,&nbsp;ans,&nbsp;v&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;c&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;;<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img id="Codehighlighter1_176_178_Open_Image" onclick="this.style.display='none'; Codehighlighter1_176_178_Open_Text.style.display='none'; Codehighlighter1_176_178_Closed_Image.style.display='inline'; Codehighlighter1_176_178_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_176_178_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_176_178_Closed_Text.style.display='none'; Codehighlighter1_176_178_Open_Image.style.display='inline'; Codehighlighter1_176_178_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;a[</span><span style="color: #000000">50</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_176_178_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_176_178_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">0</span><span style="color: #000000">}</span></span><span style="color: #000000">,&nbsp;s[</span><span style="color: #000000">50</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_189_191_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_189_191_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">0</span><span style="color: #000000">}</span></span><span style="color: #000000">,&nbsp;f[</span><span style="color: #000000">50</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_202_204_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_202_204_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">0</span><span style="color: #000000">}</span></span><span style="color: #000000">&nbsp;;<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;scanf(&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">%ld%ld%ld</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">n,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">m,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">p&nbsp;)&nbsp;;<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;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i&nbsp;</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;)<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img id="Codehighlighter1_272_471_Open_Image" onclick="this.style.display='none'; Codehighlighter1_272_471_Open_Text.style.display='none'; Codehighlighter1_272_471_Closed_Image.style.display='inline'; Codehighlighter1_272_471_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_272_471_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_272_471_Closed_Text.style.display='none'; Codehighlighter1_272_471_Open_Image.style.display='inline'; Codehighlighter1_272_471_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_272_471_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_272_471_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;scanf(&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">%ld%ld</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">c,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">v&nbsp;)&nbsp;;<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;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(&nbsp;v&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;p&nbsp;)&nbsp;<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">for</span><span style="color: #000000">&nbsp;(&nbsp;j&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;j&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;m;&nbsp;j</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)&nbsp;s[j]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;a[j]&nbsp;;<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(&nbsp;j&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;j&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;m;&nbsp;j</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<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;f[j]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(&nbsp;c&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;j&nbsp;)&nbsp;</span><span style="color: #000000">?</span><span style="color: #000000">&nbsp;f[j]&nbsp;:&nbsp;f[j]</span><span style="color: #000000">+</span><span style="color: #000000">s[j]&nbsp;;<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;a[c]</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;;<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;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(&nbsp;v&nbsp;</span><span style="color: #000000">&lt;=</span><span style="color: #000000">&nbsp;p&nbsp;)&nbsp;s[c]</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;;<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;}</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/InBlock.gif"  alt="" />&nbsp;ans&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;;<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;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(&nbsp;j&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;j&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;m;&nbsp;j</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)&nbsp;ans</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;f[j]&nbsp;;<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;printf(&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">%ld</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;ans&nbsp;)&nbsp;;<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;;<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span></div>
<p><br />&nbsp;</p><img src ="http://www.cppblog.com/superygw/aggbug/194209.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/superygw/" target="_blank">Cool Wings</a> 2012-11-03 20:45 <a href="http://www.cppblog.com/superygw/archive/2012/11/03/194209.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>