﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-wyh123-文章分类-数论</title><link>http://www.cppblog.com/wyh123/category/17423.html</link><description /><language>zh-cn</language><lastBuildDate>Mon, 01 Aug 2011 22:17:50 GMT</lastBuildDate><pubDate>Mon, 01 Aug 2011 22:17:50 GMT</pubDate><ttl>60</ttl><item><title>Catanlan数</title><link>http://www.cppblog.com/wyh123/articles/152103.html</link><dc:creator>wyh</dc:creator><author>wyh</author><pubDate>Sat, 30 Jul 2011 15:32:00 GMT</pubDate><guid>http://www.cppblog.com/wyh123/articles/152103.html</guid><wfw:comment>http://www.cppblog.com/wyh123/comments/152103.html</wfw:comment><comments>http://www.cppblog.com/wyh123/articles/152103.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wyh123/comments/commentRss/152103.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wyh123/services/trackbacks/152103.html</trackback:ping><description><![CDATA[这两天，做了四五道关于卡塔兰数的问题，觉得应该总结一下吧。<br /><br />关于卡塔兰数的一些介绍：<a href="http://www.cppblog.com/MiYu/archive/2010/08/07/122573.html">http://www.cppblog.com/MiYu/archive/2010/08/07/122573.html</a><br /><br />1）卡塔兰数是组合数学中一个常出现在各种计数问题中出现的数例。由比利时的数学家欧仁&#183;查理&#183;卡塔兰（1814-1894）命名。<br />2）卡塔兰数是由递推公式而来，其递推公式如下：<br />&nbsp;&nbsp;&nbsp; 　<strong>h(n)= h(0)*h(n-1) + h(1)*h(n-2) + ... + h(n-1)h(0) (其中n&gt;=2);<br /></strong>&nbsp;　　<strong>还可以化简为1阶递推关系: 如h(n)=(4n-2)/(n+1)*h(n-1)(n&gt;1) h(0)=1<br /></strong>&nbsp;　　<strong>通项式是</strong>：<strong>h(n)=</strong> <strong>C(2n,n)/(n+1)=P(2n,n)/(n+1)!=(2n)!/(n!*(n+1)1!) </strong><strong>(n=1,2,3,...)</strong> 　<br />3）最近做的题目，应用到卡塔兰数主要的有：<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1、n个点组成二叉树的种类<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2、一个栈的进出栈的方案总数<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3、一个圆内2*n个点两两连线且不相互交叉的方案数<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4、正n边形用对角线割分成三角形的方案数<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5、P=a1*a2*......*an加括号的不同方案数<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6、2n个物品分成a,b两种，且a个数小于b的方案数。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .................<br /><br />&nbsp;&nbsp; *这些只是我最近所见到的，但是还有更多的类型等着去发现，最最重要的是能够根据题目的描述得到递推式，再由递推式得到有关卡塔兰数的规律。<br /><br />4）题目：poj 2084 HDOJ 1134 HDOJ 1131 HDOJ 1130<br /><br />.....<br />这里面最重要的还是有关高精度的处理，附上MIYU的模版一份 
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;MAX&nbsp;105</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;BASE&nbsp;10000</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />typedef&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;myType[MAX</span><span style="color: #000000">+</span><span style="color: #000000">10</span><span style="color: #000000">];<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;multiply&nbsp;(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[],&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;Max,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;b&nbsp;)&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">大数乘小数</span><span style="color: #008000"><br /></span><span style="color: #008080">11</span><span style="color: #008000"><img id="Codehighlighter1_214_347_Open_Image" onclick="this.style.display='none'; Codehighlighter1_214_347_Open_Text.style.display='none'; Codehighlighter1_214_347_Closed_Image.style.display='inline'; Codehighlighter1_214_347_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_214_347_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_214_347_Closed_Text.style.display='none'; Codehighlighter1_214_347_Open_Image.style.display='inline'; Codehighlighter1_214_347_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_214_347_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_214_347_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i,array</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(i</span><span style="color: #000000">=</span><span style="color: #000000">Max</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">&gt;=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i</span><span style="color: #000000">--</span><span style="color: #000000">)<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img id="Codehighlighter1_266_345_Open_Image" onclick="this.style.display='none'; Codehighlighter1_266_345_Open_Text.style.display='none'; Codehighlighter1_266_345_Closed_Image.style.display='inline'; Codehighlighter1_266_345_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_266_345_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_266_345_Closed_Text.style.display='none'; Codehighlighter1_266_345_Open_Image.style.display='inline'; Codehighlighter1_266_345_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_266_345_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_266_345_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array</span><span style="color: #000000">+=</span><span style="color: #000000">b</span><span style="color: #000000">*</span><span style="color: #000000">a[i];<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[i]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;array</span><span style="color: #000000">%</span><span style="color: #000000">BASE;<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array&nbsp;</span><span style="color: #000000">/=</span><span style="color: #000000">&nbsp;BASE;<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">18</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">19</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;divide&nbsp;(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[],&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;Max,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;b&nbsp;)&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">大数除小数</span><span style="color: #008000"><br /></span><span style="color: #008080">20</span><span style="color: #008000"><img id="Codehighlighter1_398_527_Open_Image" onclick="this.style.display='none'; Codehighlighter1_398_527_Open_Text.style.display='none'; Codehighlighter1_398_527_Closed_Image.style.display='inline'; Codehighlighter1_398_527_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_398_527_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_398_527_Closed_Text.style.display='none'; Codehighlighter1_398_527_Open_Image.style.display='inline'; Codehighlighter1_398_527_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_398_527_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_398_527_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i,div</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">Max;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img id="Codehighlighter1_446_525_Open_Image" onclick="this.style.display='none'; Codehighlighter1_446_525_Open_Text.style.display='none'; Codehighlighter1_446_525_Closed_Image.style.display='inline'; Codehighlighter1_446_525_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_446_525_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_446_525_Closed_Text.style.display='none'; Codehighlighter1_446_525_Open_Image.style.display='inline'; Codehighlighter1_446_525_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_446_525_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_446_525_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;div&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;div</span><span style="color: #000000">*</span><span style="color: #000000">BASE&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;a[i];<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[i]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;div&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;b;<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;div&nbsp;</span><span style="color: #000000">%=</span><span style="color: #000000">&nbsp;b;<br /></span><span style="color: #008080">27</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">28</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">29</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;outPut&nbsp;(&nbsp;myType&nbsp;ctl[MAX]&nbsp;,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;N&nbsp;)<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img id="Codehighlighter1_568_796_Open_Image" onclick="this.style.display='none'; Codehighlighter1_568_796_Open_Text.style.display='none'; Codehighlighter1_568_796_Closed_Image.style.display='inline'; Codehighlighter1_568_796_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_568_796_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_568_796_Closed_Text.style.display='none'; Codehighlighter1_568_796_Open_Image.style.display='inline'; Codehighlighter1_568_796_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_568_796_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_568_796_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">31</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;(&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;MAX&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;ctl[N][i]&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;)<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img id="Codehighlighter1_632_666_Open_Image" onclick="this.style.display='none'; Codehighlighter1_632_666_Open_Text.style.display='none'; Codehighlighter1_632_666_Closed_Image.style.display='inline'; Codehighlighter1_632_666_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_632_666_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_632_666_Closed_Text.style.display='none'; Codehighlighter1_632_666_Open_Image.style.display='inline'; Codehighlighter1_632_666_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_632_666_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_632_666_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">去前导0</span><span style="color: #008000"><br /></span><span style="color: #008080">35</span><span style="color: #008000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">36</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;ctl[N][i</span><span style="color: #000000">++</span><span style="color: #000000">];<br /></span><span style="color: #008080">37</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;(&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;MAX&nbsp;)<br /></span><span style="color: #008080">38</span><span style="color: #000000"><img id="Codehighlighter1_722_775_Open_Image" onclick="this.style.display='none'; Codehighlighter1_722_775_Open_Text.style.display='none'; Codehighlighter1_722_775_Closed_Image.style.display='inline'; Codehighlighter1_722_775_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_722_775_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_722_775_Closed_Text.style.display='none'; Codehighlighter1_722_775_Open_Image.style.display='inline'; Codehighlighter1_722_775_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_722_775_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_722_775_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">39</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" /><br /></span><span style="color: #008080">40</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf&nbsp;(&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">%04d</span><span style="color: #000000">"</span><span style="color: #000000">,&nbsp;ctl[N][i</span><span style="color: #000000">++</span><span style="color: #000000">]&nbsp;);<br /></span><span style="color: #008080">41</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">42</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /></span><span style="color: #008080">43</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">44</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;setNum&nbsp;(&nbsp;myType&nbsp;ctl[MAX]&nbsp;)<br /></span><span style="color: #008080">45</span><span style="color: #000000"><img id="Codehighlighter1_830_1103_Open_Image" onclick="this.style.display='none'; Codehighlighter1_830_1103_Open_Text.style.display='none'; Codehighlighter1_830_1103_Closed_Image.style.display='inline'; Codehighlighter1_830_1103_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_830_1103_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_830_1103_Closed_Text.style.display='none'; Codehighlighter1_830_1103_Open_Image.style.display='inline'; Codehighlighter1_830_1103_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_830_1103_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_830_1103_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">46</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset&nbsp;(&nbsp;ctl[</span><span style="color: #000000">1</span><span style="color: #000000">],&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;MAX&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">&nbsp;(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;)&nbsp;);<br /></span><span style="color: #008080">47</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ctl[</span><span style="color: #000000">1</span><span style="color: #000000">][MAX</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">48</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">101</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br /></span><span style="color: #008080">49</span><span style="color: #000000"><img id="Codehighlighter1_948_1101_Open_Image" onclick="this.style.display='none'; Codehighlighter1_948_1101_Open_Text.style.display='none'; Codehighlighter1_948_1101_Closed_Image.style.display='inline'; Codehighlighter1_948_1101_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_948_1101_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_948_1101_Closed_Text.style.display='none'; Codehighlighter1_948_1101_Open_Image.style.display='inline'; Codehighlighter1_948_1101_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_948_1101_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_948_1101_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">50</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memcpy&nbsp;(&nbsp;ctl[i],&nbsp;ctl[i</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">],&nbsp;MAX&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">&nbsp;(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;)&nbsp;);<br /></span><span style="color: #008080">51</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;multiply&nbsp;(&nbsp;ctl[i],&nbsp;MAX,&nbsp;</span><span style="color: #000000">4</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">&nbsp;);<br /></span><span style="color: #008080">52</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;divide&nbsp;(&nbsp;ctl[i],&nbsp;MAX,&nbsp;i&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;);<br /></span><span style="color: #008080">53</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">54</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">55</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />myType&nbsp;ctl[MAX];<br /></span><span style="color: #008080">56</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">57</span><span style="color: #000000"><img id="Codehighlighter1_1133_1253_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1133_1253_Open_Text.style.display='none'; Codehighlighter1_1133_1253_Closed_Image.style.display='inline'; Codehighlighter1_1133_1253_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_1133_1253_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1133_1253_Closed_Text.style.display='none'; Codehighlighter1_1133_1253_Open_Image.style.display='inline'; Codehighlighter1_1133_1253_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1133_1253_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_1133_1253_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">58</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;setNum&nbsp;(&nbsp;ctl&nbsp;);<br /></span><span style="color: #008080">59</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;N;<br /></span><span style="color: #008080">60</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;(&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;N&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;这里根据各题要求需要做相应变化</span><span style="color: #008000"><br /></span><span style="color: #008080">61</span><span style="color: #008000"><img id="Codehighlighter1_1216_1237_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1216_1237_Open_Text.style.display='none'; Codehighlighter1_1216_1237_Closed_Image.style.display='inline'; Codehighlighter1_1216_1237_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1216_1237_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1216_1237_Closed_Text.style.display='none'; Codehighlighter1_1216_1237_Open_Image.style.display='inline'; Codehighlighter1_1216_1237_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif"></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1216_1237_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_1216_1237_Open_Text"><span style="color: #000000">{&nbsp;outPut&nbsp;(&nbsp;ctl,&nbsp;N&nbsp;);&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">62</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">63</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">64</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span></div><br /><img src ="http://www.cppblog.com/wyh123/aggbug/152103.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wyh123/" target="_blank">wyh</a> 2011-07-30 23:32 <a href="http://www.cppblog.com/wyh123/articles/152103.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>