﻿<?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>IT博客-尘封阁-随笔分类-零件仓库</title><link>http://www.cnitblog.com/cockerel/category/3075.html</link><description>多想相邀再次喝酒，待葡萄成熟透</description><language>zh-cn</language><lastBuildDate>Mon, 26 Sep 2011 06:40:10 GMT</lastBuildDate><pubDate>Mon, 26 Sep 2011 06:40:10 GMT</pubDate><ttl>60</ttl><item><title>博客插件小仓库(不断积累中……)</title><link>http://www.cnitblog.com/cockerel/archive/2007/05/31/27879.html</link><dc:creator>踏雪赤兔</dc:creator><author>踏雪赤兔</author><pubDate>Thu, 31 May 2007 15:58:00 GMT</pubDate><guid>http://www.cnitblog.com/cockerel/archive/2007/05/31/27879.html</guid><wfw:comment>http://www.cnitblog.com/cockerel/comments/27879.html</wfw:comment><comments>http://www.cnitblog.com/cockerel/archive/2007/05/31/27879.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cnitblog.com/cockerel/comments/commentRss/27879.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/cockerel/services/trackbacks/27879.html</trackback:ping><description><![CDATA[&nbsp;
<p><img height=115 alt=看贴是一种支持，回贴是一种美德 hspace=0 src="http://www.cnitblog.com/images/cnitblog_com/cockerel/3488/o_thx4re.jpg" width=150></p>
<script language="javascript" type="text/javascript" src="http://stat.ourplus.com/getpagerank/pagerank.js"></script><a href="http://www.cnitblog.com/cockerel/Rss.aspx"><img style="MARGIN-BOTTOM: 3px" alt=订阅我的博客 src="http://www.feedsky.com/images/icon_sub_c1s4.gif" vspace=2 border=0></a><br><a href="http://www.zhuaxia.com/add_channel.php?url=http://www.cnitblog.com/cockerel/Rss.aspx"><img style="MARGIN-BOTTOM: 3px" alt=订阅到抓虾 src="http://www.feedsky.com/images/icon_subscribe_zhuaxia_fs.gif" vspace=2 border=0></a><br><a href="http://fusion.google.com/add?feedurl=http://www.cnitblog.com/cockerel/Rss.aspx"><img style="MARGIN-BOTTOM: 3px" alt=订阅到google src="http://www.feedsky.com/images/icon_subscribe_google_fs.gif" vspace=2 border=0></a> <script language="javascript" type="text/javascript" src="http://www.feedsky.com/msub_ajax_sub_js.html?burl=acumon&t=1&c=gray"></script><input onclick="javascript:window.external.addFavorite('http://www.cnitblog.com/cockerel/','晓鸣的博客：百宝箱')" type=button value=收藏我的博客 name=add>&nbsp;
<p>&nbsp;<a href="tencent://message/?uin=38136419&amp;Site=http://www.cnitblog.com/cockerel&amp;Menu=yes" target=blank><img alt=点击这里给我发消息 src="http://wpa.qq.com/pa?p=1:38136419:11" border=0></a> <a id=clustrMapsLink href="http://clustrmaps.com/counter/maps.php?url=http://www.cnitblog.com/cockerel"><img alt="Locations of visitors to this page" onerror="this.onError=null; this.src='http://www.meetomatic.com/images/clustrmaps-back-soon.jpg'; document.getElementById('clustrMapsLink').href='http://clustrmaps.com/'" src="http://clustrmaps.com/counter/index2.php?url=http://www.cnitblog.com/cockerel" border=1> </a>博客地图 <script language="javascript" src="http://blog.mapbar.com/blogmap/mapjs.jsp?nid=07040822202701000698&width=170&height=303"></script></p><img src ="http://www.cnitblog.com/cockerel/aggbug/27879.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/cockerel/" target="_blank">踏雪赤兔</a> 2007-05-31 23:58 <a href="http://www.cnitblog.com/cockerel/archive/2007/05/31/27879.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>纯flash网站设计(不断完善中~~)</title><link>http://www.cnitblog.com/cockerel/archive/2006/08/09/15003.html</link><dc:creator>踏雪赤兔</dc:creator><author>踏雪赤兔</author><pubDate>Wed, 09 Aug 2006 04:59:00 GMT</pubDate><guid>http://www.cnitblog.com/cockerel/archive/2006/08/09/15003.html</guid><wfw:comment>http://www.cnitblog.com/cockerel/comments/15003.html</wfw:comment><comments>http://www.cnitblog.com/cockerel/archive/2006/08/09/15003.html#Feedback</comments><slash:comments>10</slash:comments><wfw:commentRss>http://www.cnitblog.com/cockerel/comments/commentRss/15003.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/cockerel/services/trackbacks/15003.html</trackback:ping><description><![CDATA[
		<script src="/Files/cockerel/web.js.rar">
		</script>
		<p>注：因此flash经常更新，为保证各位看到的都是最新版，采用了无缓存技术，所以显示该页面需要一些时间，请耐心等待。<br />心得及更新日志：<br /><br /><strong><u>2006年8月9日</u><br /></strong>发现将swf、js文件改名为rar后直接上传到此博客<br />发现可以用以下代码发布flash</p>
		<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.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">object</span>
				<span style="COLOR: #0000ff">&gt;&lt;</span>
				<span style="COLOR: #800000">embed </span>
				<span style="COLOR: #ff0000">src</span>
				<span style="COLOR: #0000ff">="FLASH_URL"</span>
				<span style="COLOR: #ff0000"> width</span>
				<span style="COLOR: #0000ff">="500"</span>
				<span style="COLOR: #ff0000"> height</span>
				<span style="COLOR: #0000ff">="680"</span>
				<span style="COLOR: #ff0000"> quality</span>
				<span style="COLOR: #0000ff">="high"</span>
				<span style="COLOR: #ff0000"> pluginspage</span>
				<span style="COLOR: #0000ff">="http://www.macromedia.com/go/getflashplayer"</span>
				<span style="COLOR: #ff0000"> type</span>
				<span style="COLOR: #0000ff">="application/x-shockwave-flash"</span>
				<span style="COLOR: #ff0000"> scale</span>
				<span style="COLOR: #0000ff">="exactfit"</span>
				<span style="COLOR: #0000ff">&gt;&lt;/</span>
				<span style="COLOR: #800000">embed</span>
				<span style="COLOR: #0000ff">&gt;&lt;/</span>
				<span style="COLOR: #800000">object</span>
				<span style="COLOR: #0000ff">&gt;</span>
		</div>
		<br />
		<p>发现flash不会每次重新下载，想到用添加随机冗余变量解决<br />发现此博客不支持JS，但可以引用.js文件<br />更新结果：成功发布flash，并使客户每次浏览时都重新下载。<br /><br /><br /></p>
