﻿<?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++博客-zhongguoa</title><link>http://www.cppblog.com/zhongguoa/</link><description>渺小得像一颗鼻屎一样</description><language>zh-cn</language><lastBuildDate>Tue, 14 Apr 2026 23:10:08 GMT</lastBuildDate><pubDate>Tue, 14 Apr 2026 23:10:08 GMT</pubDate><ttl>60</ttl><item><title>网络编程小例</title><link>http://www.cppblog.com/zhongguoa/archive/2010/05/12/115162.html</link><dc:creator>zhongguoa</dc:creator><author>zhongguoa</author><pubDate>Wed, 12 May 2010 02:01:00 GMT</pubDate><guid>http://www.cppblog.com/zhongguoa/archive/2010/05/12/115162.html</guid><wfw:comment>http://www.cppblog.com/zhongguoa/comments/115162.html</wfw:comment><comments>http://www.cppblog.com/zhongguoa/archive/2010/05/12/115162.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhongguoa/comments/commentRss/115162.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhongguoa/services/trackbacks/115162.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: //server.c&nbsp;1#include&nbsp;&lt;stdlib.h&gt;&nbsp;2#include&nbsp;&lt;stdio.h&gt;&nbsp;3#include&nbsp;&lt;errno.h&gt;&nbsp;4#include&nbsp;&lt;string.h&gt;&nbsp;5#include&nbsp;&lt;unistd.h&gt;&nbsp...&nbsp;&nbsp;<a href='http://www.cppblog.com/zhongguoa/archive/2010/05/12/115162.html'>阅读全文</a><img src ="http://www.cppblog.com/zhongguoa/aggbug/115162.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhongguoa/" target="_blank">zhongguoa</a> 2010-05-12 10:01 <a href="http://www.cppblog.com/zhongguoa/archive/2010/05/12/115162.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>连堆都不会用</title><link>http://www.cppblog.com/zhongguoa/archive/2008/12/02/68337.html</link><dc:creator>zhongguoa</dc:creator><author>zhongguoa</author><pubDate>Tue, 02 Dec 2008 00:12:00 GMT</pubDate><guid>http://www.cppblog.com/zhongguoa/archive/2008/12/02/68337.html</guid><wfw:comment>http://www.cppblog.com/zhongguoa/comments/68337.html</wfw:comment><comments>http://www.cppblog.com/zhongguoa/archive/2008/12/02/68337.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhongguoa/comments/commentRss/68337.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhongguoa/services/trackbacks/68337.html</trackback:ping><description><![CDATA[心烦
<img src ="http://www.cppblog.com/zhongguoa/aggbug/68337.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhongguoa/" target="_blank">zhongguoa</a> 2008-12-02 08:12 <a href="http://www.cppblog.com/zhongguoa/archive/2008/12/02/68337.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>旋转卡壳</title><link>http://www.cppblog.com/zhongguoa/archive/2008/08/28/60211.html</link><dc:creator>zhongguoa</dc:creator><author>zhongguoa</author><pubDate>Wed, 27 Aug 2008 21:57:00 GMT</pubDate><guid>http://www.cppblog.com/zhongguoa/archive/2008/08/28/60211.html</guid><wfw:comment>http://www.cppblog.com/zhongguoa/comments/60211.html</wfw:comment><comments>http://www.cppblog.com/zhongguoa/archive/2008/08/28/60211.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhongguoa/comments/commentRss/60211.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhongguoa/services/trackbacks/60211.html</trackback:ping><description><![CDATA[转得老子的脑壳子都卡住了
<img src ="http://www.cppblog.com/zhongguoa/aggbug/60211.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhongguoa/" target="_blank">zhongguoa</a> 2008-08-28 05:57 <a href="http://www.cppblog.com/zhongguoa/archive/2008/08/28/60211.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>终于明白了凸包</title><link>http://www.cppblog.com/zhongguoa/archive/2008/07/30/57483.html</link><dc:creator>zhongguoa</dc:creator><author>zhongguoa</author><pubDate>Tue, 29 Jul 2008 18:35:00 GMT</pubDate><guid>http://www.cppblog.com/zhongguoa/archive/2008/07/30/57483.html</guid><wfw:comment>http://www.cppblog.com/zhongguoa/comments/57483.html</wfw:comment><comments>http://www.cppblog.com/zhongguoa/archive/2008/07/30/57483.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/zhongguoa/comments/commentRss/57483.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhongguoa/services/trackbacks/57483.html</trackback:ping><description><![CDATA[明天再看看具体的代码怎么写
<img src ="http://www.cppblog.com/zhongguoa/aggbug/57483.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhongguoa/" target="_blank">zhongguoa</a> 2008-07-30 02:35 <a href="http://www.cppblog.com/zhongguoa/archive/2008/07/30/57483.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku1032关于数论的一个结论</title><link>http://www.cppblog.com/zhongguoa/archive/2008/05/10/49426.html</link><dc:creator>zhongguoa</dc:creator><author>zhongguoa</author><pubDate>Sat, 10 May 2008 05:45:00 GMT</pubDate><guid>http://www.cppblog.com/zhongguoa/archive/2008/05/10/49426.html</guid><wfw:comment>http://www.cppblog.com/zhongguoa/comments/49426.html</wfw:comment><comments>http://www.cppblog.com/zhongguoa/archive/2008/05/10/49426.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhongguoa/comments/commentRss/49426.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhongguoa/services/trackbacks/49426.html</trackback:ping><description><![CDATA[把自然数N分解成若干个互不相同的正整数，使乘积最大；<br><br>由于这种分解的数目是有限的，所以最大积存在；<br><br>假设最大积的分解为<br><br>n=a1+a2+a3+...+a[t-2]+a[t-1]+a[t]<br><br>(a1&lt;a2&lt;a3&lt;...&lt;a[t-2]&lt;a[t-1]&lt;a[t])<br><br>Now, from the five rules above, we could make the mutiple maximum.<br><br>to an N, find the integer k, fits<br><br>A=2+3+4+...+(k-1)+k &lt;= N &lt; A+(k+1)=B<br><br>Suppose N = A + p, (0 &lt;= p &lt; k+1)<br><br>1) p=0, then answer is Set A<br><br>2) 1&lt;=p&lt;=k-1 then answer is Set B - { k+1-p }<br><br>3) p=k, then answer is Set A - {2} + {k+2}<br>
<img src ="http://www.cppblog.com/zhongguoa/aggbug/49426.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhongguoa/" target="_blank">zhongguoa</a> 2008-05-10 13:45 <a href="http://www.cppblog.com/zhongguoa/archive/2008/05/10/49426.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>itoa </title><link>http://www.cppblog.com/zhongguoa/archive/2008/05/08/49247.html</link><dc:creator>zhongguoa</dc:creator><author>zhongguoa</author><pubDate>Thu, 08 May 2008 12:48:00 GMT</pubDate><guid>http://www.cppblog.com/zhongguoa/archive/2008/05/08/49247.html</guid><wfw:comment>http://www.cppblog.com/zhongguoa/comments/49247.html</wfw:comment><comments>http://www.cppblog.com/zhongguoa/archive/2008/05/08/49247.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhongguoa/comments/commentRss/49247.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhongguoa/services/trackbacks/49247.html</trackback:ping><description><![CDATA[功 能: 把一整数转换为字符串<br>用 法: char *itoa(int value, char *string, int radix);<br>详细解释:itoa是英文integer to string a(将整形数转化为一个字符串,并将值保存在a中)<br>的缩写.其中value为要转化的整数, radix是基数的意思,即先将value转化为几进制的数,之后在保存在a 中.<br>作用:实现数制之间的转化<br>比较:ltoa,其中l是long integer(长整形数)<br>备注:该函数的头文件是"stdlib.h"&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br>程序例:<br>#include &lt;stdlib.h&gt;<br>#include &lt;stdio.h&gt;<br>int main(){<br>&nbsp; &nbsp; int number = 123456;<br>&nbsp; &nbsp; char string[25];<br>&nbsp; &nbsp; itoa(number, string, 10);<br>&nbsp; &nbsp; printf("integer = %d string = %s\n", number, string);<br>&nbsp; &nbsp; return 0;&nbsp; &nbsp; <br>}
<img src ="http://www.cppblog.com/zhongguoa/aggbug/49247.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhongguoa/" target="_blank">zhongguoa</a> 2008-05-08 20:48 <a href="http://www.cppblog.com/zhongguoa/archive/2008/05/08/49247.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>并查集的模板</title><link>http://www.cppblog.com/zhongguoa/archive/2008/04/10/46789.html</link><dc:creator>zhongguoa</dc:creator><author>zhongguoa</author><pubDate>Thu, 10 Apr 2008 15:28:00 GMT</pubDate><guid>http://www.cppblog.com/zhongguoa/archive/2008/04/10/46789.html</guid><wfw:comment>http://www.cppblog.com/zhongguoa/comments/46789.html</wfw:comment><comments>http://www.cppblog.com/zhongguoa/archive/2008/04/10/46789.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhongguoa/comments/commentRss/46789.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhongguoa/services/trackbacks/46789.html</trackback:ping><description><![CDATA[<br><br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000">&nbsp;std;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;pre[</span><span style="COLOR: #000000">110</span><span style="COLOR: #000000">],rank[</span><span style="COLOR: #000000">110</span><span style="COLOR: #000000">],n;<br><img id=Codehighlighter1_82_188_Open_Image onclick="this.style.display='none'; Codehighlighter1_82_188_Open_Text.style.display='none'; Codehighlighter1_82_188_Closed_Image.style.display='inline'; Codehighlighter1_82_188_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_82_188_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_82_188_Closed_Text.style.display='none'; Codehighlighter1_82_188_Open_Image.style.display='inline'; Codehighlighter1_82_188_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;find(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x)</span><span id=Codehighlighter1_82_188_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_82_188_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;r</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(pre[r]</span><span style="COLOR: #000000">!=-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">pre[r];<br><img id=Codehighlighter1_137_175_Open_Image onclick="this.style.display='none'; Codehighlighter1_137_175_Open_Text.style.display='none'; Codehighlighter1_137_175_Closed_Image.style.display='inline'; Codehighlighter1_137_175_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_137_175_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_137_175_Closed_Text.style.display='none'; Codehighlighter1_137_175_Open_Image.style.display='inline'; Codehighlighter1_137_175_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(x</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">r)</span><span id=Codehighlighter1_137_175_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_137_175_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;q</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">pre[x];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pre[x]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">r;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">q;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;r;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img id=Codehighlighter1_216_353_Open_Image onclick="this.style.display='none'; Codehighlighter1_216_353_Open_Text.style.display='none'; Codehighlighter1_216_353_Closed_Image.style.display='inline'; Codehighlighter1_216_353_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_216_353_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_216_353_Closed_Text.style.display='none'; Codehighlighter1_216_353_Open_Image.style.display='inline'; Codehighlighter1_216_353_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;unionone(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;a,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;b)</span><span id=Codehighlighter1_216_353_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_216_353_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;t1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">find(a);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;t2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">find(b);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(rank[t1]</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">rank[t2])<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pre[t2]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">t1;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pre[t1]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">t2;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(rank[t1]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">rank[t2])<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rank[t2]</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;n</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img id=Codehighlighter1_365_651_Open_Image onclick="this.style.display='none'; Codehighlighter1_365_651_Open_Text.style.display='none'; Codehighlighter1_365_651_Closed_Image.style.display='inline'; Codehighlighter1_365_651_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_365_651_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_365_651_Closed_Text.style.display='none'; Codehighlighter1_365_651_Open_Image.style.display='inline'; Codehighlighter1_365_651_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()</span><span id=Codehighlighter1_365_651_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_365_651_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;m,i,begin,end;<br><img id=Codehighlighter1_396_638_Open_Image onclick="this.style.display='none'; Codehighlighter1_396_638_Open_Text.style.display='none'; Codehighlighter1_396_638_Closed_Image.style.display='inline'; Codehighlighter1_396_638_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_396_638_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_396_638_Closed_Text.style.display='none'; Codehighlighter1_396_638_Open_Image.style.display='inline'; Codehighlighter1_396_638_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&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">)</span><span id=Codehighlighter1_396_638_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_396_638_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</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,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">m);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(n</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">m</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br><img id=Codehighlighter1_469_501_Open_Image onclick="this.style.display='none'; Codehighlighter1_469_501_Open_Text.style.display='none'; Codehighlighter1_469_501_Closed_Image.style.display='inline'; Codehighlighter1_469_501_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_469_501_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_469_501_Closed_Text.style.display='none'; Codehighlighter1_469_501_Open_Image.style.display='inline'; Codehighlighter1_469_501_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span 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">)</span><span id=Codehighlighter1_469_501_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_469_501_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rank[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pre[i]</span><span style="COLOR: #000000">=-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img id=Codehighlighter1_521_612_Open_Image onclick="this.style.display='none'; Codehighlighter1_521_612_Open_Text.style.display='none'; Codehighlighter1_521_612_Closed_Image.style.display='inline'; Codehighlighter1_521_612_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_521_612_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_521_612_Closed_Text.style.display='none'; Codehighlighter1_521_612_Open_Image.style.display='inline'; Codehighlighter1_521_612_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span 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">)</span><span id=Codehighlighter1_521_612_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_521_612_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">begin,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">end);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(find(begin)</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">find(end))<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unionone(begin,end);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&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">,n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span></div>
<img src ="http://www.cppblog.com/zhongguoa/aggbug/46789.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhongguoa/" target="_blank">zhongguoa</a> 2008-04-10 23:28 <a href="http://www.cppblog.com/zhongguoa/archive/2008/04/10/46789.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>归并求逆序数模板,pku 2299 Ultra-QuickSort,注意long long</title><link>http://www.cppblog.com/zhongguoa/archive/2008/04/09/46627.html</link><dc:creator>zhongguoa</dc:creator><author>zhongguoa</author><pubDate>Wed, 09 Apr 2008 04:54:00 GMT</pubDate><guid>http://www.cppblog.com/zhongguoa/archive/2008/04/09/46627.html</guid><wfw:comment>http://www.cppblog.com/zhongguoa/comments/46627.html</wfw:comment><comments>http://www.cppblog.com/zhongguoa/archive/2008/04/09/46627.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhongguoa/comments/commentRss/46627.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhongguoa/services/trackbacks/46627.html</trackback:ping><description><![CDATA[<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">&nbsp;MAXN&nbsp;500000</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;height[MAXN</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">],temp[MAXN</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>__int64&nbsp;sum;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img id=Codehighlighter1_126_473_Open_Image onclick="this.style.display='none'; Codehighlighter1_126_473_Open_Text.style.display='none'; Codehighlighter1_126_473_Closed_Image.style.display='inline'; Codehighlighter1_126_473_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_126_473_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_126_473_Closed_Text.style.display='none'; Codehighlighter1_126_473_Open_Image.style.display='inline'; Codehighlighter1_126_473_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;merge(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">a,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;l,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;mid,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;r)&nbsp;</span><span id=Codehighlighter1_126_473_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_126_473_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,j,k;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">l,k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">mid;<br><img id=Codehighlighter1_189_320_Open_Image onclick="this.style.display='none'; Codehighlighter1_189_320_Open_Text.style.display='none'; Codehighlighter1_189_320_Closed_Image.style.display='inline'; Codehighlighter1_189_320_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_189_320_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_189_320_Closed_Text.style.display='none'; Codehighlighter1_189_320_Open_Image.style.display='inline'; Codehighlighter1_189_320_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">mid&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">k&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">r)&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_189_320_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_189_320_Open_Text><span style="COLOR: #000000">{<br><img id=Codehighlighter1_213_281_Open_Image onclick="this.style.display='none'; Codehighlighter1_213_281_Open_Text.style.display='none'; Codehighlighter1_213_281_Closed_Image.style.display='inline'; Codehighlighter1_213_281_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_213_281_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_213_281_Closed_Text.style.display='none'; Codehighlighter1_213_281_Open_Image.style.display='inline'; Codehighlighter1_213_281_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a[j]</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">a[k])&nbsp;</span><span id=Codehighlighter1_213_281_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_213_281_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum&nbsp;</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">&nbsp;mid</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">j;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;temp[i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;a[k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;temp[i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;a[j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">mid)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;temp[i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;a[j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(k</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">r)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;temp[i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;a[k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&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">;&nbsp;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">r</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">l;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;a[l</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;temp[i];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img id=Codehighlighter1_507_635_Open_Image onclick="this.style.display='none'; Codehighlighter1_507_635_Open_Text.style.display='none'; Codehighlighter1_507_635_Closed_Image.style.display='inline'; Codehighlighter1_507_635_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_507_635_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_507_635_Closed_Text.style.display='none'; Codehighlighter1_507_635_Open_Image.style.display='inline'; Codehighlighter1_507_635_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;divide(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">a,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;l,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;r)&nbsp;</span><span id=Codehighlighter1_507_635_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_507_635_Open_Text><span style="COLOR: #000000">{<br><img id=Codehighlighter1_523_633_Open_Image onclick="this.style.display='none'; Codehighlighter1_523_633_Open_Text.style.display='none'; Codehighlighter1_523_633_Closed_Image.style.display='inline'; Codehighlighter1_523_633_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_523_633_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_523_633_Closed_Text.style.display='none'; Codehighlighter1_523_633_Open_Image.style.display='inline'; Codehighlighter1_523_633_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(l</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">r)&nbsp;</span><span id=Codehighlighter1_523_633_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_523_633_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;mid&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(l</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">r)</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;divide(a,l,mid);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;divide(a,mid,r);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;merge(a,l,mid,r);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img id=Codehighlighter1_649_816_Open_Image onclick="this.style.display='none'; Codehighlighter1_649_816_Open_Text.style.display='none'; Codehighlighter1_649_816_Closed_Image.style.display='inline'; Codehighlighter1_649_816_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_649_816_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_649_816_Closed_Text.style.display='none'; Codehighlighter1_649_816_Open_Image.style.display='inline'; Codehighlighter1_649_816_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()&nbsp;</span><span id=Codehighlighter1_649_816_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_649_816_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,i;<br><img id=Codehighlighter1_693_814_Open_Image onclick="this.style.display='none'; Codehighlighter1_693_814_Open_Text.style.display='none'; Codehighlighter1_693_814_Closed_Image.style.display='inline'; Codehighlighter1_693_814_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_693_814_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_693_814_Closed_Text.style.display='none'; Codehighlighter1_693_814_Open_Image.style.display='inline'; Codehighlighter1_693_814_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">n)</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">n)&nbsp;</span><span id=Codehighlighter1_693_814_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_693_814_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">sum</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">)&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">height[i]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;divide(height,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,n);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%I64d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,sum);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span></div>
<img src ="http://www.cppblog.com/zhongguoa/aggbug/46627.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhongguoa/" target="_blank">zhongguoa</a> 2008-04-09 12:54 <a href="http://www.cppblog.com/zhongguoa/archive/2008/04/09/46627.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>最小公共子序列</title><link>http://www.cppblog.com/zhongguoa/archive/2008/04/08/46500.html</link><dc:creator>zhongguoa</dc:creator><author>zhongguoa</author><pubDate>Tue, 08 Apr 2008 05:27:00 GMT</pubDate><guid>http://www.cppblog.com/zhongguoa/archive/2008/04/08/46500.html</guid><wfw:comment>http://www.cppblog.com/zhongguoa/comments/46500.html</wfw:comment><comments>http://www.cppblog.com/zhongguoa/archive/2008/04/08/46500.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhongguoa/comments/commentRss/46500.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhongguoa/services/trackbacks/46500.html</trackback:ping><description><![CDATA[<h1>
<h1>Longest Common Subsequence</h1>
</h1>
<h1>Problem</h1>
Given a sequence A = &lt; a1, a2, ..., am &gt;, let sequence B = &lt; b1, b2, ..., bk &gt; be a subsequence of A if there exists a strictly increasing sequence ( i1&lt;i2&lt;i3 ..., ik ) of indices of A such that for all j = 1,2,...,k, aij = bj. For example, B = &lt; a, b, c, d &gt; is a subsequence of A= &lt; a, b, c, f, d, c &gt; with index sequence &lt; 1, 2, 3 ,5 &gt;.<br>Given two sequences X and Y, you need to find the length of the longest common subsequence of X and Y.<br>
<h1>Input</h1>
The input may contain several test cases.<br><br>The first line of each test case contains two integers N (the length of X) and M(the length of Y), The second line contains the sequence X, the third line contains the sequence Y, X and Y will be composed only from lowercase letters. (1&lt;=N, M&lt;=100)<br><br>Input is terminated by EOF.
<h1>Output</h1>
Output the length of the longest common subsequence of X and Y on a single line for each test case.<br>
<h1>Sample input</h1>
<tt>6 4<br>abcfdc<br>abcd<br>2 2<br>ab<br>cd</tt><br>
<h1>Sample output</h1>
<tt>4<br>0<br><br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;x[</span><span style="COLOR: #000000">105</span><span style="COLOR: #000000">],y[</span><span style="COLOR: #000000">105</span><span style="COLOR: #000000">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;c[</span><span style="COLOR: #000000">109</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">109</span><span style="COLOR: #000000">],i,j,leny,lenx;<br><img id=Codehighlighter1_80_489_Open_Image onclick="this.style.display='none'; Codehighlighter1_80_489_Open_Text.style.display='none'; Codehighlighter1_80_489_Closed_Image.style.display='inline'; Codehighlighter1_80_489_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_80_489_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_80_489_Closed_Text.style.display='none'; Codehighlighter1_80_489_Open_Image.style.display='inline'; Codehighlighter1_80_489_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()</span><span id=Codehighlighter1_80_489_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_80_489_Open_Text><span style="COLOR: #000000">{<br><img id=Codehighlighter1_121_476_Open_Image onclick="this.style.display='none'; Codehighlighter1_121_476_Open_Text.style.display='none'; Codehighlighter1_121_476_Closed_Image.style.display='inline'; Codehighlighter1_121_476_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_121_476_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_121_476_Closed_Text.style.display='none'; Codehighlighter1_121_476_Open_Image.style.display='inline'; Codehighlighter1_121_476_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d&nbsp;%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">lenx,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">leny)</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">EOF)</span><span id=Codehighlighter1_121_476_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_121_476_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%s</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">x);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%s</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">y);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">leny;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">][i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">lenx;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img id=Codehighlighter1_255_440_Open_Image onclick="this.style.display='none'; Codehighlighter1_255_440_Open_Text.style.display='none'; Codehighlighter1_255_440_Closed_Image.style.display='inline'; Codehighlighter1_255_440_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_255_440_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_255_440_Closed_Text.style.display='none'; Codehighlighter1_255_440_Open_Image.style.display='inline'; Codehighlighter1_255_440_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span 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">lenx;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)</span><span id=Codehighlighter1_255_440_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_255_440_Open_Text><span style="COLOR: #000000">{<br><img id=Codehighlighter1_280_436_Open_Image onclick="this.style.display='none'; Codehighlighter1_280_436_Open_Text.style.display='none'; Codehighlighter1_280_436_Closed_Image.style.display='inline'; Codehighlighter1_280_436_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_280_436_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_280_436_Closed_Text.style.display='none'; Codehighlighter1_280_436_Open_Image.style.display='inline'; Codehighlighter1_280_436_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">leny;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)</span><span id=Codehighlighter1_280_436_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_280_436_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(x[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">y[j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">c[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">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br><img id=Codehighlighter1_341_431_Open_Image onclick="this.style.display='none'; Codehighlighter1_341_431_Open_Text.style.display='none'; Codehighlighter1_341_431_Closed_Image.style.display='inline'; Codehighlighter1_341_431_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_341_431_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_341_431_Closed_Text.style.display='none'; Codehighlighter1_341_431_Open_Image.style.display='inline'; Codehighlighter1_341_431_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span id=Codehighlighter1_341_431_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_341_431_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(c[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j]</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">c[i][j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">c[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;c[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">c[i][j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&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">,c[lenx][leny]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span></div>
</tt>
<img src ="http://www.cppblog.com/zhongguoa/aggbug/46500.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhongguoa/" target="_blank">zhongguoa</a> 2008-04-08 13:27 <a href="http://www.cppblog.com/zhongguoa/archive/2008/04/08/46500.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>最大公约数函数gcd(int a,int b)的构造和ax=b (mod n) 的解</title><link>http://www.cppblog.com/zhongguoa/archive/2008/04/08/46498.html</link><dc:creator>zhongguoa</dc:creator><author>zhongguoa</author><pubDate>Tue, 08 Apr 2008 04:53:00 GMT</pubDate><guid>http://www.cppblog.com/zhongguoa/archive/2008/04/08/46498.html</guid><wfw:comment>http://www.cppblog.com/zhongguoa/comments/46498.html</wfw:comment><comments>http://www.cppblog.com/zhongguoa/archive/2008/04/08/46498.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/zhongguoa/comments/commentRss/46498.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhongguoa/services/trackbacks/46498.html</trackback:ping><description><![CDATA[<h1>Problem</h1>
Give you a modular equation ax=b (mod n). Count how many different x (0&lt;=x&lt;n) satisfying the equation.<br><br>
<h1>Input</h1>
The input may contain several test cases.<br><br>Each test contains a line with three integers a, b and n, each integer is positive and no more than 10^9.<br><br>Input is terminated by EOF.<br>
<h1>Output</h1>
For each test case, output a line containing the number of solutions.<br><br>
<h1>Sample input</h1>
<tt>4 2 6<br></tt><br>
<h1>Sample output</h1>
<tt>2</tt><br><br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;a,b,n;<br><img id=Codehighlighter1_53_141_Open_Image onclick="this.style.display='none'; Codehighlighter1_53_141_Open_Text.style.display='none'; Codehighlighter1_53_141_Closed_Image.style.display='inline'; Codehighlighter1_53_141_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_53_141_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_53_141_Closed_Text.style.display='none'; Codehighlighter1_53_141_Open_Image.style.display='inline'; Codehighlighter1_53_141_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;gcd(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;a,</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;b)</span><span id=Codehighlighter1_53_141_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_53_141_Open_Text><span style="COLOR: #000000">{<br><img id=Codehighlighter1_67_91_Open_Image onclick="this.style.display='none'; Codehighlighter1_67_91_Open_Text.style.display='none'; Codehighlighter1_67_91_Closed_Image.style.display='inline'; Codehighlighter1_67_91_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_67_91_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_67_91_Closed_Text.style.display='none'; Codehighlighter1_67_91_Open_Image.style.display='inline'; Codehighlighter1_67_91_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)</span><span id=Codehighlighter1_67_91_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_67_91_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;b;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br><img id=Codehighlighter1_106_139_Open_Image onclick="this.style.display='none'; Codehighlighter1_106_139_Open_Text.style.display='none'; Codehighlighter1_106_139_Closed_Image.style.display='inline'; Codehighlighter1_106_139_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_106_139_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_106_139_Closed_Text.style.display='none'; Codehighlighter1_106_139_Open_Image.style.display='inline'; Codehighlighter1_106_139_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_106_139_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_106_139_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;gcd(b</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">a,a);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img id=Codehighlighter1_153_325_Open_Image onclick="this.style.display='none'; Codehighlighter1_153_325_Open_Text.style.display='none'; Codehighlighter1_153_325_Closed_Image.style.display='inline'; Codehighlighter1_153_325_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_153_325_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_153_325_Closed_Text.style.display='none'; Codehighlighter1_153_325_Open_Image.style.display='inline'; Codehighlighter1_153_325_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()</span><span id=Codehighlighter1_153_325_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_153_325_Open_Text><span style="COLOR: #000000">{<br><img id=Codehighlighter1_197_309_Open_Image onclick="this.style.display='none'; Codehighlighter1_197_309_Open_Text.style.display='none'; Codehighlighter1_197_309_Closed_Image.style.display='inline'; Codehighlighter1_197_309_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_197_309_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_197_309_Closed_Text.style.display='none'; Codehighlighter1_197_309_Open_Image.style.display='inline'; Codehighlighter1_197_309_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d&nbsp;%d&nbsp;%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">b,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">n)</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">EOF)</span><span id=Codehighlighter1_197_309_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_197_309_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;d</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">gcd(a,n);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(b</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">d</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&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">,d);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">0\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,d);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span></div>
<img src ="http://www.cppblog.com/zhongguoa/aggbug/46498.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhongguoa/" target="_blank">zhongguoa</a> 2008-04-08 12:53 <a href="http://www.cppblog.com/zhongguoa/archive/2008/04/08/46498.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>