﻿<?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++博客-slytherin</title><link>http://www.cppblog.com/slytherin/</link><description /><language>zh-cn</language><lastBuildDate>Tue, 14 Apr 2026 23:10:07 GMT</lastBuildDate><pubDate>Tue, 14 Apr 2026 23:10:07 GMT</pubDate><ttl>60</ttl><item><title>[ahoi]搬砖头</title><link>http://www.cppblog.com/slytherin/archive/2012/02/10/165318.html</link><dc:creator>slytherin</dc:creator><author>slytherin</author><pubDate>Fri, 10 Feb 2012 13:57:00 GMT</pubDate><guid>http://www.cppblog.com/slytherin/archive/2012/02/10/165318.html</guid><wfw:comment>http://www.cppblog.com/slytherin/comments/165318.html</wfw:comment><comments>http://www.cppblog.com/slytherin/archive/2012/02/10/165318.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/slytherin/comments/commentRss/165318.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/slytherin/services/trackbacks/165318.html</trackback:ping><description><![CDATA[<div><span style="font-size: 12px;">#include &lt;stdio.h&gt;</span></div><div><span style="font-size: 12px;">int a[300]={0},b[300]={0},c[300]={0},ans[300]={0};</span></div><div><span style="font-size: 12px;">int main()</span></div><div><span style="font-size: 12px;">{</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; //freopen("1.in","r",stdin);</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; //freopen("1.out","w",stdout);</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; int j,i,n;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; scanf("%d",&amp;n);</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; a[1]=1;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; b[1]=2;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; c[1]=4;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; if(n&lt;4)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; {</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(n==1)printf("1\n");</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(n==2)printf("2\n");</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(n==3)printf("4\n");</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; }</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; else{</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; for(i=4;i&lt;=n;i++)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; {</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp;for(j=1;j&lt;=300;j++)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp;{</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ans[j]+=a[j]+b[j]+c[j];</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ans[j+1]+=ans[j]/10;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ans[j]%=10;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp;}</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp;for(j=1;j&lt;=300;j++)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp;{</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a[j]=b[j];</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b[j]=c[j];</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;c[j]=ans[j];</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ans[j]=0;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp;}</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; }</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;for(i=300;i&gt;=0;i--)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;if(c[i])break;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; for(;i&gt;=1;i--)printf("%d",c[i]);</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; printf("\n");</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;}</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; return 0;</span></div><div><span style="font-size: 12px;">}</span></div><div><span style="font-size: 12px; ">很简单的DP &nbsp; 但是竟然忘记高精度的写法了....<br /><br /></span></div><img src ="http://www.cppblog.com/slytherin/aggbug/165318.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/slytherin/" target="_blank">slytherin</a> 2012-02-10 21:57 <a href="http://www.cppblog.com/slytherin/archive/2012/02/10/165318.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>rqnoj[650]FunnyBirds</title><link>http://www.cppblog.com/slytherin/archive/2011/11/08/159835.html</link><dc:creator>slytherin</dc:creator><author>slytherin</author><pubDate>Tue, 08 Nov 2011 12:56:00 GMT</pubDate><guid>http://www.cppblog.com/slytherin/archive/2011/11/08/159835.html</guid><wfw:comment>http://www.cppblog.com/slytherin/comments/159835.html</wfw:comment><comments>http://www.cppblog.com/slytherin/archive/2011/11/08/159835.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/slytherin/comments/commentRss/159835.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/slytherin/services/trackbacks/159835.html</trackback:ping><description><![CDATA[<div>题目不是难，自定义一个函数，然后递归就可以了。<br />#include &lt;stdio.h&gt;</div><div>long cout=0;</div><div>void ans(n)</div><div>{</div><div>&nbsp; &nbsp; &nbsp;if(n!=0)</div><div>&nbsp; &nbsp; &nbsp;{</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;long i;</div><div>&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; for(i=1;n&gt;0;i++)</div><div>&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;{&nbsp;n-=i;cout++;}</div><div>&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; if(n!=0)</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{cout--;ans(n-1+i);}</div><div>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;}<br />}</div><div>int main()</div><div>{</div><div>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; //freopen("1.in","r",stdin);</div><div>&nbsp; &nbsp; //freopen("1.out","w",stdout);</div><div>&nbsp; &nbsp; long m=1,n,i;</div><div>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; scanf("%ld",&amp;n);</div><div>&nbsp; &nbsp; ans(n);</div><div>&nbsp; &nbsp; printf("%ld",cout);</div><div>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; return 0;</div><div>}</div><div>&nbsp; &nbsp;&nbsp;</div><img src ="http://www.cppblog.com/slytherin/aggbug/159835.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/slytherin/" target="_blank">slytherin</a> 2011-11-08 20:56 <a href="http://www.cppblog.com/slytherin/archive/2011/11/08/159835.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>rqnoj[2]开心的金明</title><link>http://www.cppblog.com/slytherin/archive/2011/11/02/159528.html</link><dc:creator>slytherin</dc:creator><author>slytherin</author><pubDate>Wed, 02 Nov 2011 13:32:00 GMT</pubDate><guid>http://www.cppblog.com/slytherin/archive/2011/11/02/159528.html</guid><wfw:comment>http://www.cppblog.com/slytherin/comments/159528.html</wfw:comment><comments>http://www.cppblog.com/slytherin/archive/2011/11/02/159528.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/slytherin/comments/commentRss/159528.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/slytherin/services/trackbacks/159528.html</trackback:ping><description><![CDATA[很简单的一题，但是对DP很不熟悉，这好像也是第一次自己写dp的题目，写下错误吧。<br />#include &lt;stdio.h&gt;<br />int main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;long n,m,i,j,a[30001]={0},v[26],w[26];<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp; scanf("%ld%ld",&amp;n,&amp;m);<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;m;i++)<br />&nbsp;&nbsp;&nbsp; scanf("%ld%ld",&amp;v[i],&amp;w[i]);<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;m;i++)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(j=n;j&gt;=v[i];j--)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(a[j-v[i]]+v[i]*w[i]&gt;a[j])a[j]=a[j-v[i]]+v[i]*w[i];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp; printf("%ld",a[n]);<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp; return 0;<br />}<br />很基础的一题，但是在开始对n和m的含义弄混了，导致无输出。<br />后来在for(j=n;j&gt;=v[i];j--)<br />中判断条件设成了j&gt;0&nbsp;&nbsp; 没用弄清具体含义，下次要注意。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <img src ="http://www.cppblog.com/slytherin/aggbug/159528.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/slytherin/" target="_blank">slytherin</a> 2011-11-02 21:32 <a href="http://www.cppblog.com/slytherin/archive/2011/11/02/159528.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>rqnoj[51]乒乓球</title><link>http://www.cppblog.com/slytherin/archive/2011/10/29/159322.html</link><dc:creator>slytherin</dc:creator><author>slytherin</author><pubDate>Sat, 29 Oct 2011 10:43:00 GMT</pubDate><guid>http://www.cppblog.com/slytherin/archive/2011/10/29/159322.html</guid><wfw:comment>http://www.cppblog.com/slytherin/comments/159322.html</wfw:comment><comments>http://www.cppblog.com/slytherin/archive/2011/10/29/159322.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/slytherin/comments/commentRss/159322.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/slytherin/services/trackbacks/159322.html</trackback:ping><description><![CDATA[<p><font face="Verdana" color="#000000">#include &lt;stdio.h&gt;<br />char a[10000000];<br />int main()<br />{<br />&nbsp;&nbsp;&nbsp; long i,n=0,h=0,d=0;<br />&nbsp;&nbsp;&nbsp; char c;<br />&nbsp;&nbsp;&nbsp; scanf("%c",&amp;c);<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; while(c!='E')//存入胜负记录。判断是否结束，判断是否为换行。<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(c!='\n')<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; n++;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a[n]=c;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scanf("%c",&amp;c);<br />&nbsp;&nbsp;&nbsp; }</font></p>
<p><font face="Verdana" color="#000000">&nbsp;&nbsp;&nbsp; for(i=1;i&lt;=n;i++)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(a[i]=='W')h++;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else d++;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(h&gt;=11 &amp;&amp; h-d&gt;1 || d&gt;=11 &amp;&amp; d-h&gt;1)//乒乓球的取胜规则。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%ld:%ld\n",h,d);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; h=0;d=0;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%ld:%ld\n",h,d);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; h=0;d=0;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; printf("\n");<br />&nbsp;&nbsp;&nbsp;&nbsp; for(i=1;i&lt;=n;i++)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(a[i]=='W')h++;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else d++;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(h&gt;=21 &amp;&amp; h-d&gt;1 || d&gt;=21 &amp;&amp; d-h&gt;1)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%ld:%ld\n",h,d);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; h=0;d=0;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; printf("%ld:%ld\n",h,d);<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return 0;<br />}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; <br /></font></p><img src ="http://www.cppblog.com/slytherin/aggbug/159322.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/slytherin/" target="_blank">slytherin</a> 2011-10-29 18:43 <a href="http://www.cppblog.com/slytherin/archive/2011/10/29/159322.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>rqnoj[639]侦查守卫</title><link>http://www.cppblog.com/slytherin/archive/2011/10/29/159320.html</link><dc:creator>slytherin</dc:creator><author>slytherin</author><pubDate>Sat, 29 Oct 2011 10:41:00 GMT</pubDate><guid>http://www.cppblog.com/slytherin/archive/2011/10/29/159320.html</guid><wfw:comment>http://www.cppblog.com/slytherin/comments/159320.html</wfw:comment><comments>http://www.cppblog.com/slytherin/archive/2011/10/29/159320.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/slytherin/comments/commentRss/159320.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/slytherin/services/trackbacks/159320.html</trackback:ping><description><![CDATA[二维数组空间覆盖，注意临界点和起始点。<br /><br />
<p>#include &lt;stdio.h&gt;<br />int main()<br />{<br />&nbsp;&nbsp;&nbsp; long j,i,a[101][101]={0},x[5],y[5],s1=0,s2=0,s3=0;<br />&nbsp;&nbsp;&nbsp; for(i=1;i&lt;=4;i++)scanf("%ld%ld",&amp;x[i],&amp;y[i]);<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(i=x[1];i&lt;x[2];i++)<br />&nbsp;&nbsp;&nbsp; for(j=y[1];j&lt;y[2];j++)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a[i][j]=1;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; for(i=x[3];i&lt;x[4];i++)<br />&nbsp;&nbsp;&nbsp; for(j=y[3];j&lt;y[4];j++)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(a[i][j]==1)a[i][j]=3;<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; else&nbsp; a[i][j]=1;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;=100;i++)<br />&nbsp;&nbsp;&nbsp; for(j=0;j&lt;=100;j++)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if&nbsp; (a[i][j]==3)s1++;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else&nbsp; if(a[i][j]==1)s2++;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; printf("%ld %ld %ld\n",s1,s2,10000-s1-s2);<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return 0;<br />}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p><img src ="http://www.cppblog.com/slytherin/aggbug/159320.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/slytherin/" target="_blank">slytherin</a> 2011-10-29 18:41 <a href="http://www.cppblog.com/slytherin/archive/2011/10/29/159320.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>rqnoj[62]均分纸牌</title><link>http://www.cppblog.com/slytherin/archive/2011/10/29/159319.html</link><dc:creator>slytherin</dc:creator><author>slytherin</author><pubDate>Sat, 29 Oct 2011 10:38:00 GMT</pubDate><guid>http://www.cppblog.com/slytherin/archive/2011/10/29/159319.html</guid><wfw:comment>http://www.cppblog.com/slytherin/comments/159319.html</wfw:comment><comments>http://www.cppblog.com/slytherin/archive/2011/10/29/159319.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/slytherin/comments/commentRss/159319.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/slytherin/services/trackbacks/159319.html</trackback:ping><description><![CDATA[我们按照由左而右的顺序移动纸牌。若第i堆纸牌的张数a[i]超出平均值，则移动一次(ans+1)，将超出部分留给下一堆，既第i+1堆纸牌的张数增加a[i]-ave；若第i堆纸牌的张数a[i]少于平均值，则移动一次(ans+1)，由下一堆补充不足部分，既第i+1堆纸牌的张数减少ave-a[i]；&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; 问题是，在从第i+1堆中取出纸牌补充第i堆的过程中，可能会出现第i+1堆的纸牌数小于零(a[i+1]-(ave-a[i])&lt;0 )的情况，但由于纸牌的总数是n的倍数，因此后面的堆会补充第i+1堆ave-a[i]-a[i+1]+ ave张纸牌，使其达到均分的要求。 <strong>我们在移动过程中，只是改变了移动的顺序，而移动的次数不变</strong>，因此此题使用该方法是可行的。<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;例如：1&nbsp; 2&nbsp; 27&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 我们从第二堆移出9张到第一堆后，第一堆有10张纸牌，第二堆剩下-7张纸牌，再从第三堆移动17张到第二堆，刚好三堆纸牌数都是10，最后结果是对的，从第二堆移出的牌都可以从第三堆得到。<br />&nbsp;&nbsp;&nbsp;&nbsp; 此题的原理是贪心，从左到右让每堆牌向平均数靠拢。但负数的牌也可以移动，才是此题的关键。<br /><br /><font face="Verdana" color="#000000">#include &lt;stdio.h&gt;<br />int a[101]={0};<br />int main()<br />{<br />&nbsp;&nbsp;&nbsp; long n,i,sum=0,d;<br />&nbsp;&nbsp;&nbsp; scanf("%ld",&amp;n);<br />&nbsp;&nbsp;&nbsp; for(i=1;i&lt;=n;i++)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scanf("%ld",&amp;a[i]);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sum+=a[i];<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; d=sum/n;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; long count=0;<br />&nbsp;&nbsp;&nbsp; for(i=1;i&lt;=n-1;i++)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(a[i]!=d)<br />&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; a[i+1]-=d-a[i];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; count++;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; printf("%ld",count);<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; return 0;<br />&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; <br /></font><img src ="http://www.cppblog.com/slytherin/aggbug/159319.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/slytherin/" target="_blank">slytherin</a> 2011-10-29 18:38 <a href="http://www.cppblog.com/slytherin/archive/2011/10/29/159319.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>