<img src ="http://www.cnitblog.com/cockerel/aggbug/15003.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/cockerel/" target="_blank">踏雪赤兔</a> 2006-08-09 12:59 <a href="http://www.cnitblog.com/cockerel/archive/2006/08/09/15003.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>标程：位容器</title><link>http://www.cnitblog.com/cockerel/archive/2006/07/18/13823.html</link><dc:creator>踏雪赤兔</dc:creator><author>踏雪赤兔</author><pubDate>Tue, 18 Jul 2006 09:49:00 GMT</pubDate><guid>http://www.cnitblog.com/cockerel/archive/2006/07/18/13823.html</guid><wfw:comment>http://www.cnitblog.com/cockerel/comments/13823.html</wfw:comment><comments>http://www.cnitblog.com/cockerel/archive/2006/07/18/13823.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnitblog.com/cockerel/comments/commentRss/13823.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/cockerel/services/trackbacks/13823.html</trackback:ping><description><![CDATA[
		<p> </p>
		<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.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#include</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">cstdio</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img id="Codehighlighter1_27_826_Open_Image" onclick="this.style.display='none'; Codehighlighter1_27_826_Open_Text.style.display='none'; Codehighlighter1_27_826_Closed_Image.style.display='inline'; Codehighlighter1_27_826_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_27_826_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_27_826_Closed_Text.style.display='none'; Codehighlighter1_27_826_Open_Image.style.display='inline'; Codehighlighter1_27_826_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> Bits</span>
				<span id="Codehighlighter1_27_826_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.cnitblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_27_826_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> n;</span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">底层容器，可选int或long long</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000">:<br /><img id="Codehighlighter1_80_86_Open_Image" onclick="this.style.display='none'; Codehighlighter1_80_86_Open_Text.style.display='none'; Codehighlighter1_80_86_Closed_Image.style.display='inline'; Codehighlighter1_80_86_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_80_86_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_80_86_Closed_Text.style.display='none'; Codehighlighter1_80_86_Open_Image.style.display='inline'; Codehighlighter1_80_86_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> clear()</span>
						<span id="Codehighlighter1_80_86_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_80_86_Open_Text">
								<span style="COLOR: #000000">{ n</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">;}</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_119_218_Open_Image" onclick="this.style.display='none'; Codehighlighter1_119_218_Open_Text.style.display='none'; Codehighlighter1_119_218_Closed_Image.style.display='inline'; Codehighlighter1_119_218_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_119_218_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_119_218_Closed_Text.style.display='none'; Codehighlighter1_119_218_Open_Image.style.display='inline'; Codehighlighter1_119_218_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">set</span>
						<span style="COLOR: #000000">(</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> b, </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> e, </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> num)</span>
						<span id="Codehighlighter1_119_218_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_119_218_Open_Text">
								<span style="COLOR: #000000">{</span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">将num的[0,e-b)位复制到n的[b,e)位</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        n</span>
								<span style="COLOR: #000000">|=</span>
								<span style="COLOR: #000000">num</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">b </span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000"> (</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">e)</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">b);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> n</span>
								<span style="COLOR: #000000">&amp;=</span>
								<span style="COLOR: #000000">num</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">b </span>
								<span style="COLOR: #000000">|</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">~</span>
								<span style="COLOR: #000000">( (</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">e)</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">b) );<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_252_339_Open_Image" onclick="this.style.display='none'; Codehighlighter1_252_339_Open_Text.style.display='none'; Codehighlighter1_252_339_Closed_Image.style.display='inline'; Codehighlighter1_252_339_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_252_339_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_252_339_Closed_Text.style.display='none'; Codehighlighter1_252_339_Open_Image.style.display='inline'; Codehighlighter1_252_339_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">set</span>
						<span style="COLOR: #000000">(</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> b, </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> e, </span>
						<span style="COLOR: #0000ff">bool</span>
						<span style="COLOR: #000000"> bit)</span>
						<span id="Codehighlighter1_252_339_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_252_339_Open_Text">
								<span style="COLOR: #000000">{</span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">填充位</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">(bit)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> n</span>
								<span style="COLOR: #000000">|=</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">e)</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">b); <br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> n</span>
								<span style="COLOR: #000000">&amp;=~</span>
								<span style="COLOR: #000000">( (</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">e)</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">b) );<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_363_406_Open_Image" onclick="this.style.display='none'; Codehighlighter1_363_406_Open_Text.style.display='none'; Codehighlighter1_363_406_Closed_Image.style.display='inline'; Codehighlighter1_363_406_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_363_406_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_363_406_Closed_Text.style.display='none'; Codehighlighter1_363_406_Open_Image.style.display='inline'; Codehighlighter1_363_406_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">get</span>
						<span style="COLOR: #000000">(</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> b, </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> e)</span>
						<span id="Codehighlighter1_363_406_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_363_406_Open_Text">
								<span style="COLOR: #000000">{</span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">获取[b,e)位</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> n</span>
								<span style="COLOR: #000000">&gt;&gt;</span>
								<span style="COLOR: #000000">b </span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000"> (</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">(e</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">b))</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_430_471_Open_Image" onclick="this.style.display='none'; Codehighlighter1_430_471_Open_Text.style.display='none'; Codehighlighter1_430_471_Closed_Image.style.display='inline'; Codehighlighter1_430_471_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_430_471_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_430_471_Closed_Text.style.display='none'; Codehighlighter1_430_471_Open_Image.style.display='inline'; Codehighlighter1_430_471_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> not(</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> b, </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> e)</span>
						<span id="Codehighlighter1_430_471_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_430_471_Open_Text">
								<span style="COLOR: #000000">{</span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">将[b,e)位取反</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> n</span>
								<span style="COLOR: #000000">^=</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">e)</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">b);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_542_641_Open_Image" onclick="this.style.display='none'; Codehighlighter1_542_641_Open_Text.style.display='none'; Codehighlighter1_542_641_Closed_Image.style.display='inline'; Codehighlighter1_542_641_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_542_641_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_542_641_Closed_Text.style.display='none'; Codehighlighter1_542_641_Open_Image.style.display='inline'; Codehighlighter1_542_641_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    friend </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> concat(Bits bs1, </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> b1,</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> e1, Bits bs2, </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> b2, </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> e2)</span>
						<span id="Codehighlighter1_542_641_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_542_641_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">将bs1的[b1,e1)位与bs2的[b2,e2)位连接<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">依赖get()</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> bs1.</span>
								<span style="COLOR: #0000ff">get</span>
								<span style="COLOR: #000000">(b1,e1)</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">(e2</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">b2) </span>
								<span style="COLOR: #000000">|</span>
								<span style="COLOR: #000000"> bs2.</span>
								<span style="COLOR: #0000ff">get</span>
								<span style="COLOR: #000000">(b2,e2);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_655_824_Open_Image" onclick="this.style.display='none'; Codehighlighter1_655_824_Open_Text.style.display='none'; Codehighlighter1_655_824_Closed_Image.style.display='inline'; Codehighlighter1_655_824_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_655_824_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_655_824_Closed_Text.style.display='none'; Codehighlighter1_655_824_Open_Image.style.display='inline'; Codehighlighter1_655_824_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> show()</span>
						<span id="Codehighlighter1_655_824_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_655_824_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> i;<br /><img id="Codehighlighter1_668_741_Open_Image" onclick="this.style.display='none'; Codehighlighter1_668_741_Open_Text.style.display='none'; Codehighlighter1_668_741_Closed_Image.style.display='inline'; Codehighlighter1_668_741_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_668_741_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_668_741_Closed_Text.style.display='none'; Codehighlighter1_668_741_Open_Image.style.display='inline'; Codehighlighter1_668_741_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_668_741_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">/**/</span>
								<span id="Codehighlighter1_668_741_Open_Text">
										<span style="COLOR: #008000">/*</span>
										<span style="COLOR: #008000">for(i=0; i&lt;8*sizeof(n); ++i)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            printf("%d",i%10);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        putchar('\n');/*</span>
										<span style="COLOR: #008000">*/</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </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">8</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #0000ff">sizeof</span>
								<span style="COLOR: #000000">(n); </span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">i)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            printf(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">%d</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">,(n</span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">&lt;&lt;</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.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">putchar('\n');</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />
								</span>
								<span style="COLOR: #000000">    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
		</div>
<img src ="http://www.cnitblog.com/cockerel/aggbug/13823.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/cockerel/" target="_blank">踏雪赤兔</a> 2006-07-18 17:49 <a href="http://www.cnitblog.com/cockerel/archive/2006/07/18/13823.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>标程：判断一数是否2的幂数</title><link>http://www.cnitblog.com/cockerel/archive/2006/07/17/13769.html</link><dc:creator>踏雪赤兔</dc:creator><author>踏雪赤兔</author><pubDate>Mon, 17 Jul 2006 08:24:00 GMT</pubDate><guid>http://www.cnitblog.com/cockerel/archive/2006/07/17/13769.html</guid><wfw:comment>http://www.cnitblog.com/cockerel/comments/13769.html</wfw:comment><comments>http://www.cnitblog.com/cockerel/archive/2006/07/17/13769.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.cnitblog.com/cockerel/comments/commentRss/13769.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/cockerel/services/trackbacks/13769.html</trackback:ping><description><![CDATA[以我愚见，此可算是位操作的精品了。<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.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000"> is2Power(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_21_64_Open_Image" onclick="this.style.display='none'; Codehighlighter1_21_64_Open_Text.style.display='none'; Codehighlighter1_21_64_Closed_Image.style.display='inline'; Codehighlighter1_21_64_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_21_64_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_21_64_Closed_Text.style.display='none'; Codehighlighter1_21_64_Open_Image.style.display='inline'; Codehighlighter1_21_64_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_21_64_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.cnitblog.com/images/dot.gif" /></span><span id="Codehighlighter1_21_64_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> n </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000"> (n </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">n </span><span style="COLOR: #000000">+</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"> n;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div>2006年8月9日补充：<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 id="Codehighlighter1_27_50_Open_Image" onclick="this.style.display='none'; Codehighlighter1_27_50_Open_Text.style.display='none'; Codehighlighter1_27_50_Closed_Image.style.display='inline'; Codehighlighter1_27_50_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_27_50_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_27_50_Closed_Text.style.display='none'; Codehighlighter1_27_50_Open_Image.style.display='inline'; Codehighlighter1_27_50_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /><span style="COLOR: #000000">inline </span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000"> is2Power(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n)</span><span id="Codehighlighter1_27_50_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.cnitblog.com/images/dot.gif" /></span><span id="Codehighlighter1_27_50_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> n </span><span style="COLOR: #000000">&amp;&amp; !</span><span style="COLOR: #000000">(n</span><span style="COLOR: #000000">&amp;</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.cnitblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span></div>算法无止境啊~~~<img height="20" src="http://www.cnitblog.com/Emoticons/QQ/13.gif" width="20" border="0" /><img src ="http://www.cnitblog.com/cockerel/aggbug/13769.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/cockerel/" target="_blank">踏雪赤兔</a> 2006-07-17 16:24 <a href="http://www.cnitblog.com/cockerel/archive/2006/07/17/13769.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>标程：素数表 与 质因数分解</title><link>http://www.cnitblog.com/cockerel/archive/2006/07/11/13479.html</link><dc:creator>踏雪赤兔</dc:creator><author>踏雪赤兔</author><pubDate>Mon, 10 Jul 2006 16:24:00 GMT</pubDate><guid>http://www.cnitblog.com/cockerel/archive/2006/07/11/13479.html</guid><wfw:comment>http://www.cnitblog.com/cockerel/comments/13479.html</wfw:comment><comments>http://www.cnitblog.com/cockerel/archive/2006/07/11/13479.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/cockerel/comments/commentRss/13479.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/cockerel/services/trackbacks/13479.html</trackback:ping><description><![CDATA[
		<p>特别鸣谢飞飞提醒，生成素数表效率一下提高了40%之多!<br /></p>
		<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 id="Codehighlighter1_17_975_Open_Image" onclick="this.style.display='none'; Codehighlighter1_17_975_Open_Text.style.display='none'; Codehighlighter1_17_975_Closed_Image.style.display='inline'; Codehighlighter1_17_975_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
				<img id="Codehighlighter1_17_975_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_17_975_Closed_Text.style.display='none'; Codehighlighter1_17_975_Open_Image.style.display='inline'; Codehighlighter1_17_975_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> primeNS</span>
				<span id="Codehighlighter1_17_975_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.cnitblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_17_975_Open_Text">
						<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_20_135_Open_Image" onclick="this.style.display='none'; Codehighlighter1_20_135_Open_Text.style.display='none'; Codehighlighter1_20_135_Closed_Image.style.display='inline'; Codehighlighter1_20_135_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_20_135_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_20_135_Closed_Text.style.display='none'; Codehighlighter1_20_135_Open_Image.style.display='inline'; Codehighlighter1_20_135_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_20_135_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">/**/</span>
						<span id="Codehighlighter1_20_135_Open_Text">
								<span style="COLOR: #008000">/*</span>
								<span style="COLOR: #008000">解决：素数表<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />     *算法：筛法<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />     *输入：范围MaxN<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />     *输出：素数个数pp, 素数表[p[0],p[pp])<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />     *备注：效率:1千万时，sicily-0.59 ZOJ-0.85 (朴素版sicily1.00)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />     </span>
								<span style="COLOR: #008000">*/</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">const</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> MaxN</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">10000000</span>
						<span style="COLOR: #000000">; </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">查找[2,maxN]范围的素数</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    </span>
						<span style="COLOR: #0000ff">const</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> Len</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> MaxN</span>
						<span style="COLOR: #000000">/</span>
						<span style="COLOR: #000000">2</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_220_222_Open_Image" onclick="this.style.display='none'; Codehighlighter1_220_222_Open_Text.style.display='none'; Codehighlighter1_220_222_Closed_Image.style.display='inline'; Codehighlighter1_220_222_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_220_222_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_220_222_Closed_Text.style.display='none'; Codehighlighter1_220_222_Open_Image.style.display='inline'; Codehighlighter1_220_222_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> p[Len]</span>
						<span style="COLOR: #000000">=</span>
						<span id="Codehighlighter1_220_222_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_220_222_Open_Text">
								<span style="COLOR: #000000">{</span>
								<span style="COLOR: #000000">2</span>
								<span style="COLOR: #000000">}</span>
						</span>
						<span style="COLOR: #000000">    ,pp</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_243_482_Open_Image" onclick="this.style.display='none'; Codehighlighter1_243_482_Open_Text.style.display='none'; Codehighlighter1_243_482_Closed_Image.style.display='inline'; Codehighlighter1_243_482_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_243_482_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_243_482_Closed_Text.style.display='none'; Codehighlighter1_243_482_Open_Image.style.display='inline'; Codehighlighter1_243_482_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> init()</span>
						<span id="Codehighlighter1_243_482_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_243_482_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> i,j,cur;<br /><img id="Codehighlighter1_277_421_Open_Image" onclick="this.style.display='none'; Codehighlighter1_277_421_Open_Text.style.display='none'; Codehighlighter1_277_421_Closed_Image.style.display='inline'; Codehighlighter1_277_421_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_277_421_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_277_421_Closed_Text.style.display='none'; Codehighlighter1_277_421_Open_Image.style.display='inline'; Codehighlighter1_277_421_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </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">; ; </span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">i)</span>
								<span id="Codehighlighter1_277_421_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.cnitblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_277_421_Open_Text">
										<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_291_417_Open_Image" onclick="this.style.display='none'; Codehighlighter1_291_417_Open_Text.style.display='none'; Codehighlighter1_291_417_Closed_Image.style.display='inline'; Codehighlighter1_291_417_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_291_417_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_291_417_Closed_Text.style.display='none'; Codehighlighter1_291_417_Open_Image.style.display='inline'; Codehighlighter1_291_417_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000">(</span>
										<span style="COLOR: #000000">!</span>
										<span style="COLOR: #000000">p[i])</span>
										<span id="Codehighlighter1_291_417_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.cnitblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_291_417_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                p[pp</span>
												<span style="COLOR: #000000">++</span>
												<span style="COLOR: #000000">]</span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000">cur</span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000">i</span>
												<span style="COLOR: #000000">*</span>
												<span style="COLOR: #000000">2</span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">;</span>
												<span style="COLOR: #008000">//</span>
												<span style="COLOR: #008000">找到一个素数</span>
												<span style="COLOR: #008000">
														<br />
														<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												</span>
												<span style="COLOR: #000000">                </span>
												<span style="COLOR: #0000ff">for</span>
												<span style="COLOR: #000000">(j</span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000">2</span>
												<span style="COLOR: #000000">*</span>
												<span style="COLOR: #000000">i</span>
												<span style="COLOR: #000000">*</span>
												<span style="COLOR: #000000">(i</span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">); j</span>
												<span style="COLOR: #000000">&lt;</span>
												<span style="COLOR: #000000">Len; j</span>
												<span style="COLOR: #000000">+=</span>
												<span style="COLOR: #000000">cur)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    p[j]</span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span>
												<span style="COLOR: #0000ff">if</span>
												<span style="COLOR: #000000">(j</span>
												<span style="COLOR: #000000">==</span>
												<span style="COLOR: #000000">2</span>
												<span style="COLOR: #000000">*</span>
												<span style="COLOR: #000000">i</span>
												<span style="COLOR: #000000">*</span>
												<span style="COLOR: #000000">(i</span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">))</span>
												<span style="COLOR: #008000">//</span>
												<span style="COLOR: #008000">筛完，可照抄</span>
												<span style="COLOR: #008000">
														<br />
														<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												</span>
												<span style="COLOR: #000000">                    </span>
												<span style="COLOR: #0000ff">break</span>
												<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">i;i</span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000">Len; </span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">i)</span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">照抄</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">            </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #000000">!</span>
								<span style="COLOR: #000000">p[i])<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                p[pp</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">]</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">i</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">2</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_483_486_Open_Image" onclick="this.style.display='none'; Codehighlighter1_483_486_Open_Text.style.display='none'; Codehighlighter1_483_486_Closed_Image.style.display='inline'; Codehighlighter1_483_486_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_483_486_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_483_486_Closed_Text.style.display='none'; Codehighlighter1_483_486_Open_Image.style.display='inline'; Codehighlighter1_483_486_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    }</span>
						</span>
						<span id="Codehighlighter1_483_486_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">/**/</span>
						<span id="Codehighlighter1_483_486_Open_Text">
								<span style="COLOR: #008000">/**/</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_489_633_Open_Image" onclick="this.style.display='none'; Codehighlighter1_489_633_Open_Text.style.display='none'; Codehighlighter1_489_633_Closed_Image.style.display='inline'; Codehighlighter1_489_633_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_489_633_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_489_633_Closed_Text.style.display='none'; Codehighlighter1_489_633_Open_Image.style.display='inline'; Codehighlighter1_489_633_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_489_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">/**/</span>
						<span id="Codehighlighter1_489_633_Open_Text">
								<span style="COLOR: #008000">/*</span>
								<span style="COLOR: #008000">解决：质因数分解<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />     *算法：顺搜，逐个测试<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />     *输入：待分解数num, init()的输出<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />     *输出：质因数个数dp, 质因数表d[0<img src="http://www.cnitblog.com/images/dot.gif" />dp-1]，指数表e[0<img src="http://www.cnitblog.com/images/dot.gif" />dp-1];<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />     *备注：若num&gt;=MaxN^2,可能会将所有大于MaxN的质因数之积看作一质因数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />     </span>
								<span style="COLOR: #008000">*/</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> d[Len],e[Len],dp;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_687_973_Open_Image" onclick="this.style.display='none'; Codehighlighter1_687_973_Open_Text.style.display='none'; Codehighlighter1_687_973_Closed_Image.style.display='inline'; Codehighlighter1_687_973_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_687_973_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_687_973_Closed_Text.style.display='none'; Codehighlighter1_687_973_Open_Image.style.display='inline'; Codehighlighter1_687_973_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> factorization(</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> num)</span>
						<span id="Codehighlighter1_687_973_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_687_973_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> i,cnt,div;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        dp</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_733_927_Open_Image" onclick="this.style.display='none'; Codehighlighter1_733_927_Open_Text.style.display='none'; Codehighlighter1_733_927_Closed_Image.style.display='inline'; Codehighlighter1_733_927_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_733_927_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_733_927_Closed_Text.style.display='none'; Codehighlighter1_733_927_Open_Image.style.display='inline'; Codehighlighter1_733_927_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </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">pp;i</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">)</span>
								<span id="Codehighlighter1_733_927_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.cnitblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_733_927_Open_Text">
										<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_753_923_Open_Image" onclick="this.style.display='none'; Codehighlighter1_753_923_Open_Text.style.display='none'; Codehighlighter1_753_923_Closed_Image.style.display='inline'; Codehighlighter1_753_923_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_753_923_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_753_923_Closed_Text.style.display='none'; Codehighlighter1_753_923_Open_Image.style.display='inline'; Codehighlighter1_753_923_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000">(num</span>
										<span style="COLOR: #000000">%</span>
										<span style="COLOR: #000000">p[i]</span>
										<span style="COLOR: #000000">==</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">)</span>
										<span id="Codehighlighter1_753_923_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.cnitblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_753_923_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                d[dp]</span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000">p[i];<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                div</span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000">p[i]</span>
												<span style="COLOR: #000000">*</span>
												<span style="COLOR: #000000">p[i]; cnt</span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_818_852_Open_Image" onclick="this.style.display='none'; Codehighlighter1_818_852_Open_Text.style.display='none'; Codehighlighter1_818_852_Closed_Image.style.display='inline'; Codehighlighter1_818_852_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_818_852_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_818_852_Closed_Text.style.display='none'; Codehighlighter1_818_852_Open_Image.style.display='inline'; Codehighlighter1_818_852_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />                </span>
												<span style="COLOR: #0000ff">while</span>
												<span style="COLOR: #000000">(num</span>
												<span style="COLOR: #000000">%</span>
												<span style="COLOR: #000000">div</span>
												<span style="COLOR: #000000">==</span>
												<span style="COLOR: #000000">0</span>
												<span style="COLOR: #000000">)</span>
												<span id="Codehighlighter1_818_852_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.cnitblog.com/images/dot.gif" />
												</span>
												<span id="Codehighlighter1_818_852_Open_Text">
														<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    div</span>
														<span style="COLOR: #000000">*=</span>
														<span style="COLOR: #000000">p[i];<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    </span>
														<span style="COLOR: #000000">++</span>
														<span style="COLOR: #000000">cnt;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />                }</span>
												</span>
												<span style="COLOR: #000000">
														<br />
														<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                e[dp</span>
												<span style="COLOR: #000000">++</span>
												<span style="COLOR: #000000">]</span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000">cnt;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                div</span>
												<span style="COLOR: #000000">/=</span>
												<span style="COLOR: #000000">p[i];<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span>
												<span style="COLOR: #0000ff">if</span>
												<span style="COLOR: #000000">((num</span>
												<span style="COLOR: #000000">/=</span>
												<span style="COLOR: #000000">div)</span>
												<span style="COLOR: #000000">==</span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    </span>
												<span style="COLOR: #0000ff">break</span>
												<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img id="Codehighlighter1_941_970_Open_Image" onclick="this.style.display='none'; Codehighlighter1_941_970_Open_Text.style.display='none'; Codehighlighter1_941_970_Closed_Image.style.display='inline'; Codehighlighter1_941_970_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_941_970_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_941_970_Closed_Text.style.display='none'; Codehighlighter1_941_970_Open_Image.style.display='inline'; Codehighlighter1_941_970_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">(num</span>
								<span style="COLOR: #000000">!=</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">)</span>
								<span id="Codehighlighter1_941_970_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.cnitblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_941_970_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            d[dp]</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">num; e[dp</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">]</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> primeNS;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />#include</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">cstdio</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img id="Codehighlighter1_1029_1152_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1029_1152_Open_Text.style.display='none'; Codehighlighter1_1029_1152_Closed_Image.style.display='inline'; Codehighlighter1_1029_1152_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_1029_1152_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1029_1152_Closed_Text.style.display='none'; Codehighlighter1_1029_1152_Open_Image.style.display='inline'; Codehighlighter1_1029_1152_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()</span>
				<span id="Codehighlighter1_1029_1152_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.cnitblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1029_1152_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    init();<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    factorization(</span>
						<span style="COLOR: #000000">293910</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i;<br /><img id="Codehighlighter1_1090_1123_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1090_1123_Open_Text.style.display='none'; Codehighlighter1_1090_1123_Closed_Image.style.display='inline'; Codehighlighter1_1090_1123_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1090_1123_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1090_1123_Closed_Text.style.display='none'; Codehighlighter1_1090_1123_Open_Image.style.display='inline'; Codehighlighter1_1090_1123_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </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">dp;</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">i)</span>
						<span id="Codehighlighter1_1090_1123_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1090_1123_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        printf(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">+%d^%d</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">,d[i],e[i]);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    printf(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">\n</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
<img src ="http://www.cnitblog.com/cockerel/aggbug/13479.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/cockerel/" target="_blank">踏雪赤兔</a> 2006-07-11 00:24 <a href="http://www.cnitblog.com/cockerel/archive/2006/07/11/13479.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>例程：PQ API</title><link>http://www.cnitblog.com/cockerel/archive/2006/07/09/13416.html</link><dc:creator>踏雪赤兔</dc:creator><author>踏雪赤兔</author><pubDate>Sun, 09 Jul 2006 02:11:00 GMT</pubDate><guid>http://www.cnitblog.com/cockerel/archive/2006/07/09/13416.html</guid><wfw:comment>http://www.cnitblog.com/cockerel/comments/13416.html</wfw:comment><comments>http://www.cnitblog.com/cockerel/archive/2006/07/09/13416.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cnitblog.com/cockerel/comments/commentRss/13416.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/cockerel/services/trackbacks/13416.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.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#include</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">algorithm</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">本例程介绍了STL heap的用法，并将其封装到到一个优先队列类中</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> maxLen</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">100</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />template</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> T</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">#define</span>
				<span style="COLOR: #000000"> DEAP </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">浅复制还是深复制</span>
				<span style="COLOR: #000000">
						<br />
						<img id="Codehighlighter1_129_985_Open_Image" onclick="this.style.display='none'; Codehighlighter1_129_985_Open_Text.style.display='none'; Codehighlighter1_129_985_Closed_Image.style.display='inline'; Codehighlighter1_129_985_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_129_985_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_129_985_Closed_Text.style.display='none'; Codehighlighter1_129_985_Open_Image.style.display='inline'; Codehighlighter1_129_985_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000"> PQ</span>
				<span id="Codehighlighter1_129_985_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.cnitblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_129_985_Open_Text">
						<span style="COLOR: #000000">{</span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">最大堆</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    T h[maxLen];<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> e;<br /><img id="Codehighlighter1_171_177_Open_Image" onclick="this.style.display='none'; Codehighlighter1_171_177_Open_Text.style.display='none'; Codehighlighter1_171_177_Closed_Image.style.display='inline'; Codehighlighter1_171_177_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_171_177_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_171_177_Closed_Text.style.display='none'; Codehighlighter1_171_177_Open_Image.style.display='inline'; Codehighlighter1_171_177_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> clear()</span>
						<span id="Codehighlighter1_171_177_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_171_177_Open_Text">
								<span style="COLOR: #000000">{ e</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">;}</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_192_207_Open_Image" onclick="this.style.display='none'; Codehighlighter1_192_207_Open_Text.style.display='none'; Codehighlighter1_192_207_Closed_Image.style.display='inline'; Codehighlighter1_192_207_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_192_207_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_192_207_Closed_Text.style.display='none'; Codehighlighter1_192_207_Open_Image.style.display='inline'; Codehighlighter1_192_207_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">bool</span>
						<span style="COLOR: #000000"> empty()</span>
						<span id="Codehighlighter1_192_207_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_192_207_Open_Text">
								<span style="COLOR: #000000">{ </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> e</span>
								<span style="COLOR: #000000">==</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">; }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_220_231_Open_Image" onclick="this.style.display='none'; Codehighlighter1_220_231_Open_Text.style.display='none'; Codehighlighter1_220_231_Closed_Image.style.display='inline'; Codehighlighter1_220_231_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_220_231_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_220_231_Closed_Text.style.display='none'; Codehighlighter1_220_231_Open_Image.style.display='inline'; Codehighlighter1_220_231_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> size()</span>
						<span id="Codehighlighter1_220_231_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_220_231_Open_Text">
								<span style="COLOR: #000000">{ </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> e;}</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_258_305_Open_Image" onclick="this.style.display='none'; Codehighlighter1_258_305_Open_Text.style.display='none'; Codehighlighter1_258_305_Closed_Image.style.display='inline'; Codehighlighter1_258_305_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_258_305_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_258_305_Closed_Text.style.display='none'; Codehighlighter1_258_305_Open_Image.style.display='inline'; Codehighlighter1_258_305_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> push(</span>
						<span style="COLOR: #0000ff">const</span>
						<span style="COLOR: #000000"> T</span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000"> item)</span>
						<span id="Codehighlighter1_258_305_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_258_305_Open_Text">
								<span style="COLOR: #000000">{</span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">O(logN)</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        h[e</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">]</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">item;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        push_heap(h,h</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">e);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_316_364_Open_Image" onclick="this.style.display='none'; Codehighlighter1_316_364_Open_Text.style.display='none'; Codehighlighter1_316_364_Closed_Image.style.display='inline'; Codehighlighter1_316_364_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_316_364_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_316_364_Closed_Text.style.display='none'; Codehighlighter1_316_364_Open_Image.style.display='inline'; Codehighlighter1_316_364_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    T</span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000"> pop()</span>
						<span id="Codehighlighter1_316_364_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_316_364_Open_Text">
								<span style="COLOR: #000000">{</span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">O(logN)</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        pop_heap(h,h</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">e);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> h[</span>
								<span style="COLOR: #000000">--</span>
								<span style="COLOR: #000000">e];<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_381_399_Open_Image" onclick="this.style.display='none'; Codehighlighter1_381_399_Open_Text.style.display='none'; Codehighlighter1_381_399_Closed_Image.style.display='inline'; Codehighlighter1_381_399_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_381_399_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_381_399_Closed_Text.style.display='none'; Codehighlighter1_381_399_Open_Image.style.display='inline'; Codehighlighter1_381_399_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">const</span>
						<span style="COLOR: #000000"> T</span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000"> top()</span>
						<span id="Codehighlighter1_381_399_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_381_399_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> h[</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">];<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_427_594_Open_Image" onclick="this.style.display='none'; Codehighlighter1_427_594_Open_Text.style.display='none'; Codehighlighter1_427_594_Closed_Image.style.display='inline'; Codehighlighter1_427_594_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_427_594_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_427_594_Closed_Text.style.display='none'; Codehighlighter1_427_594_Open_Image.style.display='inline'; Codehighlighter1_427_594_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> make(T</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> bgn, T</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> end)</span>
						<span id="Codehighlighter1_427_594_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_427_594_Open_Text">
								<span style="COLOR: #000000">{</span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">O(N)</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        #ifdef DEAP </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">深复制</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">            </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000">(e</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">; bgn</span>
								<span style="COLOR: #000000">!=</span>
								<span style="COLOR: #000000">end; </span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">e,</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">bgn)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                h[e]</span>
								<span style="COLOR: #000000">=*</span>
								<span style="COLOR: #000000">bgn;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">#else</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">浅复制</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            e</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">end</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">bgn;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            memcpy(h,bgn,e</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #0000ff">sizeof</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">bgn));<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">#endif</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        make_heap(h,h</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">e);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_614_809_Open_Image" onclick="this.style.display='none'; Codehighlighter1_614_809_Open_Text.style.display='none'; Codehighlighter1_614_809_Closed_Image.style.display='inline'; Codehighlighter1_614_809_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_614_809_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_614_809_Closed_Text.style.display='none'; Codehighlighter1_614_809_Open_Image.style.display='inline'; Codehighlighter1_614_809_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> sort(T</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> bgn)</span>
						<span id="Codehighlighter1_614_809_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_614_809_Open_Text">
								<span style="COLOR: #000000">{</span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">O(NlogN)</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        #ifdef DEAP </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">深复制</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">            </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> i; T</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000"> end</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">bgn;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </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">e; </span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">i,</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">end)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">end</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">h[i];<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">#else</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">浅复制</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            T</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000"> end</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">bgn</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">e;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            memcpy(bgn,h,e</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #0000ff">sizeof</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">bgn));<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">#endif</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            sort_heap(bgn, end);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_846_966_Open_Image" onclick="this.style.display='none'; Codehighlighter1_846_966_Open_Text.style.display='none'; Codehighlighter1_846_966_Closed_Image.style.display='inline'; Codehighlighter1_846_966_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_846_966_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_846_966_Closed_Text.style.display='none'; Codehighlighter1_846_966_Open_Image.style.display='inline'; Codehighlighter1_846_966_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    friend </span>
						<span style="COLOR: #0000ff">bool</span>
						<span style="COLOR: #000000"> isHeap(T</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> bgn, T</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> end)</span>
						<span id="Codehighlighter1_846_966_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_846_966_Open_Text">
								<span style="COLOR: #000000">{ </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">debug用, O(N)</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        T</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000"> h</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">bgn</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">; </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> i,e</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">end</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">bgn</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000">(i</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">2</span>
								<span style="COLOR: #000000">; i</span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000">e; </span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">i)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">(h[i</span>
								<span style="COLOR: #000000">/</span>
								<span style="COLOR: #000000">2</span>
								<span style="COLOR: #000000">]</span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000">h[i]) </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">false</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">true</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_973_983_Open_Image" onclick="this.style.display='none'; Codehighlighter1_973_983_Open_Text.style.display='none'; Codehighlighter1_973_983_Closed_Image.style.display='inline'; Codehighlighter1_973_983_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_973_983_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_973_983_Closed_Text.style.display='none'; Codehighlighter1_973_983_Open_Image.style.display='inline'; Codehighlighter1_973_983_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    PQ()</span>
						<span id="Codehighlighter1_973_983_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_973_983_Open_Text">
								<span style="COLOR: #000000">{ clear();}</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />#include</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">cassert</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />#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.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />template</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> T</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img id="Codehighlighter1_1095_1157_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1095_1157_Open_Text.style.display='none'; Codehighlighter1_1095_1157_Closed_Image.style.display='inline'; Codehighlighter1_1095_1157_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_1095_1157_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1095_1157_Closed_Text.style.display='none'; Codehighlighter1_1095_1157_Open_Image.style.display='inline'; Codehighlighter1_1095_1157_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />inline </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> show(T a[], </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> n)</span>
				<span id="Codehighlighter1_1095_1157_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.cnitblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1095_1157_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </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; </span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">i)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        cout</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">a[i]</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">'</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">'</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">endl;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">简单测试        </span>
				<span style="COLOR: #008000">
						<br />
						<img id="Codehighlighter1_1179_1732_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1179_1732_Open_Text.style.display='none'; Codehighlighter1_1179_1732_Closed_Image.style.display='inline'; Codehighlighter1_1179_1732_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_1179_1732_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1179_1732_Closed_Text.style.display='none'; Codehighlighter1_1179_1732_Open_Image.style.display='inline'; Codehighlighter1_1179_1732_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()</span>
				<span id="Codehighlighter1_1179_1732_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.cnitblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1179_1732_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    PQ</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> pq;<br /><img id="Codehighlighter1_1203_1217_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1203_1217_Open_Text.style.display='none'; Codehighlighter1_1203_1217_Closed_Image.style.display='inline'; Codehighlighter1_1203_1217_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1203_1217_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1203_1217_Closed_Text.style.display='none'; Codehighlighter1_1203_1217_Open_Image.style.display='inline'; Codehighlighter1_1203_1217_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> a[]</span>
						<span style="COLOR: #000000">=</span>
						<span id="Codehighlighter1_1203_1217_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1203_1217_Open_Text">
								<span style="COLOR: #000000">{</span>
								<span style="COLOR: #000000">3</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">6</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">5</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">4</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">2</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">7</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #000000">9</span>
								<span style="COLOR: #000000">}</span>
						</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">(pq.empty() </span>
						<span style="COLOR: #000000">?</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">Empty\n</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> : </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">Not empty\n</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    pq.make(a,a</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #0000ff">sizeof</span>
						<span style="COLOR: #000000">(a)</span>
						<span style="COLOR: #000000">/</span>
						<span style="COLOR: #0000ff">sizeof</span>
						<span style="COLOR: #000000">(</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">a));<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    show(pq.h,pq.size());<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">Top: </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">pq.top()</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">endl;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">( isHeap(pq.h, pq.h</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000">pq.e) </span>
						<span style="COLOR: #000000">?</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">Is heap\n</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> : </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">Not a heap\n</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> );<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    pq.push(</span>
						<span style="COLOR: #000000">3</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    pq.push(</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    pq.push(</span>
						<span style="COLOR: #000000">10</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    show(pq.h,pq.size());<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">Top: </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">pq.top()</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">endl;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">( isHeap(pq.h, pq.h</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000">pq.e) </span>
						<span style="COLOR: #000000">?</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">Is heap\n</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> : </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">Not a heap\n</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> );<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">Pop:</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">pq.pop()</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">endl;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">Pop:</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">pq.pop()</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">endl;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">Pop:</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">pq.pop()</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">endl;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    pq.sort(a);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    show(a,pq.size());<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
<img src ="http://www.cnitblog.com/cockerel/aggbug/13416.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/cockerel/" target="_blank">踏雪赤兔</a> 2006-07-09 10:11 <a href="http://www.cnitblog.com/cockerel/archive/2006/07/09/13416.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>标程：并查集API</title><link>http://www.cnitblog.com/cockerel/archive/2006/07/09/13414.html</link><dc:creator>踏雪赤兔</dc:creator><author>踏雪赤兔</author><pubDate>Sat, 08 Jul 2006 18:29:00 GMT</pubDate><guid>http://www.cnitblog.com/cockerel/archive/2006/07/09/13414.html</guid><wfw:comment>http://www.cnitblog.com/cockerel/comments/13414.html</wfw:comment><comments>http://www.cnitblog.com/cockerel/archive/2006/07/09/13414.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/cockerel/comments/commentRss/13414.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/cockerel/services/trackbacks/13414.html</trackback:ping><description><![CDATA[
		<p>
		</p>
		<p>
		</p>
		<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 id="Codehighlighter1_17_637_Open_Image" onclick="this.style.display='none'; Codehighlighter1_17_637_Open_Text.style.display='none'; Codehighlighter1_17_637_Closed_Image.style.display='inline'; Codehighlighter1_17_637_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
				<img id="Codehighlighter1_17_637_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_17_637_Closed_Text.style.display='none'; Codehighlighter1_17_637_Open_Image.style.display='inline'; Codehighlighter1_17_637_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> UnionNS</span>
				<span id="Codehighlighter1_17_637_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.cnitblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_17_637_Open_Text">
						<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_20_78_Open_Image" onclick="this.style.display='none'; Codehighlighter1_20_78_Open_Text.style.display='none'; Codehighlighter1_20_78_Closed_Image.style.display='inline'; Codehighlighter1_20_78_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_20_78_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_20_78_Closed_Text.style.display='none'; Codehighlighter1_20_78_Open_Image.style.display='inline'; Codehighlighter1_20_78_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_20_78_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">/**/</span>
						<span id="Codehighlighter1_20_78_Open_Text">
								<span style="COLOR: #008000">/*</span>
								<span style="COLOR: #008000">解决：并查集<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />     *算法：树状、带路径压缩的并查集<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />     *备注：by Cockerel 06-08-27<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />     </span>
								<span style="COLOR: #008000">*/</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">const</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> maxV</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">100</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> p[maxV];</span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">p[i]= p[i]&gt;=0 ? 父编号 : 集合规模<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">初始化：</span>
						<span style="COLOR: #008000">
								<br />
								<img id="Codehighlighter1_170_211_Open_Image" onclick="this.style.display='none'; Codehighlighter1_170_211_Open_Text.style.display='none'; Codehighlighter1_170_211_Closed_Image.style.display='inline'; Codehighlighter1_170_211_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_170_211_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_170_211_Closed_Text.style.display='none'; Codehighlighter1_170_211_Open_Image.style.display='inline'; Codehighlighter1_170_211_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    inline </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> init()</span>
						<span id="Codehighlighter1_170_211_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_170_211_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        memset(p,</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #0000ff">sizeof</span>
								<span style="COLOR: #000000">(p));</span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">初始化为根且规模为1</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />
								</span>
								<span style="COLOR: #000000">    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">求根运算：</span>
						<span style="COLOR: #008000">
								<br />
								<img id="Codehighlighter1_245_343_Open_Image" onclick="this.style.display='none'; Codehighlighter1_245_343_Open_Text.style.display='none'; Codehighlighter1_245_343_Closed_Image.style.display='inline'; Codehighlighter1_245_343_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_245_343_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_245_343_Closed_Text.style.display='none'; Codehighlighter1_245_343_Open_Image.style.display='inline'; Codehighlighter1_245_343_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    inline </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> root(</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i)</span>
						<span id="Codehighlighter1_245_343_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_245_343_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> j,r;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000">(r</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">i; p[r]</span>
								<span style="COLOR: #000000">&gt;=</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">; r</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">p[r]);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000">(; i</span>
								<span style="COLOR: #000000">!=</span>
								<span style="COLOR: #000000">r; i</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">j)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            j</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">p[i],p[i]</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">r;</span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">路径压缩</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> r;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">判断等价</span>
						<span style="COLOR: #008000">
								<br />
								<img id="Codehighlighter1_385_415_Open_Image" onclick="this.style.display='none'; Codehighlighter1_385_415_Open_Text.style.display='none'; Codehighlighter1_385_415_Closed_Image.style.display='inline'; Codehighlighter1_385_415_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_385_415_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_385_415_Closed_Text.style.display='none'; Codehighlighter1_385_415_Open_Image.style.display='inline'; Codehighlighter1_385_415_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    inline </span>
						<span style="COLOR: #0000ff">bool</span>
						<span style="COLOR: #000000"> equal(</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i, </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> j)</span>
						<span id="Codehighlighter1_385_415_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_385_415_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> root(i)</span>
								<span style="COLOR: #000000">==</span>
								<span style="COLOR: #000000">root(j);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">求集合规模</span>
						<span style="COLOR: #008000">
								<br />
								<img id="Codehighlighter1_449_474_Open_Image" onclick="this.style.display='none'; Codehighlighter1_449_474_Open_Text.style.display='none'; Codehighlighter1_449_474_Closed_Image.style.display='inline'; Codehighlighter1_449_474_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_449_474_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_449_474_Closed_Text.style.display='none'; Codehighlighter1_449_474_Open_Image.style.display='inline'; Codehighlighter1_449_474_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    inline </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> size(</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i)</span>
						<span id="Codehighlighter1_449_474_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_449_474_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">p[root(i)];<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">合并</span>
						<span style="COLOR: #008000">
								<br />
								<img id="Codehighlighter1_514_635_Open_Image" onclick="this.style.display='none'; Codehighlighter1_514_635_Open_Text.style.display='none'; Codehighlighter1_514_635_Closed_Image.style.display='inline'; Codehighlighter1_514_635_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_514_635_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_514_635_Closed_Text.style.display='none'; Codehighlighter1_514_635_Open_Image.style.display='inline'; Codehighlighter1_514_635_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    inline </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> merge(</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i, </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> j)</span>
						<span id="Codehighlighter1_514_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.cnitblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_514_635_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        i</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">root(i); j</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">root(j);<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">(i</span>
								<span style="COLOR: #000000">==</span>
								<span style="COLOR: #000000">j) </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">(p[i]</span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000">p[j])</span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">树状合并</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">            p[i]</span>
								<span style="COLOR: #000000">+=</span>
								<span style="COLOR: #000000">p[j], p[j]</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">i;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            p[j]</span>
								<span style="COLOR: #000000">+=</span>
								<span style="COLOR: #000000">p[i], p[i]</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">j;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
		<p>　　树状合并、带路径压缩的并查集可以以最大O(logN),平均O(1)的复杂度完成合并与测试操作<br />　　这个是2006年11月15日更新版，相比于2006年7月8日版，有以下改进：<br />　　1、添加求集合规模运算<br />　　2、简化代码<br />　　3、提高运行速度<br />　　4、减少占用空间<br />      相比于2006年8月8日版，修改了一个小bug。<br />　　该标程经VC6.0及g++编译器编译通过。<br /><br /></p>
<img src ="http://www.cnitblog.com/cockerel/aggbug/13414.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/cockerel/" target="_blank">踏雪赤兔</a> 2006-07-09 02:29 <a href="http://www.cnitblog.com/cockerel/archive/2006/07/09/13414.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>标程：经典图算法的测试程序</title><link>http://www.cnitblog.com/cockerel/archive/2006/07/07/13362.html</link><dc:creator>踏雪赤兔</dc:creator><author>踏雪赤兔</author><pubDate>Fri, 07 Jul 2006 09:53:00 GMT</pubDate><guid>http://www.cnitblog.com/cockerel/archive/2006/07/07/13362.html</guid><wfw:comment>http://www.cnitblog.com/cockerel/comments/13362.html</wfw:comment><comments>http://www.cnitblog.com/cockerel/archive/2006/07/07/13362.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/cockerel/comments/commentRss/13362.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/cockerel/services/trackbacks/13362.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 1								#include				&lt;				cstdio				&gt;																		  2										#include				&lt;				iostream				&gt;																		  3										#include				&lt;...&nbsp;&nbsp;<a href='http://www.cnitblog.com/cockerel/archive/2006/07/07/13362.html'>阅读全文</a><img src ="http://www.cnitblog.com/cockerel/aggbug/13362.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/cockerel/" target="_blank">踏雪赤兔</a> 2006-07-07 17:53 <a href="http://www.cnitblog.com/cockerel/archive/2006/07/07/13362.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>标程：经典图算法</title><link>http://www.cnitblog.com/cockerel/archive/2006/07/07/13361.html</link><dc:creator>踏雪赤兔</dc:creator><author>踏雪赤兔</author><pubDate>Fri, 07 Jul 2006 09:41:00 GMT</pubDate><guid>http://www.cnitblog.com/cockerel/archive/2006/07/07/13361.html</guid><wfw:comment>http://www.cnitblog.com/cockerel/comments/13361.html</wfw:comment><comments>http://www.cnitblog.com/cockerel/archive/2006/07/07/13361.html#Feedback</comments><slash:comments>20</slash:comments><wfw:commentRss>http://www.cnitblog.com/cockerel/comments/commentRss/13361.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/cockerel/services/trackbacks/13361.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: #include				&lt;				cstring				&gt;																								//				常量定义：																								const				 				int				 maxV				=				100				;				const				 			...&nbsp;&nbsp;<a href='http://www.cnitblog.com/cockerel/archive/2006/07/07/13361.html'>阅读全文</a><img src ="http://www.cnitblog.com/cockerel/aggbug/13361.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/cockerel/" target="_blank">踏雪赤兔</a> 2006-07-07 17:41 <a href="http://www.cnitblog.com/cockerel/archive/2006/07/07/13361.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>标程：日期序列化（原创）</title><link>http://www.cnitblog.com/cockerel/archive/2006/06/14/12249.html</link><dc:creator>踏雪赤兔</dc:creator><author>踏雪赤兔</author><pubDate>Wed, 14 Jun 2006 07:18:00 GMT</pubDate><guid>http://www.cnitblog.com/cockerel/archive/2006/06/14/12249.html</guid><wfw:comment>http://www.cnitblog.com/cockerel/comments/12249.html</wfw:comment><comments>http://www.cnitblog.com/cockerel/archive/2006/06/14/12249.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/cockerel/comments/commentRss/12249.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/cockerel/services/trackbacks/12249.html</trackback:ping><description><![CDATA[
		<p>#include&lt;iostream&gt;<br />using namespace std;<br />//测试是否闰年，计算日期是第几日(days(0,1,1)==1)，计算日期是星期几，<br />//全部复杂度都是O(1)<br />//**************************<br />int md[]={0,0,31,28,31,30,31,30,31,31,30,31,30};</p>
		<p>inline bool isly(int y){//isLeapYear,测试是否闰年<br /> return y%400==0 || y%100 !=0 &amp;&amp; y%4==0;<br />}</p>
		<p>inline int days(int y, int m, int d){//返回日期序列化值days(0,1,1)==1;<br /> d+=m&lt;=2 &amp;&amp; isly(y) ? md[m]-1 : md[m];<br /> d+=365*y+y/4-y/100+y/400+1;<br /> return d;<br />}<br />inline int day(int y, int m, int d){//返回日期是星期几(0-日,1-一....)<br /> return (days(y,m,d)+5)%7;<br />}<br />//**************************<br />void test();<br />int main(){<br /> //初始化<br /> int i;<br /> for(i=2; i&lt;=12;i++){<br />  md[i]+=md[i-1];<br /> }<br /> //测试<br /> int y1,m1,d1,y2,m2,d2;<br /> //freopen("in.txt","r",stdin);<br /> /*while(cin&gt;&gt;y1&gt;&gt;m1&gt;&gt;d1)<br />  cout&lt;&lt;days(y1,m1,d1)&lt;&lt;endl;<br /> while(cin&gt;&gt;y1&gt;&gt;m1&gt;&gt;d1&gt;&gt;y2&gt;&gt;m2&gt;&gt;d2)<br />  cout&lt;&lt;days(y2,m2,d2)-days(y1,m1,d1)&lt;&lt;endl;/**/<br /> //more test<br /> test();<br /> return 0;<br />}<br />#include&lt;cassert&gt;<br />void test(){<br /> assert(days(0,1,1)==1);<br /> assert(days(0,1,31)==31);<br /> assert(days(0,2,1)==32);<br /> assert(days(0,3,1)-days(0,2,28)==2);<br /> assert(days(0,12,31)-days(0,1,1)==365);<br /> assert(days(1,1,1)-days(0,12,31)==1);<br /> assert(days(1,3,1)-days(1,2,28)==1);<br /> assert(days(1,12,31)-days(0,12,31)==365);<br /> assert(days(4,12,31)-days(3,12,31)==366);<br /> assert(days(100,3,1)-days(100,2,28)==1);<br /> assert(days(101,1,1)-days(100,1,1)==365);<br /> assert(days(401,2,28)-days(400,2,28)==366);<br /> assert(days(1000,3,1)-days(1000,2,28)==1);<br /> assert(days(2000,3,1)-days(2000,2,28)==2);<br /> assert(days(2000,2,1)-days(2000,1,30)==2);<br /> assert(days(2100,3,1)-days(2100,2,28)==1);<br /> assert(days(2000,4,1)-days(2000,3,30)==2);<br /> assert(days(2000,5,1)-days(2000,4,30)==1);<br /> assert(days(2000,6,1)-days(2000,5,30)==2);<br /> assert(days(2000,7,1)-days(2000,6,30)==1);<br /> assert(days(2000,8,1)-days(2000,7,30)==2);<br /> assert(days(2000,9,1)-days(2000,8,30)==2);<br /> assert(days(2000,10,1)-days(2000,9,30)==1);<br /> assert(days(2000,11,1)-days(2000,10,30)==2);<br /> assert(days(2000,12,1)-days(2000,11,30)==1);<br /> assert(days(2001,1,1)-days(2000,12,30)==2);<br /> assert(days(3000,12,31)==1096093);<br /> assert(day(2006,6,14)==3);<br /> assert(day(2008,3,1)==6);<br /> assert(day(1985,10,3)==4);<br /> assert(day(2006,1,1)==0);//Sunday.<br /> cout&lt;&lt;"Accepted!"&lt;&lt;endl;</p>
		<p>}<br /></p>
		<p style="FONT-SIZE: 12px">---<br />本文章使用<a href="http://www.kicoy.com">开源内容管理kicoy</a>发布</p>
<img src ="http://www.cnitblog.com/cockerel/aggbug/12249.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/cockerel/" target="_blank">踏雪赤兔</a> 2006-06-14 15:18 <a href="http://www.cnitblog.com/cockerel/archive/2006/06/14/12249.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>STL小结（原创）</title><link>http://www.cnitblog.com/cockerel/archive/2006/06/14/12245.html</link><dc:creator>踏雪赤兔</dc:creator><author>踏雪赤兔</author><pubDate>Wed, 14 Jun 2006 05:57:00 GMT</pubDate><guid>http://www.cnitblog.com/cockerel/archive/2006/06/14/12245.html</guid><wfw:comment>http://www.cnitblog.com/cockerel/comments/12245.html</wfw:comment><comments>http://www.cnitblog.com/cockerel/archive/2006/06/14/12245.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/cockerel/comments/commentRss/12245.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/cockerel/services/trackbacks/12245.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: STL												概述：								使用容器前增加				#pragma warning(disable: 4786) 				指令								字符串容器只储存指针，请另外用数组存放真正的串（当然你也可以使用STLstring）														断言																						...&nbsp;&nbsp;<a href='http://www.cnitblog.com/cockerel/archive/2006/06/14/12245.html'>阅读全文</a><img src ="http://www.cnitblog.com/cockerel/aggbug/12245.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/cockerel/" target="_blank">踏雪赤兔</a> 2006-06-14 13:57 <a href="http://www.cnitblog.com/cockerel/archive/2006/06/14/12245.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>STL排序方法（原创）</title><link>http://www.cnitblog.com/cockerel/archive/2006/06/14/12244.html</link><dc:creator>踏雪赤兔</dc:creator><author>踏雪赤兔</author><pubDate>Wed, 14 Jun 2006 05:51:00 GMT</pubDate><guid>http://www.cnitblog.com/cockerel/archive/2006/06/14/12244.html</guid><wfw:comment>http://www.cnitblog.com/cockerel/comments/12244.html</wfw:comment><comments>http://www.cnitblog.com/cockerel/archive/2006/06/14/12244.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cnitblog.com/cockerel/comments/commentRss/12244.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/cockerel/services/trackbacks/12244.html</trackback:ping><description><![CDATA[<p>//适合读者：STL初学者</p>
		<p>//#include&lt;algorithm&gt;<br />//快速排序sort()  (平均O(NlogN) <br />//稳定排序stable_sort() (最好O(NlogN)，最坏O(N(logN)^2) 用法与sort()相同<br />//堆排序s ort_heap()  (O(NlogN)) 用法同sort()，要先make_heap()或push_heap()<br />/************目录************<br />用法一：内置类型的由小到大排序：使用默认比较函数(less&lt;T&gt;())<br /> sort(a,a+len); //a:数组名，len:数组长度=sizeof(arrray)/sizeof(*array)</p>
		<p>用法二:内置类型的由大到小排序：使用内置比较函数(greater&lt;T&gt;())<br /> sort(a,a+len,greater&lt;int&gt;()); //greater&lt;Type&gt;():#include&lt;functional&gt;</p>
		<p>用法三:自定义类型对象数组的由大到小排序：使用游离比较函数(myGreater(Type&amp;, Type&amp;)<br /> bool myGreater(const Type&amp; a, const Type&amp; b){ return a&gt;b;}<br /> sort(a,a+len,myGreater); //自定义类型对象数组的由大到小排序<br /> 堆排序版本：<br /> bool myGreater(const Type&amp; a, const Type&amp; b){ return a&gt;b;}<br /> make_heap(a,a+len,myGreater);<br /> sort_heap(a,a+len,myGreater); //参数必须完全一样!<br /> <br />用法四:指针数组的由大到小排序：使用游离比较函数(myGreater(const Type*, const Type*)<br /> bool myGreater(const int* a, const int* b){ return *a&gt;*b;}<br /> sort(p,p+len,myGreater); //指针数组的由大到小排序，适用于索引排序<br />/**/<br />//***********例子************<br />#include&lt;iostream&gt;<br />#include&lt;algorithm&gt;<br />#include&lt;functional&gt;<br />using namespace std;<br />//用法一：内置类型的由小到大排序：使用默认比较函数(less&lt;T&gt;())<br />/*void main()<br />{<br /> int a[]={3, 1,4,2,5};<br /> int len=sizeof(a)/sizeof(int);<br /> sort(a,a+len); //默认：内置类型的由小到大排序<br /> for (int i=0; i&lt;len; i++)<br />  cout&lt;&lt;a[i]&lt;&lt;'\t';<br /> cout&lt;&lt;endl;<br />}<br />/**/<br />//用法二:内置类型的由大到小排序：使用内置比较函数(greater&lt;T&gt;())<br />/*void main()<br />{<br /> int a[]={3, 1,4,2,5};<br /> int len=sizeof(a)/sizeof(int);<br /> sort(a,a+len,greater&lt;int&gt;()); //内置类型的由大到小排序<br /> for (int i=0; i&lt;len; i++)<br />  cout&lt;&lt;a[i]&lt;&lt;'\t';<br /> cout&lt;&lt;endl;<br />}<br />/**/<br />//用法三:自定义类型对象数组的由大到小排序：使用游离比较函数(myGreater(Type&amp;, Type&amp;)<br />/*bool myGreater(int&amp; a, int&amp; b){ return a&gt;b;}<br />void main()<br />{<br /> int a[]={3, 1,4,2,5};<br /> int len=sizeof(a)/sizeof(int);<br /> sort(a,a+len,myGreater); //自定义类型的由大到小排序<br /> for (int i=0; i&lt;len; i++)<br />  cout&lt;&lt;a[i]&lt;&lt;'\t';<br /> cout&lt;&lt;endl;<br />}<br />/**/<br />//sort_heap版本：<br />bool myGreater(int&amp; a, int&amp; b){ return a&gt;b;}<br />void main()<br />{<br /> int a[]={3, 1,4,2,5};<br /> int len=sizeof(a)/sizeof(int);<br /> make_heap(a,a+len,myGreater);<br /> sort_heap(a,a+len,myGreater); //自定义类型的由大到小排序<br /> for (int i=0; i&lt;len; i++)<br />  cout&lt;&lt;a[i]&lt;&lt;'\t';<br /> cout&lt;&lt;endl;<br />}<br />/**/</p>
		<p>//用法四:自定义类型指针数组的由大到小排序：使用游离比较函数(myGreater(Type&amp;, Type&amp;)<br />/*bool myGreater(int* a, int* b){ return *a&gt;*b;}<br />void main()<br />{<br /> int a[]={3, 1,4,2,5};<br /> int* p[5];<br /> for(int i=0;i&lt;5;i++) p[i]=&amp;a[i];<br /> int len=sizeof(a)/sizeof(int);<br /> sort(p,p+len,myGreater); //自定义类型的由大到小排序<br /> for (i=0; i&lt;len; i++)<br />  cout&lt;&lt;a[i]&lt;&lt;'\t';<br /> cout&lt;&lt;endl;<br /> for (i=0; i&lt;len; i++)<br />  cout&lt;&lt;*p[i]&lt;&lt;'\t';<br /> cout&lt;&lt;endl;<br />}<br />/**/</p>
		<p style="font-size: 12px;">---<br />本文章使用<a href="http://www.kicoy.com">开源内容管理kicoy</a>发布</p><img src ="http://www.cnitblog.com/cockerel/aggbug/12244.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/cockerel/" target="_blank">踏雪赤兔</a> 2006-06-14 13:51 <a href="http://www.cnitblog.com/cockerel/archive/2006/06/14/12244.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>园内导航</title><link>http://www.cnitblog.com/cockerel/archive/2006/06/14/12223.html</link><dc:creator>踏雪赤兔</dc:creator><author>踏雪赤兔</author><pubDate>Wed, 14 Jun 2006 02:11:00 GMT</pubDate><guid>http://www.cnitblog.com/cockerel/archive/2006/06/14/12223.html</guid><wfw:comment>http://www.cnitblog.com/cockerel/comments/12223.html</wfw:comment><comments>http://www.cnitblog.com/cockerel/archive/2006/06/14/12223.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.cnitblog.com/cockerel/comments/commentRss/12223.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/cockerel/services/trackbacks/12223.html</trackback:ping><description><![CDATA[
		<p designtimesp="19596">
				<a class="" title="" href="/cockerel/category/3074.html" target="">岁月如歌</a>
				<br />成长的足迹，岁月的积淀<a class="" title="" href="/cockerel/category/3068.html" target="_blank" designtimesp="19597"><br />个人词典</a><br designtimesp="19598" />如果你对新名词有旺盛的求知欲，这是满足欲望的好地方<br designtimesp="19599" /><a class="" title="" href="/cockerel/category/3074.html" target="_blank" designtimesp="19600">奇闻趣文</a><br designtimesp="19601" />世界之大，无奇不有<br /><a class="" title="" href="/cockerel/category/3189.html" target="_blank">休闲搞笑</a><br />笑一笑，十年少<br designtimesp="19602" /><a class="" title="" href="/cockerel/category/3073.html" target="_blank" designtimesp="19603">IT资讯</a><br designtimesp="19604" />如果你是一位IT人士，这里预见了你的前途<br designtimesp="19605" /><a class="" title="" href="/cockerel/category/3077.html" target="_blank" designtimesp="19606">玩转编程</a><br designtimesp="19607" />没有做不到，只有想不到<br designtimesp="19608" /><a class="" title="" href="/cockerel/category/3075.html" target="_blank" designtimesp="19609">零件仓库</a><br designtimesp="19610" />合抱之木，生于毫末；九层之台，起于累土；千里之行，始于足下。<br /><a class="" title="" href="/cockerel/category/4378.html" target="">新语丝精华</a><br />精神宝库，战斗前沿</p>
<img src ="http://www.cnitblog.com/cockerel/aggbug/12223.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/cockerel/" target="_blank">踏雪赤兔</a> 2006-06-14 10:11 <a href="http://www.cnitblog.com/cockerel/archive/2006/06/14/12223.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ELFhash函数</title><link>http://www.cnitblog.com/cockerel/archive/2006/06/12/12071.html</link><dc:creator>踏雪赤兔</dc:creator><author>踏雪赤兔</author><pubDate>Mon, 12 Jun 2006 03:42:00 GMT</pubDate><guid>http://www.cnitblog.com/cockerel/archive/2006/06/12/12071.html</guid><wfw:comment>http://www.cnitblog.com/cockerel/comments/12071.html</wfw:comment><comments>http://www.cnitblog.com/cockerel/archive/2006/06/12/12071.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/cockerel/comments/commentRss/12071.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/cockerel/services/trackbacks/12071.html</trackback:ping><description><![CDATA[
		<p>//ELFhash函数<br />int hasher(char *k){<br /> unsigned long h=0,g;<br /> while(*k){<br />  h=(h&lt;&lt;4)+*k++;<br />  g=h &amp;0xf0000000l; //7个0;<br />  if(g) h^=g&gt;&gt;24;<br />  h&amp;=~g;<br /> }<br /> return h;<br />}</p>
		<p>附测试：</p>
		<center>
				<!--StartFragment-->
				<table width="728" align="center">
						<tbody>
								<tr>
										<td align="middle">
												<h2>
														<font color="#0f3ccd">经典字符串Hash函数测试</font>
												</h2>
										</td>
								</tr>
								<tr>
										<td align="right">01-8-22 上午 11:50:37<br /><hr width="718" color="#f46240" size="1" /></td>
								</tr>
						</tbody>
				</table>
				<br />
				<table width="728" align="center">
						<tbody>
								<tr>
										<td valign="top" width="600">
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																				<b>
																						<font size="4">1 概述</font>
																				</b>
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">链表查找的时间效率为O(N)，二分法为log2N，B+ Tree为log2N，但Hash链表查找的时间效率为O(1)。</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">设计高效算法往往需要使用Hash链表，常数级的查找速度是任何别的算法无法比拟的，Hash链表的构造和冲突的不同实现方法对效率当然有一定的影响，然而Hash函数是Hash链表最核心的部分，本文尝试分析一些经典软件中使用到的字符串Hash函数在执行效率、离散性、空间利用率等方面的性能问题。</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																				<b>
																						<font size="4">2 经典字符串Hash函数介绍</font>
																				</b>
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">作者阅读过大量经典软件原代码，下面分别介绍几个经典软件中出现的字符串Hash函数。</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																				<b>2.1 PHP中出现的字符串Hash函数</b>
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">static unsigned long hashpjw(char *arKey, unsigned int nKeyLength)</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">{</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">unsigned long h = 0, g;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">char *arEnd=arKey+nKeyLength;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">while (arKey &lt; arEnd) {</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">h = (h &lt;&lt; 4) + *arKey++;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">if ((g = (h &amp; 0xF0000000))) {</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">h = h ^ (g &gt;&gt; 24);</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">h = h ^ g;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">}</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">}</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">return h;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">}</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																				<b>2.2 OpenSSL中出现的字符串Hash函数</b>
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">unsigned long lh_strhash(char *str)</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">{</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">int i,l;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">unsigned long ret=0;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">unsigned short *s;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">if (str == NULL) return(0);</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">l=(strlen(str)+1)/2;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">s=(unsigned short *)str;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">for (i=0; i<l; td="">&lt; i++)&gt;</l;></td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">ret^=(s[i]&lt;&lt;(i&amp;0x0f));</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">return(ret);</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">} */</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">/* The following hash seems to work very well on normal text strings</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">* no collisions on /usr/dict/words and it distributes on %2^n quite</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">* well, not as good as MD5, but still good.</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">*/</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">unsigned long lh_strhash(const char *c)</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">{</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">unsigned long ret=0;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">long n;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">unsigned long v;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">int r;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">if ((c == NULL) || (*c == '\0'))</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">return(ret);</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">/*</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">unsigned char b[16];</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">MD5(c,strlen(c),b);</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">return(b[0]|(b[1]&lt;&lt;8)|(b[2]&lt;&lt;16)|(b[3]&lt;&lt;24)); </td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">*/</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">n=0x100;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">while (*c)</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">{</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">v=n|(*c);</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">n+=0x100;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">r= (int)((v&gt;&gt;2)^v)&amp;0x0f;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">ret=(ret&lt;<r)|(ret>&gt;(32-r));</r)|(ret></td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">ret&amp;=0xFFFFFFFFL;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">ret^=v*v;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">c++;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">}</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">return((ret&gt;&gt;16)^ret);</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">}</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">在下面的测量过程中我们分别将上面的两个函数标记为OpenSSL_Hash1和OpenSSL_Hash2，至于上面的实现中使用MD5算法的实现函数我们不作测试。</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																				<b>2.3 MySql中出现的字符串Hash函数</b>
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">#ifndef NEW_HASH_FUNCTION</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">/* Calc hashvalue for a key */</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">static uint calc_hashnr(const byte *key,uint length)</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">{</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">register uint nr=1, nr2=4;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">while (length--)</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">{</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">nr^= (((nr &amp; 63)+nr2)*((uint) (uchar) *key++))+ (nr &lt;&lt; 8);</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">nr2+=3;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">}</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">return((uint) nr);</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">}</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">/* Calc hashvalue for a key, case indepenently */</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">static uint calc_hashnr_caseup(const byte *key,uint length)</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">{</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">register uint nr=1, nr2=4;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">while (length--)</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">{</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">nr^= (((nr &amp; 63)+nr2)*((uint) (uchar) toupper(*key++)))+ (nr &lt;&lt; 8);</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">nr2+=3;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">}</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">return((uint) nr);</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">}</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">#else</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">/*</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">* Fowler/Noll/Vo hash</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">*</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">* The basis of the hash algorithm was taken from an idea sent by email to the</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">* IEEE Posix P1003.2 mailing list from Phong Vo (kpv@research.att.com) and</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">* Glenn Fowler (gsf@research.att.com). Landon Curt Noll (chongo@toad.com)</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">* later improved on their algorithm.</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">*</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">* The magic is in the interesting relationship between the special prime</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">* 16777619 (2^24 + 403) and 2^32 and 2^8.</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">*</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">* This hash produces the fewest collisions of any function that we've seen so</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">* far, and works well on both numbers and strings.</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">*/</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">uint calc_hashnr(const byte *key, uint len)</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">{</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">const byte *end=key+len;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">uint hash;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">for (hash = 0; key &lt; end; key++)</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">{</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">hash *= 16777619;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">hash ^= (uint) *(uchar*) key;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">}</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">return (hash);</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">}</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">uint calc_hashnr_caseup(const byte *key, uint len)</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">{</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">const byte *end=key+len;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">uint hash;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">for (hash = 0; key &lt; end; key++)</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">{</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">hash *= 16777619;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">hash ^= (uint) (uchar) toupper(*key);</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">}</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">return (hash);</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">}</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">#endif</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">Mysql中对字符串Hash函数还区分了大小写，我们的测试中使用不区分大小写的字符串Hash函数，另外我们将上面的两个函数分别记为MYSQL_Hash1和MYSQL_Hash2。</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																				<b>2.4 另一个经验字符串Hash函数</b>
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">unsigned int hash(char *str)</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">{</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">register unsigned int h;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">register unsigned char *p;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">for(h=0, p = (unsigned char *)str; *p ; p++)</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">h = 31 * h + *p;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">return h;</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">}</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																				<b>
																						<font size="4">3 测试及结果</font>
																				</b>
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																				<b>3.1 测试说明</b>
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">从上面给出的经典字符串Hash函数中可以看出，有的涉及到字符串大小敏感问题，我们的测试中只考虑字符串大小写敏感的函数，另外在上面的函数中有的函数需要长度参数，有的不需要长度参数，这对函数本身的效率有一定的影响，我们的测试中将对函数稍微作一点修改，全部使用长度参数，并将函数内部出现的计算长度代码删除。</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">我们用来作测试用的Hash链表采用经典的拉链法解决冲突，另外我们采用静态分配桶（Hash链表长度）的方法来构造Hash链表，这主要是为了简化我们的实现，并不影响我们的测试结果。</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">测试文本采用单词表，测试过程中从一个输入文件中读取全部不重复单词构造一个Hash表，测试内容分别是函数总调用次数、函数总调用时间、最大拉链长度、平均拉链长度、桶利用率（使用过的桶所占的比率），其中函数总调用次数是指Hash函数被调用的总次数，为了测试出函数执行时间，该值在测试过程中作了一定的放大，函数总调用时间是指Hash函数总的执行时间，最大拉链长度是指使用拉链法构造链表过程中出现的最大拉链长度，平均拉链长度指拉链的平均长度。 </td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">测试过程中使用的机器配置如下：</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">PIII600笔记本，128M内存，windows 2000 server操作系统。</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																				<b>3.2 测试结果</b>
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">以下分别是对两个不同文本文件中的全部不重复单词构造Hash链表的测试结果，测试结果中函数调用次数放大了100倍，相应的函数调用时间也放大了100倍。</td>
																</tr>
														</tbody>
												</table>
												<table height="22" width="100%">
														<tbody>
																<tr>
																		<td class="a14" height="18">
																				<p align="center">
																						<img src="01_8_22_3a.jpg" border="0" />
																				</p>
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">
																				<p align="center">
																						<img src="01_8_22_3b.jpg" border="0" />
																				</p>
																		</td>
																</tr>
														</tbody>
												</table>
												<table width="100%">
														<tbody>
																<tr>
																		<td class="a14">从上表可以看出，这些经典软件虽然构造字符串Hash函数的方法不同，但是它们的效率都是不错的，相互之间差距很小，读者可以参考实际情况从其中借鉴使用。</td>
																</tr>
														</tbody>
												</table>
										</td>
								</tr>
						</tbody>
				</table>
				<!--EndFragment-->
		</center>
		<p style="FONT-SIZE: 12px">---<br />本文章使用<a href="http://www.kicoy.com">开源内容管理kicoy</a>发布</p>
<img src ="http://www.cnitblog.com/cockerel/aggbug/12071.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/cockerel/" target="_blank">踏雪赤兔</a> 2006-06-12 11:42 <a href="http://www.cnitblog.com/cockerel/archive/2006/06/12/12071.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>