﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-&amp;豪-文章分类-数据结构与算法</title><link>http://www.cppblog.com/qywyh/category/547.html</link><description>豪-&gt;blog</description><language>zh-cn</language><lastBuildDate>Mon, 19 May 2008 14:36:11 GMT</lastBuildDate><pubDate>Mon, 19 May 2008 14:36:11 GMT</pubDate><ttl>60</ttl><item><title>红黑树（数据结构大作业扩展版）</title><link>http://www.cppblog.com/qywyh/articles/32740.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Sun, 23 Sep 2007 13:32:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/32740.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/32740.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/32740.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/32740.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/32740.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: RBTree.h&nbsp;#ifndef&nbsp;RBTREE_H#define&nbsp;RBTREE_Hconst&nbsp;int&nbsp;RED&nbsp;=&nbsp;0;const&nbsp;int&nbsp;BLACK&nbsp;=&nbsp;1;template&nbsp;&lt;class&nbsp;KT,&nbsp;class&nbsp;RT&gt;class&n...&nbsp;&nbsp;<a href='http://www.cppblog.com/qywyh/articles/32740.html'>阅读全文</a><img src ="http://www.cppblog.com/qywyh/aggbug/32740.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-09-23 21:32 <a href="http://www.cppblog.com/qywyh/articles/32740.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pku3268 dij+heap</title><link>http://www.cppblog.com/qywyh/articles/28653.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Mon, 23 Jul 2007 12:51:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/28653.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/28653.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/28653.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/28653.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/28653.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 写了个比较通用的堆，可直接用作优先队列Silver Cow Party Time Limit:2000MS&nbsp; Memory Limit:65536KTotal Submit:1112 Accepted:326 DescriptionOne cow from each of N farms (1 &#8804; N &#8804; 1000) conveniently numb...&nbsp;&nbsp;<a href='http://www.cppblog.com/qywyh/articles/28653.html'>阅读全文</a><img src ="http://www.cppblog.com/qywyh/aggbug/28653.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-07-23 20:51 <a href="http://www.cppblog.com/qywyh/articles/28653.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>线段树类</title><link>http://www.cppblog.com/qywyh/articles/21446.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Sat, 07 Apr 2007 04:16:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/21446.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/21446.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/21446.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/21446.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/21446.html</trackback:ping><description><![CDATA[<pre>const int MAXN = 50000;
 
class SegmentTree {
public:
      int LSON[MAXN]; //LSON[i]为节点i的左儿子的序号
      int RSON[MAXN]; //RSON[i]为节点i的右儿子的序号
      int B[MAXN]; //B[i]为区间i左端点
      int E[MAXN]; //E[i]为区间i右端点
      int cnt[MAXN]; //cnt[i]为区间i的计数器
      int M[MAXN]; //M[i]为区间i的测度
      int lbd[MAXN]; //lbd[i]为区间i的左端点是否被覆盖
      int rbd[MAXN]; //rbd[i]为区间i的右端点是否被覆盖
      int lines[MAXN]; //lines[i]为区间i的连续线段数
      int root; //树根 初始化时候设为1
      int n; //树的节点数
      SegmentTree(int, int);
      void build(int, int);
      void insert(int, int, int);
      void del(int, int, int);
      void updateM(int); //更新测度
      void updateLines(int); //更新连续线段数
};
SegmentTree::SegmentTree(int a, int b) {
      root = 1;
      n = 0;
      memset(LSON, 0, sizeof(LSON));
      memset(RSON, 0, sizeof(RSON));
      memset(cnt, 0, sizeof(cnt));
      memset(M, 0, sizeof(M));
      memset(lines, 0, sizeof(lines));
      memset(lbd, 0, sizeof(lbd));
      memset(rbd, 0, sizeof(rbd));
      build(a, b);
}
void SegmentTree::build(int a, int b) {
      n += 1;
      int v = n;
      B[v] = a; E[v] = b; 
      if (b - a > 1) {
            LSON[v] = n + 1;
            build(a, (a+b)/2);
            RSON[v] = n + 1;
            build((a+b)/2, b);
      }
}
void SegmentTree::insert(int a, int b, int v) {
      if (!v) return ;
      if (a <= B[v] && E[v] <= b) {
            cnt[v]++;
            lbd[v] = rbd[v] = 1;
      } else if (E[v]-B[v] > 1) {
            if (a <(b[v]+e[v])/2) insert(a, b, LSON[v]);
            if (b > (B[v]+E[v])/2) insert(a, b, RSON[v]);
      }
      updateM(v);
      updateLines(v);
}
void SegmentTree::del(int a, int b, int v) {
      if (!v) return ;
      if (a <= B[v] && E[v] <= b) {
            cnt[v]--;
            if (a == B[v]) lbd[v] = 0;
            if (b == E[v]) rbd[v] = 0;
      } else if (E[v]-B[v] > 1) {
            if (a <(b[v]+e[v])/2) del(a, b, LSON[v]);
            if (b > (B[v]+E[v])/2) del(a, b, RSON[v]);
      }
      updateM(v);
      updateLines(v);
}
void SegmentTree::updateM(int v) {
      if (cnt[v] > 0) M[v] = E[v] - B[v];
      else {
            if (E[v]-B[v] == 1) M[v] = 0;
            else M[v] = M[LSON[v]] + M[RSON[v]];
      }
}
void SegmentTree::updateLines(int v) {
      if (cnt[v] > 0) lbd[v] = rbd[v] = lines[v] = 1;
      else {
            if (E[v]-B[v] == 1) lbd[v] = rbd[v] = lines[v] = 0;
            else {
                  lbd[v] = lbd[LSON[v]]; rbd[v] = rbd[RSON[v]];
                  lines[v] = lines[LSON[v]] + lines[RSON[v]] - rbd[LSON[v]] * lbd[RSON[v]];
            }
      }
}
</pre><img src ="http://www.cppblog.com/qywyh/aggbug/21446.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-04-07 12:16 <a href="http://www.cppblog.com/qywyh/articles/21446.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>LIS O(nlogn)</title><link>http://www.cppblog.com/qywyh/articles/21273.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Wed, 04 Apr 2007 15:38:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/21273.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/21273.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/21273.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/21273.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/21273.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" twffan="done"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><span style="COLOR: #0000ff" twffan="done">const</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;MAXN&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">100</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;d[MAXN];<br><img id=Codehighlighter1_59_515_Open_Image onclick="this.style.display='none'; Codehighlighter1_59_515_Open_Text.style.display='none'; Codehighlighter1_59_515_Closed_Image.style.display='inline'; Codehighlighter1_59_515_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_59_515_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_59_515_Closed_Text.style.display='none'; Codehighlighter1_59_515_Open_Image.style.display='inline'; Codehighlighter1_59_515_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;LIS(</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">*</span><span style="COLOR: #000000" twffan="done">a,&nbsp;</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;n)&nbsp;</span><span id=Codehighlighter1_59_515_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" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_59_515_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;i,&nbsp;l,&nbsp;r,&nbsp;m,&nbsp;len;<br><img id=Codehighlighter1_105_500_Open_Image onclick="this.style.display='none'; Codehighlighter1_105_500_Open_Text.style.display='none'; Codehighlighter1_105_500_Closed_Image.style.display='inline'; Codehighlighter1_105_500_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_105_500_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_105_500_Closed_Text.style.display='none'; Codehighlighter1_105_500_Open_Image.style.display='inline'; Codehighlighter1_105_500_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">for</span><span style="COLOR: #000000" twffan="done">&nbsp;(i</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">;&nbsp;i</span><span style="COLOR: #000000" twffan="done">&lt;=</span><span style="COLOR: #000000" twffan="done">n;&nbsp;i</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">)&nbsp;</span><span id=Codehighlighter1_105_500_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" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_105_500_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img id=Codehighlighter1_129_206_Open_Image onclick="this.style.display='none'; Codehighlighter1_129_206_Open_Text.style.display='none'; Codehighlighter1_129_206_Closed_Image.style.display='inline'; Codehighlighter1_129_206_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_129_206_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_129_206_Closed_Text.style.display='none'; Codehighlighter1_129_206_Open_Image.style.display='inline'; Codehighlighter1_129_206_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(a[i]&nbsp;</span><span style="COLOR: #000000" twffan="done">&gt;=</span><span style="COLOR: #000000" twffan="done">&nbsp;d[len])&nbsp;</span><span id=Codehighlighter1_129_206_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" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_129_206_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{&nbsp;</span><span style="COLOR: #008000" twffan="done">//</span><span style="COLOR: #008000" twffan="done">单调上升&nbsp;a[i]&nbsp;&gt;&nbsp;d[len]</span><span style="COLOR: #008000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done"></span><span style="COLOR: #000000" twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;len&nbsp;</span><span style="COLOR: #000000" twffan="done">+=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[len]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;a[i];<br><img id=Codehighlighter1_213_493_Open_Image onclick="this.style.display='none'; Codehighlighter1_213_493_Open_Text.style.display='none'; Codehighlighter1_213_493_Closed_Image.style.display='inline'; Codehighlighter1_213_493_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_213_493_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_213_493_Closed_Text.style.display='none'; Codehighlighter1_213_493_Open_Image.style.display='inline'; Codehighlighter1_213_493_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #0000ff" twffan="done">else</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span id=Codehighlighter1_213_493_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" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_213_493_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;len;<br><img id=Codehighlighter1_286_410_Open_Image onclick="this.style.display='none'; Codehighlighter1_286_410_Open_Text.style.display='none'; Codehighlighter1_286_410_Closed_Image.style.display='inline'; Codehighlighter1_286_410_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_286_410_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_286_410_Closed_Text.style.display='none'; Codehighlighter1_286_410_Open_Image.style.display='inline'; Codehighlighter1_286_410_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">while</span><span style="COLOR: #000000" twffan="done">&nbsp;&nbsp;(l&nbsp;</span><span style="COLOR: #000000" twffan="done">&lt;</span><span style="COLOR: #000000" twffan="done">&nbsp;r&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">)&nbsp;</span><span id=Codehighlighter1_286_410_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" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_286_410_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;(l&nbsp;</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">&nbsp;r)&nbsp;</span><span style="COLOR: #000000" twffan="done">/</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">2</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;&nbsp;(d[m]&nbsp;</span><span style="COLOR: #000000" twffan="done">&lt;=</span><span style="COLOR: #000000" twffan="done">&nbsp;a[i])&nbsp;l&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;m;&nbsp;</span><span style="COLOR: #008000" twffan="done">//</span><span style="COLOR: #008000" twffan="done">单调上升&nbsp;d[m]&nbsp;&lt;&nbsp;a[i]</span><span style="COLOR: #008000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done"></span><span style="COLOR: #000000" twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">else</span><span style="COLOR: #000000" twffan="done">&nbsp;r&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;m;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000" twffan="done">&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(d[l]&nbsp;</span><span style="COLOR: #000000" twffan="done">&gt;</span><span style="COLOR: #000000" twffan="done">&nbsp;a[i])&nbsp;d[l]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;a[i];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">else</span><span style="COLOR: #000000" twffan="done">&nbsp;d[r]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;a[i];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000" twffan="done">&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">return</span><span style="COLOR: #000000" twffan="done">&nbsp;len;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top twffan="done">}</span></span></div>
<img src ="http://www.cppblog.com/qywyh/aggbug/21273.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-04-04 23:38 <a href="http://www.cppblog.com/qywyh/articles/21273.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>凸包...</title><link>http://www.cppblog.com/qywyh/articles/20550.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Sat, 24 Mar 2007 18:43:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/20550.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/20550.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/20550.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/20550.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/20550.html</trackback:ping><description><![CDATA[
		<p>用差积做极角排序，减少浮点误差<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 src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#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.cppblog.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.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />typedef </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> XYType;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_97_113_Open_Image" onclick="this.style.display='none'; Codehighlighter1_97_113_Open_Text.style.display='none'; Codehighlighter1_97_113_Closed_Image.style.display='inline'; Codehighlighter1_97_113_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_97_113_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_97_113_Closed_Text.style.display='none'; Codehighlighter1_97_113_Open_Image.style.display='inline'; Codehighlighter1_97_113_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000"> POINT </span>
				<span id="Codehighlighter1_97_113_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_97_113_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    XYType x, y;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000"> ps;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_163_262_Open_Image" onclick="this.style.display='none'; Codehighlighter1_163_262_Open_Text.style.display='none'; Codehighlighter1_163_262_Closed_Image.style.display='inline'; Codehighlighter1_163_262_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_163_262_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_163_262_Closed_Text.style.display='none'; Codehighlighter1_163_262_Open_Image.style.display='inline'; Codehighlighter1_163_262_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />XYType cross(POINT p1, POINT p2, POINT p0) </span>
				<span id="Codehighlighter1_163_262_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_163_262_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">求矢量[p0,p1],[p0,p2]的差积;</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> (p1.x </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> p0.x) </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> (p2.y </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> p0.y) </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> (p2.x </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> p0.x) </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> (p1.y </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> p0.y);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img id="Codehighlighter1_293_591_Open_Image" onclick="this.style.display='none'; Codehighlighter1_293_591_Open_Text.style.display='none'; Codehighlighter1_293_591_Closed_Image.style.display='inline'; Codehighlighter1_293_591_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_293_591_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_293_591_Closed_Text.style.display='none'; Codehighlighter1_293_591_Open_Image.style.display='inline'; Codehighlighter1_293_591_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> cmp(POINT p1, POINT p2) </span>
				<span id="Codehighlighter1_293_591_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_293_591_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">以ps为中心的极角排序</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    XYType ax, ay, bx, by;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ax </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> p1.x </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> ps.x; ay </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> p1.y </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> ps.y;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    bx </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> p2.x </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> ps.x; by </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> p2.y </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> ps.y;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (ay </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> by </span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">) </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> by </span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> ay </span>
						<span style="COLOR: #000000">||</span>
						<span style="COLOR: #000000"> (by </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> ay </span>
						<span style="COLOR: #000000">&amp;&amp;</span>
						<span style="COLOR: #000000"> bx </span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> ax);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    XYType ret </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> cross(p1, p2, ps);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (ret </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: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (ret </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">) </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> bx </span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> ax;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (ret </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">) </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.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_606_1454_Open_Image" onclick="this.style.display='none'; Codehighlighter1_606_1454_Open_Text.style.display='none'; Codehighlighter1_606_1454_Closed_Image.style.display='inline'; Codehighlighter1_606_1454_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_606_1454_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_606_1454_Closed_Text.style.display='none'; Codehighlighter1_606_1454_Open_Image.style.display='inline'; Codehighlighter1_606_1454_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main() </span>
				<span id="Codehighlighter1_606_1454_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_606_1454_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    freopen(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">test.txt</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">r</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">, stdin);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    POINT arrP[</span>
						<span style="COLOR: #000000">100</span>
						<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> n </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, i, beg;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> stack[</span>
						<span style="COLOR: #000000">100</span>
						<span style="COLOR: #000000">], top;    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000"> (scanf(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">%d%d</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000">arrP[n].x, </span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000">arrP[n].y) </span>
						<span style="COLOR: #000000">!=</span>
						<span style="COLOR: #000000"> EOF) n</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_783_896_Open_Image" onclick="this.style.display='none'; Codehighlighter1_783_896_Open_Text.style.display='none'; Codehighlighter1_783_896_Closed_Image.style.display='inline'; Codehighlighter1_783_896_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_783_896_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_783_896_Closed_Text.style.display='none'; Codehighlighter1_783_896_Open_Image.style.display='inline'; Codehighlighter1_783_896_Open_Text.style.display='inline';" src="http://www.cppblog.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">; i</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">n; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) </span>
						<span id="Codehighlighter1_783_896_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_783_896_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (arrP[i].y </span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000"> arrP[</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">].y </span>
								<span style="COLOR: #000000">||</span>
								<span style="COLOR: #000000"> (arrP[i].y </span>
								<span style="COLOR: #000000">==</span>
								<span style="COLOR: #000000"> arrP[</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">].y </span>
								<span style="COLOR: #000000">&amp;&amp;</span>
								<span style="COLOR: #000000"> arrP[i].x </span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000"> arrP[</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">].x)) <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            swap(arrP[</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">], arrP[i]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ps.x </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> arrP[</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">].x; ps.y </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> arrP[</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">].y;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    sort(arrP</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">, arrP</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000">n, cmp);<br /><img src="http://www.cppblog.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">2</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) stack[i] </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    top </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">2</span>
						<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_1030_1136_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1030_1136_Open_Text.style.display='none'; Codehighlighter1_1030_1136_Closed_Image.style.display='inline'; Codehighlighter1_1030_1136_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1030_1136_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1030_1136_Closed_Text.style.display='none'; Codehighlighter1_1030_1136_Open_Image.style.display='inline'; Codehighlighter1_1030_1136_Open_Text.style.display='inline';" src="http://www.cppblog.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">3</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">n; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) </span>
						<span id="Codehighlighter1_1030_1136_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1030_1136_Open_Text">
								<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_1099_1113_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1099_1113_Open_Text.style.display='none'; Codehighlighter1_1099_1113_Closed_Image.style.display='inline'; Codehighlighter1_1099_1113_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1099_1113_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1099_1113_Closed_Text.style.display='none'; Codehighlighter1_1099_1113_Open_Image.style.display='inline'; Codehighlighter1_1099_1113_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">while</span>
								<span style="COLOR: #000000"> (cross(arrP[stack[top]], arrP[i], arrP[stack[top</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">]]) </span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">) </span>
								<span id="Codehighlighter1_1099_1113_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_1099_1113_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            top</span>
										<span style="COLOR: #000000">--</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        stack[</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">top] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_1162_1309_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1162_1309_Open_Text.style.display='none'; Codehighlighter1_1162_1309_Closed_Image.style.display='inline'; Codehighlighter1_1162_1309_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_1162_1309_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1162_1309_Closed_Text.style.display='none'; Codehighlighter1_1162_1309_Open_Image.style.display='inline'; Codehighlighter1_1162_1309_Open_Text.style.display='inline';" src="http://www.cppblog.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">top; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) </span>
						<span id="Codehighlighter1_1162_1309_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1162_1309_Open_Text">
								<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_1218_1244_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1218_1244_Open_Text.style.display='none'; Codehighlighter1_1218_1244_Closed_Image.style.display='inline'; Codehighlighter1_1218_1244_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1218_1244_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1218_1244_Closed_Text.style.display='none'; Codehighlighter1_1218_1244_Open_Image.style.display='inline'; Codehighlighter1_1218_1244_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (arrP[stack[i]].x </span>
								<span style="COLOR: #000000">==</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"> arrP[stack[i]].y </span>
								<span style="COLOR: #000000">==</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">) </span>
								<span id="Codehighlighter1_1218_1244_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_1218_1244_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            beg </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">break</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">printf("(%d,%d)\n", arrP[stack[i]].x, arrP[stack[i]].y);</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />
								</span>
								<span style="COLOR: #000000">    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_1341_1441_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1341_1441_Open_Text.style.display='none'; Codehighlighter1_1341_1441_Closed_Image.style.display='inline'; Codehighlighter1_1341_1441_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_1341_1441_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1341_1441_Closed_Text.style.display='none'; Codehighlighter1_1341_1441_Open_Image.style.display='inline'; Codehighlighter1_1341_1441_Open_Text.style.display='inline';" src="http://www.cppblog.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">beg; i</span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000">top</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000">beg; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) </span>
						<span id="Codehighlighter1_1341_1441_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1341_1441_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> k </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> i </span>
								<span style="COLOR: #000000">&gt;</span>
								<span style="COLOR: #000000"> top </span>
								<span style="COLOR: #000000">?</span>
								<span style="COLOR: #000000"> i </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000"> top </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000"> : i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        printf(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">(%d,%d)\n</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">, arrP[stack[k]].x, arrP[stack[k]].y);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/20550.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-03-25 02:43 <a href="http://www.cppblog.com/qywyh/articles/20550.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MinHeap</title><link>http://www.cppblog.com/qywyh/articles/19936.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Thu, 15 Mar 2007 16:44:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/19936.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/19936.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/19936.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/19936.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/19936.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />using namespace std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">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">10000</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />class MinHeap {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    MinHeap();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    MinHeap(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    void swim(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    void sink(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    void insert(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    void build();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    void decreaseKey(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> , </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> delMin();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> getMin();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    void heapSort(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">private</span>
				<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a[MAXN];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> hSize;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">arr;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />};<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />MinHeap::MinHeap() {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    hSize </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />MinHeap::MinHeap(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">b, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> bLen) {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    hSize </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> bLen;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    arr </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> b;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000"> (</span>
				<span style="COLOR: #0000ff">int</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">bLen; i</span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">) a[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"> b[i];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    build();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />void MinHeap::swim(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> p) {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> q </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> p </span>
				<span style="COLOR: #000000">&gt;&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, t </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> a[p];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000"> (q !</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">) {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000"> (t </span>
				<span style="COLOR: #000000">&gt;=</span>
				<span style="COLOR: #000000"> a[q]) break;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        a[p] </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> a[p];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        p </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> q;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        q </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> p </span>
				<span style="COLOR: #000000">&gt;&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    }<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    a[p] </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> t;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />void MinHeap::sink(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> p) {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> q </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> p </span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">, t </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> a[p];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000"> (q </span>
				<span style="COLOR: #000000">&lt;=</span>
				<span style="COLOR: #000000"> hSize) {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000"> (q </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> hSize </span>
				<span style="COLOR: #000000">&amp;&amp;</span>
				<span style="COLOR: #000000"> a[q] </span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> a[q</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">]) q</span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000"> (a[q] </span>
				<span style="COLOR: #000000">&gt;=</span>
				<span style="COLOR: #000000"> t) break;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        a[p] </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> a[q];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        p </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> q;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        q </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> p </span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    }<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    a[p] </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> t;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> MinHeap::delMin() {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> ret </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> a[</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    a[</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">] </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> a[hSize</span>
				<span style="COLOR: #000000">--</span>
				<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    sink(</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    return ret;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />void MinHeap::insert(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> key) {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    a[hSize</span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">] </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> key;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    swim(hSize);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />void MinHeap::decreaseKey(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> p, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> t) {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    a[p] </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> t;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    swim(p);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />void MinHeap::build() {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000"> (</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> i</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">hSize</span>
				<span style="COLOR: #000000">/</span>
				<span style="COLOR: #000000">2</span>
				<span style="COLOR: #000000">; i</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">; i</span>
				<span style="COLOR: #000000">--</span>
				<span style="COLOR: #000000">) sink(i);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> MinHeap::getMin() {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    return a[</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />void MinHeap::heapSort(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">b, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> bLen) {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    hSize </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> bLen;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000"> (</span>
				<span style="COLOR: #0000ff">int</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">bLen; i</span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">) a[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"> b[i];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    build();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> i, k </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000"> (hSize </span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">) {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        b[k</span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">] </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> a[</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        a[</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">] </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> a[hSize</span>
				<span style="COLOR: #000000">--</span>
				<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        sink(</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    }<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">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">bLen; i</span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">) cout </span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> b[i] </span>
				<span style="COLOR: #000000">&lt;&lt;</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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main() {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> b[] </span>
				<span style="COLOR: #000000">=</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">3</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: #000000">2</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">9</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">8</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">7</span>
				<span style="COLOR: #000000">};<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    MinHeap h;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    h.heapSort(b, sizeof(b)</span>
				<span style="COLOR: #000000">/</span>
				<span style="COLOR: #000000">sizeof(b[</span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">]));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    system(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">pause</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    return </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}</span>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/19936.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-03-16 00:44 <a href="http://www.cppblog.com/qywyh/articles/19936.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>树状数组</title><link>http://www.cppblog.com/qywyh/articles/19095.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Thu, 01 Mar 2007 14:02:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/19095.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/19095.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/19095.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/19095.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/19095.html</trackback:ping><description><![CDATA[那么,何为树形数组呢?? <br />下图中的C数组就是树状数组,a数组是原数组; <br /><img src="" align="left" border="0" twffan="done" /><br />可以发现这些规律: <br />C1=a1 <br />C2=a1+a2 <br />C3=a3 <br />C4=a1+a2+a3+a4 <br />C5=a5 <br />…… <br />C8=a1+a2+a3+a4+a5+a6+a7+a8 <br />…… <br />C2^n=a1+a2+….+a2^n <br /><br />对于序列a，我们设一个数组C定义C[t] = a[t – 2^k + 1] + … + a[t]，k为t在二进制下末尾0的个数。 <br />K的计算可以这样: <br />2^k=t and (t xor (t-1)) <br />以6为例 <br />               (6)10=(0110)2 <br />xor    6-1=(5)10=(0101)2 <br />                        (0011)2 <br />and          (6)10=(0110)2 <br />                        (0010)2 <br /><br />所以问题变的很简单,重要写几个函数就可以了; <br />求2^k的函数代码如下: <br /><table style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; MARGIN: 10px; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" cellspacing="0" cellpadding="10" width="90%"><tbody><tr><td bgcolor="#eeeeee"><font face="Courier New"><br />int Lowbit(int t) <br />{ <br />    return t &amp; ( t ^ ( t - 1 ) ); <br />} <br /></font></td></tr></tbody></table><br /><br />求1 -- end和的函数代码如下: <br /><table style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; MARGIN: 10px; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" cellspacing="0" cellpadding="10" width="90%"><tbody><tr><td bgcolor="#eeeeee"><font face="Courier New"><br />int Sum(int end) <br />{ <br />    int sum = 0; <br />    while(end &gt; 0) <br />    { <br />        sum += in[end]; <br />        end -= Lowbit(end); <br />    } <br />    return sum; <br />} <br /></font></td></tr></tbody></table><br /><br />对某位进行操作函数如下(以加法为例) <br /><table style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; MARGIN: 10px; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" cellspacing="0" cellpadding="10" width="90%"><tbody><tr><td bgcolor="#eeeeee"><font face="Courier New"><br />void plus(int pos , int num) <br />{ <br />    while(pos &lt;= n) <br />    { <br />          in[pos] += num; <br />          pos += Lowbit(pos); <br />    } <br />} <br /></font></td></tr></tbody></table><br /><br />有了这三个函数整个树形数组也就基本构建成功啦!! <br />对于刚才的一题,每次修改与询问都是对C数组做处理.空间复杂度有3N降为N,时间效率也有所提高.编程复杂度更是降了不少. <br /><br /><br />下面是用树状数组做的 pku star<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> N </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">32100</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> c[N];</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">树状数组</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000"><br /><img id="Codehighlighter1_99_128_Open_Image" onclick="this.style.display='none'; Codehighlighter1_99_128_Open_Text.style.display='none'; Codehighlighter1_99_128_Closed_Image.style.display='inline'; Codehighlighter1_99_128_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_99_128_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_99_128_Closed_Text.style.display='none'; Codehighlighter1_99_128_Open_Image.style.display='inline'; Codehighlighter1_99_128_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> lowBit(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> x) </span><span id="Codehighlighter1_99_128_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_99_128_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> x </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> (x </span><span style="COLOR: #000000">^</span><span style="COLOR: #000000"> (x </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.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_154_222_Open_Image" onclick="this.style.display='none'; Codehighlighter1_154_222_Open_Text.style.display='none'; Codehighlighter1_154_222_Closed_Image.style.display='inline'; Codehighlighter1_154_222_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_154_222_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_154_222_Closed_Text.style.display='none'; Codehighlighter1_154_222_Open_Image.style.display='inline'; Codehighlighter1_154_222_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> add(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> x, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> k) </span><span id="Codehighlighter1_154_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.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_154_222_Open_Text"><span style="COLOR: #000000">{ <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">a[x] += k</span><span style="COLOR: #008000"><br /><img id="Codehighlighter1_186_220_Open_Image" onclick="this.style.display='none'; Codehighlighter1_186_220_Open_Text.style.display='none'; Codehighlighter1_186_220_Closed_Image.style.display='inline'; Codehighlighter1_186_220_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_186_220_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_186_220_Closed_Text.style.display='none'; Codehighlighter1_186_220_Open_Image.style.display='inline'; Codehighlighter1_186_220_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (x </span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000"> N) </span><span id="Codehighlighter1_186_220_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_186_220_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        c[x] </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> k;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        x </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> lowBit(x);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_248_315_Open_Image" onclick="this.style.display='none'; Codehighlighter1_248_315_Open_Text.style.display='none'; Codehighlighter1_248_315_Closed_Image.style.display='inline'; Codehighlighter1_248_315_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_248_315_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_248_315_Closed_Text.style.display='none'; Codehighlighter1_248_315_Open_Image.style.display='inline'; Codehighlighter1_248_315_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> sub(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> x, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> k) </span><span id="Codehighlighter1_248_315_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_248_315_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">a[x] -= k</span><span style="COLOR: #008000"><br /><img id="Codehighlighter1_279_313_Open_Image" onclick="this.style.display='none'; Codehighlighter1_279_313_Open_Text.style.display='none'; Codehighlighter1_279_313_Closed_Image.style.display='inline'; Codehighlighter1_279_313_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_279_313_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_279_313_Closed_Text.style.display='none'; Codehighlighter1_279_313_Open_Image.style.display='inline'; Codehighlighter1_279_313_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (x </span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000"> N) </span><span id="Codehighlighter1_279_313_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_279_313_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        c[x] </span><span style="COLOR: #000000">-=</span><span style="COLOR: #000000"> k;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        x </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> lowBit(x);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_333_436_Open_Image" onclick="this.style.display='none'; Codehighlighter1_333_436_Open_Text.style.display='none'; Codehighlighter1_333_436_Closed_Image.style.display='inline'; Codehighlighter1_333_436_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_333_436_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_333_436_Closed_Text.style.display='none'; Codehighlighter1_333_436_Open_Image.style.display='inline'; Codehighlighter1_333_436_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> sum(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> x) </span><span id="Codehighlighter1_333_436_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_333_436_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">return sum(1..x);</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> ret </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img id="Codehighlighter1_385_421_Open_Image" onclick="this.style.display='none'; Codehighlighter1_385_421_Open_Text.style.display='none'; Codehighlighter1_385_421_Closed_Image.style.display='inline'; Codehighlighter1_385_421_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_385_421_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_385_421_Closed_Text.style.display='none'; Codehighlighter1_385_421_Open_Image.style.display='inline'; Codehighlighter1_385_421_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (x </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">) </span><span id="Codehighlighter1_385_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.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_385_421_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        ret </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> c[x];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        x </span><span style="COLOR: #000000">-=</span><span style="COLOR: #000000"> lowBit(x);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> ret;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">out</span><span style="COLOR: #000000">[N];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> f[N];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_473_726_Open_Image" onclick="this.style.display='none'; Codehighlighter1_473_726_Open_Text.style.display='none'; Codehighlighter1_473_726_Closed_Image.style.display='inline'; Codehighlighter1_473_726_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_473_726_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_473_726_Closed_Text.style.display='none'; Codehighlighter1_473_726_Open_Image.style.display='inline'; Codehighlighter1_473_726_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main() </span><span id="Codehighlighter1_473_726_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_473_726_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">pku2352</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i, j, k, x, y;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">n);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_556_639_Open_Image" onclick="this.style.display='none'; Codehighlighter1_556_639_Open_Text.style.display='none'; Codehighlighter1_556_639_Closed_Image.style.display='inline'; Codehighlighter1_556_639_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_556_639_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_556_639_Closed_Text.style.display='none'; Codehighlighter1_556_639_Open_Image.style.display='inline'; Codehighlighter1_556_639_Open_Text.style.display='inline';" src="http://www.cppblog.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">n; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">) </span><span id="Codehighlighter1_556_639_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_556_639_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">x, </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">y);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        x</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        add(x,</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">out</span><span style="COLOR: #000000">[sum(x</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"> f[x]]</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        f[x]</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_663_693_Open_Image" onclick="this.style.display='none'; Codehighlighter1_663_693_Open_Text.style.display='none'; Codehighlighter1_663_693_Closed_Image.style.display='inline'; Codehighlighter1_663_693_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_663_693_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_663_693_Closed_Text.style.display='none'; Codehighlighter1_663_693_Open_Image.style.display='inline'; Codehighlighter1_663_693_Open_Text.style.display='inline';" src="http://www.cppblog.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">n; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">) </span><span id="Codehighlighter1_663_693_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_663_693_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #0000ff">out</span><span style="COLOR: #000000">[i]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /><img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div><br /><img src ="http://www.cppblog.com/qywyh/aggbug/19095.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-03-01 22:02 <a href="http://www.cppblog.com/qywyh/articles/19095.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转贴] 快速计算某个日期是星期几的经验公式</title><link>http://www.cppblog.com/qywyh/articles/14021.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Sun, 22 Oct 2006 15:30:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/14021.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/14021.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/14021.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/14021.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/14021.html</trackback:ping><description><![CDATA[
		<p>
				<br />巧算星期几</p>
		<p>基姆。拉尔森</p>
		<p>基姆拥有计算机学科的博士学位。他对数据库，算法和数据结构有着浓厚的兴趣。他的联系地址是            （原文为丹麦文－－译者注） 31，DK－5270，Odense N,Denmark,或发 E-mail 至 :kslarsen@imada.ou.dk。</p>
		<p>简介</p>
		<p>布鲁斯 施耐尔</p>
		<p> </p>
		<p>“四，六，九，十一，三十天就齐……”儿歌是这么唱的；或许你也曾经掰着手指头翻来覆去地数，让赶上单数的指头代表只有30天的短月吧？这样的口诀对我们是很管用的（我就是念叨着这首傻乎乎的儿歌长大的），可是电脑就没有这份“灵感”了。当然，我们可以用一大堆IF－THEN－ELSES的语句或几个CASE来编写计算程序，让它计算某个指定日期是星期几。</p>
		<p> </p>
		<p>不过我更喜欢基姆拉尔森在本月的“算法小径”中为我们带来的新技巧，因为他的方法另辟蹊径，从一个全新的方向着手解决日期计算的问题。其实，并没有什么数学公式能算出某个指定日期是星期几，不过我们可以试着拼凑一个，如果我们的尝试成功了，你就能拥有一个易于编程的数学公式，并能用它自动计算哪天是星期几了。</p>
		<p> </p>
		<p>顺便说一句，如果你已经设计出更巧妙的算法，或是在已有的方法上有了新突破的话，不妨告诉我，我一定洗耳恭听。我的联系方法是<a href="mailto:schneier@chinet.com">schneier@chinet.com</a>，或者在DJJ编辑部给我留张便条就行。</p>
		<p> </p>
		<p>你有没有疑惑过你的电脑怎么就知道今天是星期三呢？就算你的电脑关机了，你重启后设定了新日期，它也能立即知道这天是星期几。</p>
		<p> </p>
		<p>在你还是个孩子的时候，你可能见过一种纪录记录着年，月，日的表格，只要加上几个数字，和它相连的另一张表格就会告诉你这个日期是星期几。当然，计算机硬盘的操作系统里也可以加入这样的计算表。不过有一种简单的方法可以轻松地算出某天是星期几；而且这个方法只占用很少的内存空间，而那些只能推算几百年的表格可就太占地方了。</p>
		<p> </p>
		<p>如果目前你的电脑还不具备推算与日期对应的星期数的功能，现在就不妨在自己的程序中试试下面的公式。</p>
		<p> </p>
		<p> </p>
		<p>创建公式</p>
		<p> </p>
		<p>首先，我们要用变量D，M和Y来表示日期。比如，1994年3月1日就用“D＝1，M＝3，Y＝4”记录。我们的目标是让计算结果在0到6之间。0代表星期一，1代表星期二，2代表星期三，依此类推。</p>
		<p> </p>
		<p>1994年3月1日是个星期二，那么“D mod 7(日期变量除以7的余数）)))”这个公式对于整个三月份都有效。比如3月18日是星期五，18 mod 7＝4；而4正代表星期五。别忘了，整数的除法和求模有着密切的关系。比方说，26除以7商3余5，这就是说，26除以7商数取整等于3，而26除以7求模（简写为26 mod 7）等于5。以上这些意味着19 mod 7=12 mod 7= 5 mod 7=5。在运算规则中，负数求模运算法相似，所以依此类推，-2 mod 7=5, -9 mod 7=5。</p>
		<p> </p>
		<p>在更正式的表达法中，统一用任意整数n和k表达上述关系，那么这个过程可以表达为n=qk+r，这里的q和r的取值范围同样是整数和0。表1中列出了所有月份的变换数据（shift information此处试译为“档级数据”，还请进一步校对－－译者注）。为了尽可能地得出规律，二月被排在最后，同理，一月也是如此。</p>
		<p> </p>
		<p>例1（a）中的公式是仿照表1中的变换数据栏所描述的模式而创建的。这个公式中的除法一律是商数取整。所以得数是最接近真正商数的整数。表2得出了此功能得出的有趣的数值。凭直觉，我们不难发现，当M(代表月份的变量)的值以1为单位递增时，2M就成倍增长，而3(M+1)/5就以3/5为增长倍数。</p>
		<p> </p>
		<p>这正是我们仿制3,2,3,2,3这个重复格式所需要的（表中右边的弯括号表明了这一点）。请注意，我们在以7为除数求模，那么从6到2的求模结果就会逐个增加3（顺序是6,0,1,2）。</p>
		<p> </p>
		<p>现在，我们发现了适用于逐月向下推算的校正方法，并希望把它加入刚才的尝试中，就是那个mod7公式。还以1994年3月1日为例，这个日期的M＝3。请注意，在例1（b）中，8 mod 7＝1，所以当整个公式合并时，必须减去1。在做以7为除数求模的运算时，减1和加6是一样的，因为-1 mod 7=6 mod 7=6。</p>
		<p> </p>
		<p>这样，例1（c）中的公式就可以计算这一年中剩下的月份了。其实，既然我们把一月和二月排在表1的最后，那么只要我们把它们看成是十三月和十四月，就能接着推算1995年的前两个月了。这是因为，虽然它们并不是一个完整的3,2,3,2,3结构，但恰好可以是这个结构的开始，为了使这个公式更完善，我们还是最好把一月和二月看成是上一年的十三月和十四月。</p>
		<p> </p>
		<p> </p>
		<p>加入年份</p>
		<p> </p>
		<p>顺着年份向下找，我们观察到1995年3月1日是星期三。这说明，每增加一年，我们公式的计算结果就会增加1。这太简单了，我们只要简单地把年份加上去就行了。再提醒你一次，我们必须确保出发点是正确的。由于1994 mod 7=6，我们在把Y加入已有的公式时就必须减去6。由此改进的例2(a)就更完善了。</p>
		<p> </p>
		<p>1996年是个闰年，这带来了我们的下一个问题。这一年的3月1日是星期五，而不是刚才的公式推算出的星期四。所以每当我们碰上闰年时还得多加上1。判断闰年的规则是，能被4整除，并能被100和400同时整除的年份就是闰年。就这样，我们在原有的基础上添加Y/4--Y/100+Y/400。再强调一下，我们必须从一开始就确保正确。既然(1994/4--1994/100+1994/400) mod 7=(498--19+4) mod 7=483 mod 7=0,所以就不用再做任何调整了。这样，例2(b)就是我们最终的成果了。这个公式能一直工作下去，除非改变现行的日历系统。作为示例，让我们试着推算一下2000年7月4日：(4+2*3+(7+1)/5+2000+2000/4--2000/100+2000/400) mod 7= (4+14+2000+500--20+5) mod 7=2507 mod 7=1，所以那一天是星期二。</p>
		<p> </p>
		<p>这个公式还能推算过去的日期；然而计算范围有限，让我们看看1752年9月14号这个星期四吧，我们的公式最远只能推算到这里了。不过像“1963年11月22日你在哪里”这样的日常问题中提到的日期还是可以轻松应对的：(22+2*11+3(11+1)/5+1963+1963/4--1963/100+1963/400) mod 7=(22+22+7+1963+490--19+4) mod 7=2489 mod 7=4。那天就是星期五。</p>
		<p> </p>
		<p>例3例子3是一个C语言程序，按照把这个公式自动推算给定日期是星期几。</p>
		<p> </p>
		<p> </p>
		<p> </p>
		<p>表1：每月变换数据</p>
		<p>月份         天数         变换</p>
		<p>三月          31            3</p>
		<p>四月          30            2</p>
		<p>五月          31            3</p>
		<p>六月          30            2</p>
		<p>七月          31            3</p>
		<p>八月          31            3</p>
		<p>九月          30            2</p>
		<p>十月          31            3</p>
		<p>十一月        30            2</p>
		<p>十二月        31            3</p>
		<p>一月          31            3</p>
		<p>二月          28            3</p>
		<p> </p>
		<p> </p>
		<p> </p>
		<p>表2：仿制变换数据形式的功能。例1中建立的公式可以适用于1994年。例2把这个公式的功能扩展到可以应用在不同的年份进行推算。</p>
		<p> </p>
		<p>例3：用C语言程序表达上述公式</p>
		<p>/*计算指定日期是星期几。默认输入的*/</p>
		<p>/*数字代表正确的日期*/</p>
		<p>/* 推算给定日期是星期几，假定输入是正确的数据 */<br />#include <br />char *name[] = { "Monday",<br />                 "Tuesday",<br />                 "Wednesday",<br />                "Thursday",<br />                "Friday",<br />                "Saturday",<br />                "Sunday"<br />               };<br />void main(){<br />  int D,M,Y,A;<br />  printf("Day: "); fflush(stdout);<br />  scanf("%d",&amp;D);<br />  printf("Month: "); fflush(stdout);<br />  scanf("%d",&amp;M);<br />  printf("Year: "); fflush(stdout);<br />  scanf("%d",&amp;Y);<br />/* January and February are treated as month 13 and 14, */<br />/* respectively, from the year before.                  */<br />  if ((M == 1) || (M == 2)){<br />    M += 12;<br />    Y--;<br />  }<br />  A = (D + 2*M + 3*(M+1)/5 + Y + Y/4 - Y/100 + Y/400) % 7;<br />  printf("It's a %s.\n",name[A]);<br />}</p>
		<p> </p>
		<p> </p>
		<p>/*一月和二月被当作前一年的*/</p>
		<p>/*十三月和十四月分别处理*/</p>
		<p> </p>
		<p> <br /> <br /> <br /></p>
<img src ="http://www.cppblog.com/qywyh/aggbug/14021.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-10-22 23:30 <a href="http://www.cppblog.com/qywyh/articles/14021.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>拓扑排序</title><link>http://www.cppblog.com/qywyh/articles/13566.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Wed, 11 Oct 2006 05:05:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/13566.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/13566.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/13566.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/13566.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/13566.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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">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">100</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> list[MAXN][MAXN];</span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">邻接表 </span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> next[MAXN];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> vInDegree[MAXN]; </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">定点入度 </span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> tpV[MAXN]; </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">拓扑序列</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.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"> 定点数 </span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> TopoSort()<br /><img id="Codehighlighter1_191_756_Open_Image" onclick="this.style.display='none'; Codehighlighter1_191_756_Open_Text.style.display='none'; Codehighlighter1_191_756_Closed_Image.style.display='inline'; Codehighlighter1_191_756_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_191_756_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_191_756_Closed_Text.style.display='none'; Codehighlighter1_191_756_Open_Image.style.display='inline'; Codehighlighter1_191_756_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_191_756_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_191_756_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">不能求最大并行组 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">使用静态链盏</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.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;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> cnt </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> top </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 id="Codehighlighter1_296_404_Open_Image" onclick="this.style.display='none'; Codehighlighter1_296_404_Open_Text.style.display='none'; Codehighlighter1_296_404_Closed_Image.style.display='inline'; Codehighlighter1_296_404_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_296_404_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_296_404_Closed_Text.style.display='none'; Codehighlighter1_296_404_Open_Image.style.display='inline'; Codehighlighter1_296_404_Open_Text.style.display='inline';" src="http://www.cppblog.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">n; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) </span>
						<span id="Codehighlighter1_296_404_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_296_404_Open_Text">
								<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_329_398_Open_Image" onclick="this.style.display='none'; Codehighlighter1_329_398_Open_Text.style.display='none'; Codehighlighter1_329_398_Closed_Image.style.display='inline'; Codehighlighter1_329_398_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_329_398_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_329_398_Closed_Text.style.display='none'; Codehighlighter1_329_398_Open_Image.style.display='inline'; Codehighlighter1_329_398_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (vInDegree[i] </span>
								<span style="COLOR: #000000">==</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">) </span>
								<span id="Codehighlighter1_329_398_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_329_398_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.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000">            vInDegree[i] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> top;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            top </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_427_738_Open_Image" onclick="this.style.display='none'; Codehighlighter1_427_738_Open_Text.style.display='none'; Codehighlighter1_427_738_Closed_Image.style.display='inline'; Codehighlighter1_427_738_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_427_738_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_427_738_Closed_Text.style.display='none'; Codehighlighter1_427_738_Open_Image.style.display='inline'; Codehighlighter1_427_738_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000"> (top </span>
						<span style="COLOR: #000000">&gt;=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">) </span>
						<span id="Codehighlighter1_427_738_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_427_738_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        t </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> top;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        top </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> vInDegree[top]; </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">出盏 </span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        tpV[cnt</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> t;<br /><img id="Codehighlighter1_540_732_Open_Image" onclick="this.style.display='none'; Codehighlighter1_540_732_Open_Text.style.display='none'; Codehighlighter1_540_732_Closed_Image.style.display='inline'; Codehighlighter1_540_732_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_540_732_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_540_732_Closed_Text.style.display='none'; Codehighlighter1_540_732_Open_Image.style.display='inline'; Codehighlighter1_540_732_Open_Text.style.display='inline';" src="http://www.cppblog.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">next[t]; i</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">) </span>
								<span id="Codehighlighter1_540_732_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_540_732_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            vInDegree[list[t][i]]</span>
										<span style="COLOR: #000000">--</span>
										<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_623_722_Open_Image" onclick="this.style.display='none'; Codehighlighter1_623_722_Open_Text.style.display='none'; Codehighlighter1_623_722_Closed_Image.style.display='inline'; Codehighlighter1_623_722_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_623_722_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_623_722_Closed_Text.style.display='none'; Codehighlighter1_623_722_Open_Image.style.display='inline'; Codehighlighter1_623_722_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (vInDegree[list[t][i]] </span>
										<span style="COLOR: #000000">==</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">) </span>
										<span id="Codehighlighter1_623_722_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_623_722_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.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												</span>
												<span style="COLOR: #000000">                vInDegree[list[t][i]] </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> top;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                top </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> list[t][i];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> cnt;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()<br /><img id="Codehighlighter1_770_1312_Open_Image" onclick="this.style.display='none'; Codehighlighter1_770_1312_Open_Text.style.display='none'; Codehighlighter1_770_1312_Closed_Image.style.display='inline'; Codehighlighter1_770_1312_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_770_1312_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_770_1312_Closed_Text.style.display='none'; Codehighlighter1_770_1312_Open_Image.style.display='inline'; Codehighlighter1_770_1312_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_770_1312_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_770_1312_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i, j, b;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    freopen(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">test.txt</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">r</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">, stdin);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    scanf(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">%d</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000">n);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    memset(vInDegree, </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #0000ff">sizeof</span>
						<span style="COLOR: #000000">(vInDegree));<br /><img id="Codehighlighter1_916_1099_Open_Image" onclick="this.style.display='none'; Codehighlighter1_916_1099_Open_Text.style.display='none'; Codehighlighter1_916_1099_Closed_Image.style.display='inline'; Codehighlighter1_916_1099_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_916_1099_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_916_1099_Closed_Text.style.display='none'; Codehighlighter1_916_1099_Open_Image.style.display='inline'; Codehighlighter1_916_1099_Open_Text.style.display='inline';" src="http://www.cppblog.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">n; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) </span>
						<span id="Codehighlighter1_916_1099_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_916_1099_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        scanf(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">%d</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">, </span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000">b);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        scanf(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">%d</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">, </span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000">next[b]);<br /><img id="Codehighlighter1_1008_1093_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1008_1093_Open_Text.style.display='none'; Codehighlighter1_1008_1093_Closed_Image.style.display='inline'; Codehighlighter1_1008_1093_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1008_1093_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1008_1093_Closed_Text.style.display='none'; Codehighlighter1_1008_1093_Open_Image.style.display='inline'; Codehighlighter1_1008_1093_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (j</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">; j</span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000">next[b]; j</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">) </span>
								<span id="Codehighlighter1_1008_1093_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_1008_1093_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            scanf(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">%d</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">, </span>
										<span style="COLOR: #000000">&amp;</span>
										<span style="COLOR: #000000">list[b][j]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            vInDegree[list[b][j]]</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_1126_1219_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1126_1219_Open_Text.style.display='none'; Codehighlighter1_1126_1219_Closed_Image.style.display='inline'; Codehighlighter1_1126_1219_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_1126_1219_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1126_1219_Closed_Text.style.display='none'; Codehighlighter1_1126_1219_Open_Image.style.display='inline'; Codehighlighter1_1126_1219_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (TopoSort() </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> n) </span>
						<span id="Codehighlighter1_1126_1219_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1126_1219_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.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; i</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">) <br /><img src="http://www.cppblog.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">, tpV[i]);<br /><img src="http://www.cppblog.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 id="Codehighlighter1_1226_1273_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1226_1273_Open_Text.style.display='none'; Codehighlighter1_1226_1273_Closed_Image.style.display='inline'; Codehighlighter1_1226_1273_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1226_1273_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1226_1273_Closed_Text.style.display='none'; Codehighlighter1_1226_1273_Open_Image.style.display='inline'; Codehighlighter1_1226_1273_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000"> </span>
						<span id="Codehighlighter1_1226_1273_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1226_1273_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        printf(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">can't not be Sort!\n</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">system("pause");</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    </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.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
		<p>
				<br /> </p>
<img src ="http://www.cppblog.com/qywyh/aggbug/13566.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-10-11 13:05 <a href="http://www.cppblog.com/qywyh/articles/13566.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>合并排序</title><link>http://www.cppblog.com/qywyh/articles/13507.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Mon, 09 Oct 2006 17:11:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/13507.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/13507.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/13507.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/13507.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/13507.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 id="Codehighlighter1_0_10_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_10_Open_Text.style.display='none'; Codehighlighter1_0_10_Closed_Image.style.display='inline'; Codehighlighter1_0_10_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
				<img id="Codehighlighter1_0_10_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_0_10_Closed_Text.style.display='none'; Codehighlighter1_0_10_Open_Image.style.display='inline'; Codehighlighter1_0_10_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				<span id="Codehighlighter1_0_10_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_0_10_Open_Text">
						<span style="COLOR: #008000">/*</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />合并排序 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /></span>
						<span style="COLOR: #008000">*/</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.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.cppblog.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.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> Merge(T c[], T d[], </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> l, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> m, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> r) <br /><img id="Codehighlighter1_120_475_Open_Image" onclick="this.style.display='none'; Codehighlighter1_120_475_Open_Text.style.display='none'; Codehighlighter1_120_475_Closed_Image.style.display='inline'; Codehighlighter1_120_475_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_120_475_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_120_475_Closed_Text.style.display='none'; Codehighlighter1_120_475_Open_Image.style.display='inline'; Codehighlighter1_120_475_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_120_475_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_120_475_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> l, j </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> m </span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">, k </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> l;<br /><img id="Codehighlighter1_184_303_Open_Image" onclick="this.style.display='none'; Codehighlighter1_184_303_Open_Text.style.display='none'; Codehighlighter1_184_303_Closed_Image.style.display='inline'; Codehighlighter1_184_303_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_184_303_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_184_303_Closed_Text.style.display='none'; Codehighlighter1_184_303_Open_Image.style.display='inline'; Codehighlighter1_184_303_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000"> (i </span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000"> m </span>
						<span style="COLOR: #000000">&amp;&amp;</span>
						<span style="COLOR: #000000"> j </span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000"> r) </span>
						<span id="Codehighlighter1_184_303_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_184_303_Open_Text">
								<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_212_251_Open_Image" onclick="this.style.display='none'; Codehighlighter1_212_251_Open_Text.style.display='none'; Codehighlighter1_212_251_Closed_Image.style.display='inline'; Codehighlighter1_212_251_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_212_251_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_212_251_Closed_Text.style.display='none'; Codehighlighter1_212_251_Open_Image.style.display='inline'; Codehighlighter1_212_251_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (c[i] </span>
								<span style="COLOR: #000000">&lt;=</span>
								<span style="COLOR: #000000"> c[j]) </span>
								<span id="Codehighlighter1_212_251_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_212_251_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            d[k</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> c[i</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">];<br /><img id="Codehighlighter1_258_297_Open_Image" onclick="this.style.display='none'; Codehighlighter1_258_297_Open_Text.style.display='none'; Codehighlighter1_258_297_Closed_Image.style.display='inline'; Codehighlighter1_258_297_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_258_297_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_258_297_Closed_Text.style.display='none'; Codehighlighter1_258_297_Open_Image.style.display='inline'; Codehighlighter1_258_297_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000"> </span>
								<span id="Codehighlighter1_258_297_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_258_297_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            d[k</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> c[j</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_320_393_Open_Image" onclick="this.style.display='none'; Codehighlighter1_320_393_Open_Text.style.display='none'; Codehighlighter1_320_393_Closed_Image.style.display='inline'; Codehighlighter1_320_393_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_320_393_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_320_393_Closed_Text.style.display='none'; Codehighlighter1_320_393_Open_Image.style.display='inline'; Codehighlighter1_320_393_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (i </span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> m) </span>
						<span id="Codehighlighter1_320_393_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_320_393_Open_Text">
								<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_350_387_Open_Image" onclick="this.style.display='none'; Codehighlighter1_350_387_Open_Text.style.display='none'; Codehighlighter1_350_387_Closed_Image.style.display='inline'; Codehighlighter1_350_387_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_350_387_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_350_387_Closed_Text.style.display='none'; Codehighlighter1_350_387_Open_Image.style.display='inline'; Codehighlighter1_350_387_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (; j </span>
								<span style="COLOR: #000000">&lt;=</span>
								<span style="COLOR: #000000"> r; j</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">) </span>
								<span id="Codehighlighter1_350_387_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_350_387_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            d[k</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> c[j];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img id="Codehighlighter1_400_473_Open_Image" onclick="this.style.display='none'; Codehighlighter1_400_473_Open_Text.style.display='none'; Codehighlighter1_400_473_Closed_Image.style.display='inline'; Codehighlighter1_400_473_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_400_473_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_400_473_Closed_Text.style.display='none'; Codehighlighter1_400_473_Open_Image.style.display='inline'; Codehighlighter1_400_473_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000"> </span>
						<span id="Codehighlighter1_400_473_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_400_473_Open_Text">
								<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_430_467_Open_Image" onclick="this.style.display='none'; Codehighlighter1_430_467_Open_Text.style.display='none'; Codehighlighter1_430_467_Closed_Image.style.display='inline'; Codehighlighter1_430_467_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_430_467_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_430_467_Closed_Text.style.display='none'; Codehighlighter1_430_467_Open_Image.style.display='inline'; Codehighlighter1_430_467_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (; i </span>
								<span style="COLOR: #000000">&lt;=</span>
								<span style="COLOR: #000000"> m; i</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">) </span>
								<span id="Codehighlighter1_430_467_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_430_467_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            d[k</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> c[i];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> Copy(T c[], T d[], </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> l, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> r) <br /><img id="Codehighlighter1_535_610_Open_Image" onclick="this.style.display='none'; Codehighlighter1_535_610_Open_Text.style.display='none'; Codehighlighter1_535_610_Closed_Image.style.display='inline'; Codehighlighter1_535_610_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_535_610_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_535_610_Closed_Text.style.display='none'; Codehighlighter1_535_610_Open_Image.style.display='inline'; Codehighlighter1_535_610_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_535_610_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_535_610_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i;<br /><img id="Codehighlighter1_573_608_Open_Image" onclick="this.style.display='none'; Codehighlighter1_573_608_Open_Text.style.display='none'; Codehighlighter1_573_608_Closed_Image.style.display='inline'; Codehighlighter1_573_608_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_573_608_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_573_608_Closed_Text.style.display='none'; Codehighlighter1_573_608_Open_Image.style.display='inline'; Codehighlighter1_573_608_Open_Text.style.display='inline';" src="http://www.cppblog.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">l; i</span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000">r; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) </span>
						<span id="Codehighlighter1_573_608_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_573_608_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        c[i] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> d[i];        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> MergePass(T a[], T b[], </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> l, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> r)<br /><img id="Codehighlighter1_674_856_Open_Image" onclick="this.style.display='none'; Codehighlighter1_674_856_Open_Text.style.display='none'; Codehighlighter1_674_856_Closed_Image.style.display='inline'; Codehighlighter1_674_856_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_674_856_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_674_856_Closed_Text.style.display='none'; Codehighlighter1_674_856_Open_Image.style.display='inline'; Codehighlighter1_674_856_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_674_856_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_674_856_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> m;<br /><img id="Codehighlighter1_702_854_Open_Image" onclick="this.style.display='none'; Codehighlighter1_702_854_Open_Text.style.display='none'; Codehighlighter1_702_854_Closed_Image.style.display='inline'; Codehighlighter1_702_854_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_702_854_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_702_854_Closed_Text.style.display='none'; Codehighlighter1_702_854_Open_Image.style.display='inline'; Codehighlighter1_702_854_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (l </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> r) </span>
						<span id="Codehighlighter1_702_854_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_702_854_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        m </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> (l </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> r) </span>
								<span style="COLOR: #000000">/</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">2</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        MergePass(a, b, l, m);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        MergePass(a, b, m</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">, r);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        Merge(a, b, l, m, r);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        Copy(a, b, l, r); <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> MergeSort(T a[], </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_906_958_Open_Image" onclick="this.style.display='none'; Codehighlighter1_906_958_Open_Text.style.display='none'; Codehighlighter1_906_958_Closed_Image.style.display='inline'; Codehighlighter1_906_958_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_906_958_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_906_958_Closed_Text.style.display='none'; Codehighlighter1_906_958_Open_Image.style.display='inline'; Codehighlighter1_906_958_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_906_958_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_906_958_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    T </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">b </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">new</span>
						<span style="COLOR: #000000"> T[n];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    MergePass(a, b, </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, n</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()<br /><img id="Codehighlighter1_972_1141_Open_Image" onclick="this.style.display='none'; Codehighlighter1_972_1141_Open_Text.style.display='none'; Codehighlighter1_972_1141_Closed_Image.style.display='inline'; Codehighlighter1_972_1141_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_972_1141_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_972_1141_Closed_Text.style.display='none'; Codehighlighter1_972_1141_Open_Image.style.display='inline'; Codehighlighter1_972_1141_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_972_1141_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_972_1141_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i, j;<br /><img id="Codehighlighter1_1002_1016_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1002_1016_Open_Text.style.display='none'; Codehighlighter1_1002_1016_Closed_Image.style.display='inline'; Codehighlighter1_1002_1016_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1002_1016_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1002_1016_Closed_Text.style.display='none'; Codehighlighter1_1002_1016_Open_Image.style.display='inline'; Codehighlighter1_1002_1016_Open_Text.style.display='inline';" src="http://www.cppblog.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 style="COLOR: #000000"> </span>
						<span id="Codehighlighter1_1002_1016_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1002_1016_Open_Text">
								<span style="COLOR: #000000">{</span>
								<span style="COLOR: #000000">5</span>
								<span style="COLOR: #000000">, </span>
								<span style="COLOR: #000000">9</span>
								<span style="COLOR: #000000">, </span>
								<span style="COLOR: #000000">3</span>
								<span style="COLOR: #000000">, </span>
								<span style="COLOR: #000000">7</span>
								<span style="COLOR: #000000">, </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">}</span>
						</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    MergeSort(a, </span>
						<span style="COLOR: #000000">5</span>
						<span style="COLOR: #000000">);<br /><img id="Codehighlighter1_1064_1099_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1064_1099_Open_Text.style.display='none'; Codehighlighter1_1064_1099_Closed_Image.style.display='inline'; Codehighlighter1_1064_1099_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1064_1099_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1064_1099_Closed_Text.style.display='none'; Codehighlighter1_1064_1099_Open_Image.style.display='inline'; Codehighlighter1_1064_1099_Open_Text.style.display='inline';" src="http://www.cppblog.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">5</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) </span>
						<span id="Codehighlighter1_1064_1099_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1064_1099_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.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">, a[i]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    system(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">pause</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/13507.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-10-10 01:11 <a href="http://www.cppblog.com/qywyh/articles/13507.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>二分图最大匹配（匈牙利算法）</title><link>http://www.cppblog.com/qywyh/articles/13197.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Sat, 30 Sep 2006 18:15:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/13197.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/13197.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/13197.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/13197.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/13197.html</trackback:ping><description><![CDATA[
		<p>算法轮廓：<br />(1)置M为空<br />(2)找出一条增广路径P，通过取反操作获得更大的匹配M’代替M<br />(3)重复(2)操作直到找不出增广路径为止<br />V2:</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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">fstream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">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">100</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> uN, vN;  </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">u,ｖ数目 </span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">bool</span>
				<span style="COLOR: #000000"> g[MAXN][MAXN];</span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">g[i][j] 表示 xi与yj相连 </span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> xM[MAXN], yM[MAXN]; </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> 输出量 </span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">bool</span>
				<span style="COLOR: #000000"> chk[MAXN]; </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">辅助量 检查某轮 y[v]是否被check </span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">bool</span>
				<span style="COLOR: #000000"> SearchPath(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> u)<br /><img id="Codehighlighter1_246_450_Open_Image" onclick="this.style.display='none'; Codehighlighter1_246_450_Open_Text.style.display='none'; Codehighlighter1_246_450_Closed_Image.style.display='inline'; Codehighlighter1_246_450_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_246_450_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_246_450_Closed_Text.style.display='none'; Codehighlighter1_246_450_Open_Image.style.display='inline'; Codehighlighter1_246_450_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_246_450_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_246_450_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> v;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (v</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">; v</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">vN; v</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_279_433_Open_Image" onclick="this.style.display='none'; Codehighlighter1_279_433_Open_Text.style.display='none'; Codehighlighter1_279_433_Closed_Image.style.display='inline'; Codehighlighter1_279_433_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_279_433_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_279_433_Closed_Text.style.display='none'; Codehighlighter1_279_433_Open_Image.style.display='inline'; Codehighlighter1_279_433_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_279_433_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_279_433_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (g[u][v] </span>
								<span style="COLOR: #000000">&amp;&amp;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">!</span>
								<span style="COLOR: #000000">chk[v])<br /><img id="Codehighlighter1_309_430_Open_Image" onclick="this.style.display='none'; Codehighlighter1_309_430_Open_Text.style.display='none'; Codehighlighter1_309_430_Closed_Image.style.display='inline'; Codehighlighter1_309_430_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_309_430_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_309_430_Closed_Text.style.display='none'; Codehighlighter1_309_430_Open_Image.style.display='inline'; Codehighlighter1_309_430_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_309_430_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_309_430_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            chk[v] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">true</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (yM[v] </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"> </span>
										<span style="COLOR: #000000">||</span>
										<span style="COLOR: #000000"> SearchPath(yM[v])) <br /><img id="Codehighlighter1_374_426_Open_Image" onclick="this.style.display='none'; Codehighlighter1_374_426_Open_Text.style.display='none'; Codehighlighter1_374_426_Closed_Image.style.display='inline'; Codehighlighter1_374_426_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_374_426_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_374_426_Closed_Text.style.display='none'; Codehighlighter1_374_426_Open_Image.style.display='inline'; Codehighlighter1_374_426_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span id="Codehighlighter1_374_426_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_374_426_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                yM[v] </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> u;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                xM[u] </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> v;<br /><img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </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.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> MaxMatch()<br /><img id="Codehighlighter1_469_684_Open_Image" onclick="this.style.display='none'; Codehighlighter1_469_684_Open_Text.style.display='none'; Codehighlighter1_469_684_Closed_Image.style.display='inline'; Codehighlighter1_469_684_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_469_684_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_469_684_Closed_Text.style.display='none'; Codehighlighter1_469_684_Open_Image.style.display='inline'; Codehighlighter1_469_684_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_469_684_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_469_684_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> u;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> ret </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    memset(xM, </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">(xM));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    memset(yM, </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">(yM));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (u</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">; u</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">uN; u</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_574_669_Open_Image" onclick="this.style.display='none'; Codehighlighter1_574_669_Open_Text.style.display='none'; Codehighlighter1_574_669_Closed_Image.style.display='inline'; Codehighlighter1_574_669_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_574_669_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_574_669_Closed_Text.style.display='none'; Codehighlighter1_574_669_Open_Image.style.display='inline'; Codehighlighter1_574_669_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_574_669_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_574_669_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (xM[u] </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 id="Codehighlighter1_597_666_Open_Image" onclick="this.style.display='none'; Codehighlighter1_597_666_Open_Text.style.display='none'; Codehighlighter1_597_666_Closed_Image.style.display='inline'; Codehighlighter1_597_666_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_597_666_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_597_666_Closed_Text.style.display='none'; Codehighlighter1_597_666_Open_Image.style.display='inline'; Codehighlighter1_597_666_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_597_666_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_597_666_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            memset(chk, </span>
										<span style="COLOR: #0000ff">false</span>
										<span style="COLOR: #000000">, </span>
										<span style="COLOR: #0000ff">sizeof</span>
										<span style="COLOR: #000000">(chk));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (SearchPath(u)) ret</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> ret;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()<br /><img id="Codehighlighter1_698_1046_Open_Image" onclick="this.style.display='none'; Codehighlighter1_698_1046_Open_Text.style.display='none'; Codehighlighter1_698_1046_Closed_Image.style.display='inline'; Codehighlighter1_698_1046_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_698_1046_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_698_1046_Closed_Text.style.display='none'; Codehighlighter1_698_1046_Open_Image.style.display='inline'; Codehighlighter1_698_1046_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_698_1046_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_698_1046_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i, k; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> tU, tV;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ifstream cin(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">test.txt</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cin </span>
						<span style="COLOR: #000000">&gt;&gt;</span>
						<span style="COLOR: #000000"> uN </span>
						<span style="COLOR: #000000">&gt;&gt;</span>
						<span style="COLOR: #000000"> vN </span>
						<span style="COLOR: #000000">&gt;&gt;</span>
						<span style="COLOR: #000000"> k;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    memset(g, </span>
						<span style="COLOR: #0000ff">false</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #0000ff">sizeof</span>
						<span style="COLOR: #000000">(g));<br /><img src="http://www.cppblog.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">k; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_827_869_Open_Image" onclick="this.style.display='none'; Codehighlighter1_827_869_Open_Text.style.display='none'; Codehighlighter1_827_869_Closed_Image.style.display='inline'; Codehighlighter1_827_869_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_827_869_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_827_869_Closed_Text.style.display='none'; Codehighlighter1_827_869_Open_Image.style.display='inline'; Codehighlighter1_827_869_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_827_869_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_827_869_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        cin </span>
								<span style="COLOR: #000000">&gt;&gt;</span>
								<span style="COLOR: #000000"> tU </span>
								<span style="COLOR: #000000">&gt;&gt;</span>
								<span style="COLOR: #000000"> tV;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        g[tU][tV] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">true</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> M </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">  MaxMatch();<br /><img src="http://www.cppblog.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">"</span>
						<span style="COLOR: #000000">Total Match: </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> M </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> endl;<br /><img src="http://www.cppblog.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">MAXN; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (xM[i] </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.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            cout </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> 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">'</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> xM[i] </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    system(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">pause</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_1051_1108_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1051_1108_Open_Text.style.display='none'; Codehighlighter1_1051_1108_Closed_Image.style.display='inline'; Codehighlighter1_1051_1108_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1051_1108_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1051_1108_Closed_Text.style.display='none'; Codehighlighter1_1051_1108_Open_Image.style.display='inline'; Codehighlighter1_1051_1108_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_1051_1108_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_1051_1108_Open_Text">
						<span style="COLOR: #008000">/*</span>
						<span style="COLOR: #008000">**********<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />test data:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    3 3 3<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    1 1<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    1 0<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    2 2<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />**********</span>
						<span style="COLOR: #008000">*/</span>
				</span>
		</div>
		<p>
				<br /> </p>
<img src ="http://www.cppblog.com/qywyh/aggbug/13197.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-10-01 02:15 <a href="http://www.cppblog.com/qywyh/articles/13197.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>最短路Bellman-Ford实现</title><link>http://www.cppblog.com/qywyh/articles/12845.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Fri, 22 Sep 2006 14:04:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/12845.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/12845.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/12845.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/12845.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/12845.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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">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">100</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.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"> MAXV </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> MAXN </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> MAXN;<br /><img src="http://www.cppblog.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"> INF </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">2000000000</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000"> EDGE<br /><img id="Codehighlighter1_135_148_Open_Image" onclick="this.style.display='none'; Codehighlighter1_135_148_Open_Text.style.display='none'; Codehighlighter1_135_148_Closed_Image.style.display='inline'; Codehighlighter1_135_148_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_135_148_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_135_148_Closed_Text.style.display='none'; Codehighlighter1_135_148_Open_Image.style.display='inline'; Codehighlighter1_135_148_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_135_148_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_135_148_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> u, v;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> g[MAXN][MAXN];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />EDGE e[MAXV];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> BellmanFord(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> beg, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> end, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> nNum, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> eNum)<br /><img id="Codehighlighter1_240_600_Open_Image" onclick="this.style.display='none'; Codehighlighter1_240_600_Open_Text.style.display='none'; Codehighlighter1_240_600_Closed_Image.style.display='inline'; Codehighlighter1_240_600_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_240_600_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_240_600_Closed_Text.style.display='none'; Codehighlighter1_240_600_Open_Image.style.display='inline'; Codehighlighter1_240_600_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_240_600_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_240_600_Open_Text">
						<span style="COLOR: #000000">{</span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">nNum为顶点数, eNum为边数, 复杂度O(VE)</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> d[MAXN];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i, k;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.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">nNum; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        d[i] </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> INF;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    d[beg] </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">bool</span>
						<span style="COLOR: #000000"> ex </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">true</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (k</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">; k</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">nNum </span>
						<span style="COLOR: #000000">&amp;&amp;</span>
						<span style="COLOR: #000000"> ex; k</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_398_581_Open_Image" onclick="this.style.display='none'; Codehighlighter1_398_581_Open_Text.style.display='none'; Codehighlighter1_398_581_Closed_Image.style.display='inline'; Codehighlighter1_398_581_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_398_581_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_398_581_Closed_Text.style.display='none'; Codehighlighter1_398_581_Open_Image.style.display='inline'; Codehighlighter1_398_581_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_398_581_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_398_581_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        ex </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">false</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.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">eNum; i</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (d[e[i].u] </span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000"> INF </span>
								<span style="COLOR: #000000">&amp;&amp;</span>
								<span style="COLOR: #000000"> d[e[i].v] </span>
								<span style="COLOR: #000000">&gt;</span>
								<span style="COLOR: #000000"> d[e[i].u] </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> g[e[i].u][e[i].v])<br /><img id="Codehighlighter1_511_578_Open_Image" onclick="this.style.display='none'; Codehighlighter1_511_578_Open_Text.style.display='none'; Codehighlighter1_511_578_Closed_Image.style.display='inline'; Codehighlighter1_511_578_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_511_578_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_511_578_Closed_Text.style.display='none'; Codehighlighter1_511_578_Open_Image.style.display='inline'; Codehighlighter1_511_578_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
								<span id="Codehighlighter1_511_578_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_511_578_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                d[e[i].v] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> d[e[i].u] </span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000"> g[e[i].u][e[i].v];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                ex </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">true</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> d[end];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()<br /><img id="Codehighlighter1_614_912_Open_Image" onclick="this.style.display='none'; Codehighlighter1_614_912_Open_Text.style.display='none'; Codehighlighter1_614_912_Closed_Image.style.display='inline'; Codehighlighter1_614_912_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_614_912_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_614_912_Closed_Text.style.display='none'; Codehighlighter1_614_912_Open_Image.style.display='inline'; Codehighlighter1_614_912_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_614_912_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_614_912_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i, j;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> t </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> eNum </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> nNum </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">9</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.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">4</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (j</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">; j</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">4</span>
						<span style="COLOR: #000000">; j</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_714_850_Open_Image" onclick="this.style.display='none'; Codehighlighter1_714_850_Open_Text.style.display='none'; Codehighlighter1_714_850_Closed_Image.style.display='inline'; Codehighlighter1_714_850_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_714_850_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_714_850_Closed_Text.style.display='none'; Codehighlighter1_714_850_Open_Image.style.display='inline'; Codehighlighter1_714_850_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
						<span id="Codehighlighter1_714_850_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_714_850_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.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) <br /><img id="Codehighlighter1_735_759_Open_Image" onclick="this.style.display='none'; Codehighlighter1_735_759_Open_Text.style.display='none'; Codehighlighter1_735_759_Closed_Image.style.display='inline'; Codehighlighter1_735_759_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_735_759_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_735_759_Closed_Text.style.display='none'; Codehighlighter1_735_759_Open_Image.style.display='inline'; Codehighlighter1_735_759_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
								<span id="Codehighlighter1_735_759_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_735_759_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                g[i][j] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> INF;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000">
										<br />
										<img id="Codehighlighter1_772_846_Open_Image" onclick="this.style.display='none'; Codehighlighter1_772_846_Open_Text.style.display='none'; Codehighlighter1_772_846_Closed_Image.style.display='inline'; Codehighlighter1_772_846_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_772_846_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_772_846_Closed_Text.style.display='none'; Codehighlighter1_772_846_Open_Image.style.display='inline'; Codehighlighter1_772_846_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
								<span id="Codehighlighter1_772_846_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_772_846_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                g[i][j] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">t;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                e[eNum].u </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                e[eNum].v </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> j;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                eNum</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
						</span>
						<span style="COLOR: #000000">    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> BellmanFord(</span>
						<span style="COLOR: #000000">2</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">3</span>
						<span style="COLOR: #000000">, nNum, eNum) </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> endl;<br /><img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/12845.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-09-22 22:04 <a href="http://www.cppblog.com/qywyh/articles/12845.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RBTree类</title><link>http://www.cppblog.com/qywyh/articles/12490.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Thu, 14 Sep 2006 17:16:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/12490.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/12490.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/12490.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/12490.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/12490.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: #include 				&lt;				iostream				&gt;																								using				 				namespace				 std;				const				 				int				 MAXSIZE 				=				 				100				;				const...&nbsp;&nbsp;<a href='http://www.cppblog.com/qywyh/articles/12490.html'>阅读全文</a><img src ="http://www.cppblog.com/qywyh/aggbug/12490.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-09-15 01:16 <a href="http://www.cppblog.com/qywyh/articles/12490.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>压缩位的__int64高精度(发觉我写了好多高精度-_-)</title><link>http://www.cppblog.com/qywyh/articles/11988.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Sat, 02 Sep 2006 20:29:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/11988.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/11988.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/11988.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/11988.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/11988.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: #include 				&lt;				iostream				&gt;																#include 				&lt;				string				&gt;																								using				 				namespace				 std;typedef  				long	...&nbsp;&nbsp;<a href='http://www.cppblog.com/qywyh/articles/11988.html'>阅读全文</a><img src ="http://www.cppblog.com/qywyh/aggbug/11988.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-09-03 04:29 <a href="http://www.cppblog.com/qywyh/articles/11988.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>并查集</title><link>http://www.cppblog.com/qywyh/articles/11987.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Sat, 02 Sep 2006 20:26:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/11987.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/11987.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/11987.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/11987.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/11987.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">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">100</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> UFset<br /><img id="Codehighlighter1_77_155_Open_Image" onclick="this.style.display='none'; Codehighlighter1_77_155_Open_Text.style.display='none'; Codehighlighter1_77_155_Closed_Image.style.display='inline'; Codehighlighter1_77_155_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_77_155_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_77_155_Closed_Text.style.display='none'; Codehighlighter1_77_155_Open_Image.style.display='inline'; Codehighlighter1_77_155_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_77_155_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_77_155_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> parent[MAXN];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    UFset();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> Find(</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> Union(</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />UFset::UFset()<br /><img id="Codehighlighter1_174_213_Open_Image" onclick="this.style.display='none'; Codehighlighter1_174_213_Open_Text.style.display='none'; Codehighlighter1_174_213_Closed_Image.style.display='inline'; Codehighlighter1_174_213_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_174_213_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_174_213_Closed_Text.style.display='none'; Codehighlighter1_174_213_Open_Image.style.display='inline'; Codehighlighter1_174_213_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_174_213_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_174_213_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    memset(parent, </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">(parent));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> UFset::Find(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> x)<br /><img id="Codehighlighter1_239_346_Open_Image" onclick="this.style.display='none'; Codehighlighter1_239_346_Open_Text.style.display='none'; Codehighlighter1_239_346_Closed_Image.style.display='inline'; Codehighlighter1_239_346_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_239_346_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_239_346_Closed_Text.style.display='none'; Codehighlighter1_239_346_Open_Image.style.display='inline'; Codehighlighter1_239_346_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_239_346_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_239_346_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (parent[x] </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> x;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_280_337_Open_Image" onclick="this.style.display='none'; Codehighlighter1_280_337_Open_Text.style.display='none'; Codehighlighter1_280_337_Closed_Image.style.display='inline'; Codehighlighter1_280_337_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_280_337_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_280_337_Closed_Text.style.display='none'; Codehighlighter1_280_337_Open_Image.style.display='inline'; Codehighlighter1_280_337_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_280_337_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_280_337_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        parent[x] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> Find(parent[x]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> parent[x];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> 压缩路径</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />
						</span>
						<span style="COLOR: #000000">}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> UFset::Union(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> x, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> y)<br /><img id="Codehighlighter1_381_629_Open_Image" onclick="this.style.display='none'; Codehighlighter1_381_629_Open_Text.style.display='none'; Codehighlighter1_381_629_Closed_Image.style.display='inline'; Codehighlighter1_381_629_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_381_629_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_381_629_Closed_Text.style.display='none'; Codehighlighter1_381_629_Open_Image.style.display='inline'; Codehighlighter1_381_629_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_381_629_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_381_629_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> pX </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> Find(x);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> pY </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> Find(y);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> tmp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (pX </span>
						<span style="COLOR: #000000">!=</span>
						<span style="COLOR: #000000"> pY)<br /><img id="Codehighlighter1_447_627_Open_Image" onclick="this.style.display='none'; Codehighlighter1_447_627_Open_Text.style.display='none'; Codehighlighter1_447_627_Closed_Image.style.display='inline'; Codehighlighter1_447_627_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_447_627_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_447_627_Closed_Text.style.display='none'; Codehighlighter1_447_627_Open_Image.style.display='inline'; Codehighlighter1_447_627_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_447_627_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_447_627_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        tmp </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> parent[pX] </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> parent[pY]; </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000"> 加权合并</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (parent[pX] </span>
								<span style="COLOR: #000000">&gt;</span>
								<span style="COLOR: #000000"> parent[pY])<br /><img id="Codehighlighter1_523_568_Open_Image" onclick="this.style.display='none'; Codehighlighter1_523_568_Open_Text.style.display='none'; Codehighlighter1_523_568_Closed_Image.style.display='inline'; Codehighlighter1_523_568_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_523_568_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_523_568_Closed_Text.style.display='none'; Codehighlighter1_523_568_Open_Image.style.display='inline'; Codehighlighter1_523_568_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_523_568_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_523_568_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            parent[pX] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> pY;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            parent[pY] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> tmp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000">
										<br />
										<img id="Codehighlighter1_579_624_Open_Image" onclick="this.style.display='none'; Codehighlighter1_579_624_Open_Text.style.display='none'; Codehighlighter1_579_624_Closed_Image.style.display='inline'; Codehighlighter1_579_624_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_579_624_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_579_624_Closed_Text.style.display='none'; Codehighlighter1_579_624_Open_Image.style.display='inline'; Codehighlighter1_579_624_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_579_624_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_579_624_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            parent[pY] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> pX;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            parent[pX] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> tmp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()<br /><img id="Codehighlighter1_643_656_Open_Image" onclick="this.style.display='none'; Codehighlighter1_643_656_Open_Text.style.display='none'; Codehighlighter1_643_656_Closed_Image.style.display='inline'; Codehighlighter1_643_656_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_643_656_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_643_656_Closed_Text.style.display='none'; Codehighlighter1_643_656_Open_Image.style.display='inline'; Codehighlighter1_643_656_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_643_656_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_643_656_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/11987.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-09-03 04:26 <a href="http://www.cppblog.com/qywyh/articles/11987.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>BST类（没有删除操作， 代码好长啊， 继续优化中-_-）</title><link>http://www.cppblog.com/qywyh/articles/11986.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Sat, 02 Sep 2006 20:24:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/11986.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/11986.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/11986.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/11986.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/11986.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000"> BSTreeNode<br /><img id="Codehighlighter1_79_124_Open_Image" onclick="this.style.display='none'; Codehighlighter1_79_124_Open_Text.style.display='none'; Codehighlighter1_79_124_Closed_Image.style.display='inline'; Codehighlighter1_79_124_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_79_124_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_79_124_Closed_Text.style.display='none'; Codehighlighter1_79_124_Open_Image.style.display='inline'; Codehighlighter1_79_124_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_79_124_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_79_124_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    T info;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    BSTreeNode </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">ls;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    BSTreeNode </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">rs;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> BSTree<br /><img id="Codehighlighter1_160_440_Open_Image" onclick="this.style.display='none'; Codehighlighter1_160_440_Open_Text.style.display='none'; Codehighlighter1_160_440_Closed_Image.style.display='inline'; Codehighlighter1_160_440_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_160_440_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_160_440_Closed_Text.style.display='none'; Codehighlighter1_160_440_Open_Image.style.display='inline'; Codehighlighter1_160_440_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_160_440_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_160_440_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    BSTree();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">bool</span>
						<span style="COLOR: #000000"> insert(T key);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">bool</span>
						<span style="COLOR: #000000"> find(T key);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> travel();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> size();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #0000ff">private</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">bool</span>
						<span style="COLOR: #000000"> insert_inner(BSTreeNode</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">T</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">*&amp;</span>
						<span style="COLOR: #000000">root, BSTreeNode</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">T</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">p);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">bool</span>
						<span style="COLOR: #000000"> find_inner(BSTreeNode</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">T</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">root, T key);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> travel_inner(BSTreeNode</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">T</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">root);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    BSTreeNode</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">T</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">root;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> _size;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />BSTree</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">T</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">::BSTree()<br /><img id="Codehighlighter1_483_511_Open_Image" onclick="this.style.display='none'; Codehighlighter1_483_511_Open_Text.style.display='none'; Codehighlighter1_483_511_Closed_Image.style.display='inline'; Codehighlighter1_483_511_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_483_511_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_483_511_Closed_Text.style.display='none'; Codehighlighter1_483_511_Open_Image.style.display='inline'; Codehighlighter1_483_511_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_483_511_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_483_511_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    root </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    _size </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">bool</span>
				<span style="COLOR: #000000"> BSTree</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">T</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">::insert(T key)<br /><img id="Codehighlighter1_563_715_Open_Image" onclick="this.style.display='none'; Codehighlighter1_563_715_Open_Text.style.display='none'; Codehighlighter1_563_715_Closed_Image.style.display='inline'; Codehighlighter1_563_715_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_563_715_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_563_715_Closed_Text.style.display='none'; Codehighlighter1_563_715_Open_Image.style.display='inline'; Codehighlighter1_563_715_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_563_715_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_563_715_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    BSTreeNode</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">T</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">p </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">new</span>
						<span style="COLOR: #000000"> BSTreeNode</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">T</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    p</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">info </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> key;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    p</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">ls </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    p</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">rs </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (insert_inner(root, p))<br /><img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </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.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">bool</span>
				<span style="COLOR: #000000"> BSTree</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">T</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">::insert_inner(BSTreeNode</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">T</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*&amp;</span>
				<span style="COLOR: #000000">root, BSTreeNode</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">T</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">p)<br /><img id="Codehighlighter1_806_1008_Open_Image" onclick="this.style.display='none'; Codehighlighter1_806_1008_Open_Text.style.display='none'; Codehighlighter1_806_1008_Closed_Image.style.display='inline'; Codehighlighter1_806_1008_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_806_1008_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_806_1008_Closed_Text.style.display='none'; Codehighlighter1_806_1008_Open_Image.style.display='inline'; Codehighlighter1_806_1008_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_806_1008_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_806_1008_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (root </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> NULL)<br /><img id="Codehighlighter1_828_869_Open_Image" onclick="this.style.display='none'; Codehighlighter1_828_869_Open_Text.style.display='none'; Codehighlighter1_828_869_Closed_Image.style.display='inline'; Codehighlighter1_828_869_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_828_869_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_828_869_Closed_Text.style.display='none'; Codehighlighter1_828_869_Open_Image.style.display='inline'; Codehighlighter1_828_869_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_828_869_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_828_869_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        root </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> p;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        _size</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">info </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> p</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">info)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </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.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (p</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">info </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">info)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        insert_inner(root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">ls, p);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        insert_inner(root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">rs, p);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">bool</span>
				<span style="COLOR: #000000"> BSTree</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">T</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">::find(T key)<br /><img id="Codehighlighter1_1058_1125_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1058_1125_Open_Text.style.display='none'; Codehighlighter1_1058_1125_Closed_Image.style.display='inline'; Codehighlighter1_1058_1125_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1058_1125_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1058_1125_Closed_Text.style.display='none'; Codehighlighter1_1058_1125_Open_Image.style.display='inline'; Codehighlighter1_1058_1125_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_1058_1125_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1058_1125_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (find_inner(root, key))<br /><img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </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.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">bool</span>
				<span style="COLOR: #000000"> BSTree</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">T</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">::find_inner(BSTreeNode</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">T</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">root, T key)<br /><img id="Codehighlighter1_1202_1367_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1202_1367_Open_Text.style.display='none'; Codehighlighter1_1202_1367_Closed_Image.style.display='inline'; Codehighlighter1_1202_1367_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1202_1367_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1202_1367_Closed_Text.style.display='none'; Codehighlighter1_1202_1367_Open_Image.style.display='inline'; Codehighlighter1_1202_1367_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_1202_1367_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1202_1367_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (root </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> NULL)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </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.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">info </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> key)<br /><img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (key </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">info)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        find_inner(root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">ls, key);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        find_inner(root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">rs, key);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> BSTree</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">T</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">::size()<br /><img id="Codehighlighter1_1411_1428_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1411_1428_Open_Text.style.display='none'; Codehighlighter1_1411_1428_Closed_Image.style.display='inline'; Codehighlighter1_1411_1428_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1411_1428_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1411_1428_Closed_Text.style.display='none'; Codehighlighter1_1411_1428_Open_Image.style.display='inline'; Codehighlighter1_1411_1428_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_1411_1428_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1411_1428_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> _size;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> BSTree</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">T</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">::travel()<br /><img id="Codehighlighter1_1475_1498_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1475_1498_Open_Text.style.display='none'; Codehighlighter1_1475_1498_Closed_Image.style.display='inline'; Codehighlighter1_1475_1498_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1475_1498_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1475_1498_Closed_Text.style.display='none'; Codehighlighter1_1475_1498_Open_Image.style.display='inline'; Codehighlighter1_1475_1498_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_1475_1498_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1475_1498_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    travel_inner(root);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> BSTree</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">T</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">::travel_inner(BSTreeNode</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">T</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">root)<br /><img id="Codehighlighter1_1570_1679_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1570_1679_Open_Text.style.display='none'; Codehighlighter1_1570_1679_Closed_Image.style.display='inline'; Codehighlighter1_1570_1679_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1570_1679_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1570_1679_Closed_Text.style.display='none'; Codehighlighter1_1570_1679_Open_Image.style.display='inline'; Codehighlighter1_1570_1679_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_1570_1679_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1570_1679_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (root </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> NULL) </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> ;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    travel_inner(root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">ls);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">info </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    travel_inner(root</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">rs);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()<br /><img id="Codehighlighter1_1694_1833_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1694_1833_Open_Text.style.display='none'; Codehighlighter1_1694_1833_Closed_Image.style.display='inline'; Codehighlighter1_1694_1833_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1694_1833_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1694_1833_Closed_Text.style.display='none'; Codehighlighter1_1694_1833_Open_Image.style.display='inline'; Codehighlighter1_1694_1833_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_1694_1833_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1694_1833_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    BSTree</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> bst;<br /><img id="Codehighlighter1_1725_1739_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1725_1739_Open_Text.style.display='none'; Codehighlighter1_1725_1739_Closed_Image.style.display='inline'; Codehighlighter1_1725_1739_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1725_1739_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1725_1739_Closed_Text.style.display='none'; Codehighlighter1_1725_1739_Open_Image.style.display='inline'; Codehighlighter1_1725_1739_Open_Text.style.display='inline';" src="http://www.cppblog.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 style="COLOR: #000000"> </span>
						<span id="Codehighlighter1_1725_1739_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1725_1739_Open_Text">
								<span style="COLOR: #000000">{</span>
								<span style="COLOR: #000000">3</span>
								<span style="COLOR: #000000">, </span>
								<span style="COLOR: #000000">2</span>
								<span style="COLOR: #000000">, </span>
								<span style="COLOR: #000000">5</span>
								<span style="COLOR: #000000">, </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">, </span>
								<span style="COLOR: #000000">4</span>
								<span style="COLOR: #000000">}</span>
						</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (</span>
						<span style="COLOR: #0000ff">int</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: #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: #0000ff">int</span>
						<span style="COLOR: #000000">); i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        bst.insert(a[i]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    bst.travel();<br /><img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/11986.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-09-03 04:24 <a href="http://www.cppblog.com/qywyh/articles/11986.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Floyd-Warshall多源最短路径</title><link>http://www.cppblog.com/qywyh/articles/11819.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Tue, 29 Aug 2006 07:24:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/11819.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/11819.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/11819.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/11819.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/11819.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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<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">101</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.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"> INF </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1000000</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> g[MAXN][MAXN];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> d[MAXN][MAXN];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> floyd(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_102_449_Open_Image" onclick="this.style.display='none'; Codehighlighter1_102_449_Open_Text.style.display='none'; Codehighlighter1_102_449_Closed_Image.style.display='inline'; Codehighlighter1_102_449_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_102_449_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_102_449_Closed_Text.style.display='none'; Codehighlighter1_102_449_Open_Image.style.display='inline'; Codehighlighter1_102_449_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_102_449_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_102_449_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">  i, j, k;<br /><img src="http://www.cppblog.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">1</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000">n; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (j</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">; j</span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000">n; j</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            d[i][j] </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> g[i][j];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (k</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">; k</span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000">n; k</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_236_433_Open_Image" onclick="this.style.display='none'; Codehighlighter1_236_433_Open_Text.style.display='none'; Codehighlighter1_236_433_Closed_Image.style.display='inline'; Codehighlighter1_236_433_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_236_433_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_236_433_Closed_Text.style.display='none'; Codehighlighter1_236_433_Open_Image.style.display='inline'; Codehighlighter1_236_433_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_236_433_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_236_433_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.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">1</span>
								<span style="COLOR: #000000">; i</span>
								<span style="COLOR: #000000">&lt;=</span>
								<span style="COLOR: #000000">n; i</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (j</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">; j</span>
								<span style="COLOR: #000000">&lt;=</span>
								<span style="COLOR: #000000">n; j</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_312_429_Open_Image" onclick="this.style.display='none'; Codehighlighter1_312_429_Open_Text.style.display='none'; Codehighlighter1_312_429_Closed_Image.style.display='inline'; Codehighlighter1_312_429_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_312_429_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_312_429_Closed_Text.style.display='none'; Codehighlighter1_312_429_Open_Image.style.display='inline'; Codehighlighter1_312_429_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
								<span id="Codehighlighter1_312_429_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_312_429_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (d[i][k] </span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #000000"> INF </span>
										<span style="COLOR: #000000">&amp;&amp;</span>
										<span style="COLOR: #000000"> d[k][j] </span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #000000"> INF<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span>
										<span style="COLOR: #000000">&amp;&amp;</span>
										<span style="COLOR: #000000"> d[i][k] </span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000"> d[k][j] </span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #000000"> d[i][j])<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    d[i][j] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> d[i][k] </span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000"> d[k][j];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/11819.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-08-29 15:24 <a href="http://www.cppblog.com/qywyh/articles/11819.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Kruskal最小生成树</title><link>http://www.cppblog.com/qywyh/articles/11473.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Sat, 19 Aug 2006 17:39:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/11473.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/11473.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/11473.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/11473.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/11473.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #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">100</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> UFset<br /><img id="Codehighlighter1_35_113_Open_Image" onclick="this.style.display='none'; Codehighlighter1_35_113_Open_Text.style.display='none'; Codehighlighter1_35_113_Closed_Image.style.display='inline'; Codehighlighter1_35_113_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_35_113_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_35_113_Closed_Text.style.display='none'; Codehighlighter1_35_113_Open_Image.style.display='inline'; Codehighlighter1_35_113_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_35_113_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_35_113_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> parent[MAXN];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    UFset();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> Find(</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> Union(</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />UFset::UFset()<br /><img id="Codehighlighter1_132_171_Open_Image" onclick="this.style.display='none'; Codehighlighter1_132_171_Open_Text.style.display='none'; Codehighlighter1_132_171_Closed_Image.style.display='inline'; Codehighlighter1_132_171_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_132_171_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_132_171_Closed_Text.style.display='none'; Codehighlighter1_132_171_Open_Image.style.display='inline'; Codehighlighter1_132_171_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_132_171_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_132_171_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    memset(parent, </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">(parent));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> UFset::Find(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> x)<br /><img id="Codehighlighter1_197_276_Open_Image" onclick="this.style.display='none'; Codehighlighter1_197_276_Open_Text.style.display='none'; Codehighlighter1_197_276_Closed_Image.style.display='inline'; Codehighlighter1_197_276_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_197_276_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_197_276_Closed_Text.style.display='none'; Codehighlighter1_197_276_Open_Image.style.display='inline'; Codehighlighter1_197_276_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_197_276_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_197_276_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (parent[x] </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> x;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        parent[x] </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> Find(parent[x]); </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> 压缩路径</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />
						</span>
						<span style="COLOR: #000000">}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> UFset::Union(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> x, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> y)<br /><img id="Codehighlighter1_311_559_Open_Image" onclick="this.style.display='none'; Codehighlighter1_311_559_Open_Text.style.display='none'; Codehighlighter1_311_559_Closed_Image.style.display='inline'; Codehighlighter1_311_559_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_311_559_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_311_559_Closed_Text.style.display='none'; Codehighlighter1_311_559_Open_Image.style.display='inline'; Codehighlighter1_311_559_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_311_559_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_311_559_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> pX </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> Find(x);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> pY </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> Find(y);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> tmp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (pX </span>
						<span style="COLOR: #000000">!=</span>
						<span style="COLOR: #000000"> pY)<br /><img id="Codehighlighter1_377_557_Open_Image" onclick="this.style.display='none'; Codehighlighter1_377_557_Open_Text.style.display='none'; Codehighlighter1_377_557_Closed_Image.style.display='inline'; Codehighlighter1_377_557_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_377_557_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_377_557_Closed_Text.style.display='none'; Codehighlighter1_377_557_Open_Image.style.display='inline'; Codehighlighter1_377_557_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_377_557_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_377_557_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        tmp </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> parent[pX] </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> parent[pY]; </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000"> 加权合并</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (parent[pX] </span>
								<span style="COLOR: #000000">&gt;</span>
								<span style="COLOR: #000000"> parent[pY])<br /><img id="Codehighlighter1_453_498_Open_Image" onclick="this.style.display='none'; Codehighlighter1_453_498_Open_Text.style.display='none'; Codehighlighter1_453_498_Closed_Image.style.display='inline'; Codehighlighter1_453_498_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_453_498_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_453_498_Closed_Text.style.display='none'; Codehighlighter1_453_498_Open_Image.style.display='inline'; Codehighlighter1_453_498_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_453_498_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_453_498_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            parent[pX] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> pY;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            parent[pY] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> tmp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000">
										<br />
										<img id="Codehighlighter1_509_554_Open_Image" onclick="this.style.display='none'; Codehighlighter1_509_554_Open_Text.style.display='none'; Codehighlighter1_509_554_Closed_Image.style.display='inline'; Codehighlighter1_509_554_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_509_554_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_509_554_Closed_Text.style.display='none'; Codehighlighter1_509_554_Open_Image.style.display='inline'; Codehighlighter1_509_554_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_509_554_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_509_554_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            parent[pY] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> pX;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            parent[pX] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> tmp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">int g[MAXN][MAXN];</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000"> EDGEDATA<br /><img id="Codehighlighter1_599_624_Open_Image" onclick="this.style.display='none'; Codehighlighter1_599_624_Open_Text.style.display='none'; Codehighlighter1_599_624_Closed_Image.style.display='inline'; Codehighlighter1_599_624_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_599_624_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_599_624_Closed_Text.style.display='none'; Codehighlighter1_599_624_Open_Image.style.display='inline'; Codehighlighter1_599_624_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_599_624_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_599_624_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> beg, end;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> q;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />EDGEDATA e[MAXN</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">MAXN];</span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">输入边信息</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">EDGEDATA v[MAXN];</span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">返回路径</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> inorder(EDGEDATA a, EDGEDATA b)<br /><img id="Codehighlighter1_719_740_Open_Image" onclick="this.style.display='none'; Codehighlighter1_719_740_Open_Text.style.display='none'; Codehighlighter1_719_740_Closed_Image.style.display='inline'; Codehighlighter1_719_740_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_719_740_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_719_740_Closed_Text.style.display='none'; Codehighlighter1_719_740_Open_Image.style.display='inline'; Codehighlighter1_719_740_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_719_740_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_719_740_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> a.q </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> b.q;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> kruskal(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> nn, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> n) </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> nn边数, n顶点数</span>
				<span style="COLOR: #008000">
						<br />
						<img id="Codehighlighter1_784_1096_Open_Image" onclick="this.style.display='none'; Codehighlighter1_784_1096_Open_Text.style.display='none'; Codehighlighter1_784_1096_Closed_Image.style.display='inline'; Codehighlighter1_784_1096_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_784_1096_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_784_1096_Closed_Text.style.display='none'; Codehighlighter1_784_1096_Open_Image.style.display='inline'; Codehighlighter1_784_1096_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span id="Codehighlighter1_784_1096_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_784_1096_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> k;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    UFset UFS;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> rnt </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> e 已按权排序</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    </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">, k</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">nn; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_868_1081_Open_Image" onclick="this.style.display='none'; Codehighlighter1_868_1081_Open_Text.style.display='none'; Codehighlighter1_868_1081_Closed_Image.style.display='inline'; Codehighlighter1_868_1081_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_868_1081_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_868_1081_Closed_Text.style.display='none'; Codehighlighter1_868_1081_Open_Image.style.display='inline'; Codehighlighter1_868_1081_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_868_1081_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_868_1081_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (UFS.Find(e[i].beg) </span>
								<span style="COLOR: #000000">!=</span>
								<span style="COLOR: #000000"> UFS.Find(e[i].end))<br /><img id="Codehighlighter1_920_1055_Open_Image" onclick="this.style.display='none'; Codehighlighter1_920_1055_Open_Text.style.display='none'; Codehighlighter1_920_1055_Closed_Image.style.display='inline'; Codehighlighter1_920_1055_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_920_1055_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_920_1055_Closed_Text.style.display='none'; Codehighlighter1_920_1055_Open_Image.style.display='inline'; Codehighlighter1_920_1055_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_920_1055_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_920_1055_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            v[k].beg </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> e[i].beg;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            v[k].end </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> e[i].end;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            v[k].q </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> e[i].q;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            rnt </span>
										<span style="COLOR: #000000">+=</span>
										<span style="COLOR: #000000"> e[i].q;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            k</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            UFS.Union(e[i].beg, e[i].end);            <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (k </span>
								<span style="COLOR: #000000">==</span>
								<span style="COLOR: #000000"> n</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">) </span>
								<span style="COLOR: #0000ff">break</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> rnt;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/11473.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-08-20 01:39 <a href="http://www.cppblog.com/qywyh/articles/11473.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>等价类与并查集的原理和应用 (转)</title><link>http://www.cppblog.com/qywyh/articles/11302.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Wed, 16 Aug 2006 12:26:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/11302.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/11302.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/11302.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/11302.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/11302.html</trackback:ping><description><![CDATA[
		<div align="center"> </div>
		<div style="WIDTH: 520px; WORD-BREAK: break-all; WORD-WRAP: break-word">
				<div id="td_content">
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
										<font size="3">等价类与并查集的原理和应用</font>
								</span>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">
										<span lang="EN-US">
												<span style="mso-tab-count: 1">       </span>
										</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">并查集主要解决判断两个元素是否同属一个集合，和把两个不属同一集合的两个元素进行合并的问题。</span>
										<span lang="EN-US">(</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">想想最小生成树中的</span>
										<span lang="EN-US">kruskal</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">算法</span>
										<span lang="EN-US">:</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">关键是判别两个节点是否属同一连通分量，这里并查集可以以很好的时间复杂度解决它，几乎是线性时间！！</span>
										<span lang="EN-US">)</span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">
										<span lang="EN-US">
												<span style="mso-tab-count: 1">       </span>
										</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">首先要知道关于等价类（就相当于前面说的同属一个集合）的基本性质。</span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">
										<span lang="EN-US">
												<span style="mso-tab-count: 1">       </span>
										</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">等价类三大性质：（用Ｘ</span>
										<b>
												<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol">
														<span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span>
												</span>
										</b>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Ｙ表Ｘ与Ｙ等价）</span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">
										<span lang="EN-US">
												<span style="mso-tab-count: 1">       </span>
										</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">自反性：如Ｘ</span>
										<b>
												<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol">
														<span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span>
												</span>
										</b>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Ｘ则Ｘ</span>
										<b>
												<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol">
														<span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span>
												</span>
										</b>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Ｘ；</span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">
										<span lang="EN-US">
												<span style="mso-tab-count: 1">       </span>
										</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对称性：如Ｘ</span>
										<b>
												<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol">
														<span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span>
												</span>
										</b>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Ｙ则Ｙ</span>
										<b>
												<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol">
														<span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span>
												</span>
										</b>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Ｘ；</span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">
										<span lang="EN-US">
												<span style="mso-tab-count: 1">       </span>
										</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">传递性：如Ｘ</span>
										<b>
												<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol">
														<span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span>
												</span>
										</b>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Ｙ且Ｙ</span>
										<b>
												<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol">
														<span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span>
												</span>
										</b>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Ｚ则Ｘ</span>
										<b>
												<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol">
														<span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span>
												</span>
										</b>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Ｚ；</span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
										<font size="3">等价类应用：</font>
								</span>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">
										<span lang="EN-US">
												<span style="mso-tab-count: 1">       </span>
										</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设初始有一集合</span>
										<b>
												<i>
														<span lang="EN-US">s={0,1,2,3,4,5,6,7,8,9,10,11}</span>
												</i>
										</b>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">
										<b>
												<i>
														<span lang="EN-US">       </span>
												</i>
										</b>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">依次读若干事先定义的等价对</span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
								</span>
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
										<font size="3">
												<strong>
														<span>   0<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol"><span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span></span></span>
														<span>4,3<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol"><span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span></span></span>
														<span>1,6<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol"><span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span></span></span>
														<span>10,8<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol"><span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span></span></span>
														<span lang="EN-US">9,</span>
												</strong>
												<b>
														<span lang="EN-US">7<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol"><span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span></span></span>
												</b>
												<b>
														<span lang="EN-US">4,</span>
												</b>
												<span lang="EN-US">6<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol"><span style="mso-char-type: symbol; mso-symbol-font-family: Symbol"><strong>º</strong></span></span></span>
												<span lang="EN-US">8,3<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol"><span style="mso-char-type: symbol; mso-symbol-font-family: Symbol"><strong>º</strong></span></span></span>
												<span lang="EN-US">5,2<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol"><span style="mso-char-type: symbol; mso-symbol-font-family: Symbol"><strong>º</strong></span></span></span>
												<span lang="EN-US">11,11<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol"><span style="mso-char-type: symbol; mso-symbol-font-family: Symbol"><strong>º</strong></span></span></span>
												<span lang="EN-US">0.</span>
										</font>
								</span>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
										<font size="3">
												<span lang="EN-US">    </span>我们想把每次读入一个等价对后，把等价集合合并起来。</font>
								</span>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">    </font>
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
										<font size="3">则每读入一个等价对后的集合状态是：（用｛｝表示一个等价集合）</font>
								</span>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
								<font size="3">
										<b>
												<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">初始</span>
												<span lang="EN-US">
														<span style="mso-tab-count: 1">      </span>
												</span>
										</b>
										<span lang="EN-US">{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}<b><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?><o:p></o:p></b></span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
								<font size="3">
										<b>
												<span lang="EN-US">0<i></i></span>
										</b>
										<b>
												<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol">
														<span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span>
												</span>
												<span lang="EN-US"> 4 </span>
										</b>
										<span lang="EN-US">
												<span style="mso-tab-count: 1">     </span>
												<b>{</b>0,4<b>}</b>,<b>{</b>1<b>}</b>,<b>{</b>2<b>}</b>,<b>{</b>3<b>}</b>,<b>{</b>5<b>}</b>,<b>{</b>6<b>}</b>,<b>{</b>7<b>}</b>,<b>{</b>8<b>}</b>,<b>{</b>9<b>}</b>,<b>{</b>10<b>}</b>,<b>{</b>11<b>}</b></span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
								<font size="3">
										<b>
												<span lang="EN-US">3<i></i></span>
										</b>
										<b>
												<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol">
														<span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span>
												</span>
												<span lang="EN-US"> 1</span>
										</b>
										<span lang="EN-US">
												<span style="mso-tab-count: 1">     </span>
												<b>{</b>0,4<b>}</b>, <b>{</b>1,3<b>}</b>,<b>{</b>2<b>}</b>,<b>{</b>5<b>}</b>,<b>{</b>6<b>}</b>,<b>{</b>7<b>}</b>,<b>{</b>8<b>}</b>,<b>{</b>9<b>}</b>,<b>{</b>10<b>}</b>,<b>{</b>11<b>}</b></span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
								<font size="3">
										<b>
												<span lang="EN-US">6<i></i></span>
										</b>
										<b>
												<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol">
														<span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span>
												</span>
												<span lang="EN-US"> 10<span style="mso-tab-count: 1">    </span>{</span>
										</b>
										<span lang="EN-US">0,4<b>}</b>,<b>{</b>1,3<b>}</b>,<b>{</b>2<b>}</b>,<b>{</b>5<b>}</b>,<b>{</b>6,10<b>}</b>,<b>{</b>7<b>}</b>,<b>{</b>8<b>}</b>,<b>{</b>9<b>}</b>,<b>{</b>11<b>}</b></span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
								<font size="3">
										<b>
												<span lang="EN-US">8<i></i></span>
										</b>
										<b>
												<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol">
														<span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span>
												</span>
												<span lang="EN-US"> 9</span>
										</b>
										<span lang="EN-US">
												<span style="mso-tab-count: 1">     </span>
												<b>{</b>0,4<b>}</b>,<b>{</b>1,3<b>}</b>,<b>{</b>2<b>}</b>,<b>{</b>5<b>}</b>,<b>{</b>6,10<b>}</b>,<b>{</b>7<b>}</b>,<b>{</b>8,9<b>}</b>,<b>{</b>11<b>}</b></span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
								<font size="3">
										<b>
												<span lang="EN-US">7<i></i></span>
										</b>
										<b>
												<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol">
														<span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span>
												</span>
												<span lang="EN-US"> 4</span>
										</b>
										<span lang="EN-US">
												<span style="mso-tab-count: 1">     </span>
												<b>{</b>0,4,7<b>}</b>,<b>{</b>1,3<b>}</b>,<b>{</b>2<b>}</b>,<b>{</b>5<b>}</b>,<b>{</b>6,10<b>}</b>,<b>{</b>8,9<b>}</b>,<b>{</b>11<b>}<o:p></o:p></b></span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
								<font size="3">
										<b>
												<span lang="EN-US">6<i></i></span>
										</b>
										<b>
												<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol">
														<span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span>
												</span>
												<span lang="EN-US"> 8</span>
										</b>
										<span lang="EN-US">
												<span style="mso-tab-count: 1">     </span>
												<b>{</b>0,4,7<b>}</b>,<b>{</b>1,3<b>}</b>,<b>{</b>2<b>}</b>,<b>{</b>5<b>}</b>,<b>{</b>6,8,9,10<b>}</b>,<b>{</b>11<b>}</b></span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
								<font size="3">
										<b>
												<span lang="EN-US">3<i></i></span>
										</b>
										<b>
												<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol">
														<span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span>
												</span>
												<span lang="EN-US"> 5</span>
										</b>
										<span lang="EN-US">
												<span style="mso-tab-count: 1">     </span>
												<b>{</b>0,4,7<b>}</b>,<b>{</b>1,3,5<b>}</b>,<b>{</b>2<b>}</b>,<b>{</b>6,8,9,10<b>}</b>,<b>{</b>11<b>}</b></span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
								<font size="3">
										<b>
												<span lang="EN-US">2<i></i></span>
										</b>
										<b>
												<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol">
														<span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span>
												</span>
												<span lang="EN-US"> 11<span style="mso-tab-count: 1">    </span>{</span>
										</b>
										<span lang="EN-US">0,4,7<b>}</b>,<b>{</b>1,3,5<b>}</b>,<b>{</b>2,11<b>}</b>,<b>{</b>6,8,9,10<b>}</b></span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
								<font size="3">
										<b>
												<span lang="EN-US">11<i></i></span>
										</b>
										<b>
												<span lang="EN-US" style="FONT-FAMILY: Symbol; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Symbol">
														<span style="mso-char-type: symbol; mso-symbol-font-family: Symbol">º</span>
												</span>
												<span lang="EN-US"> 0<span style="mso-tab-count: 1">    </span>{</span>
										</b>
										<span lang="EN-US">0,2,4,7,11<b>}</b>,<b>{</b>1,3,5<b>}</b>,<b>{</b>6,8,9,10<b>}<o:p></o:p></b></span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">
										<span lang="EN-US">
												<span style="mso-tab-count: 1">       </span>
										</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">怎样来实现这样的结构呢？</span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">
										<span lang="EN-US">
												<span style="mso-tab-count: 1">       </span>
										</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们可建一个含Ｓ元素个数大小的指针数组</span>
										<span lang="EN-US">node *seq[N]</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。其中每个元素是一个指向其下一个等价元素对应序号节点的头指针。每读入一个等价对后，修改链表。上例读完后的表状态是：</span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
												<font size="3">
														<img src="http://blog.programfan.com/upfile/200607/200607272007049.jpg" />
												</font>
										</span>
								</span>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
												<font size="3">建表算法如下：<br />void creatlist()<br />{ int x,y,c;<br /> node *P;<br /> scanf("%d",&amp;c); //读入等价对数<br /> for(int i=0;i&lt;c;i++)<br /> {<br />  scanf("%d %d",&amp;x,&amp;y);<br />  P=new node; <br />  P-&gt;data=y;<br />  P-&gt;next=seq[x];<br />  seq[x]=P;<br />  P=new node; //为什么要两个节点呢？因为你建了个Ａ的下一等价对Ｂ那么由对称性，应该再建一个节点表示Ｂ的下一等价对是Ａ。<br />  P-&gt;data=x;<br />  P-&gt;next=seq[y];<br />  seq[y]=P;<br /> }//for<br />}</font>
										</span>
								</span>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
												<font size="3">
												</font> </span>
								</span>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
										<font size="3">    现在我们想把同属一个等价集合的元素分别输出出来。有什么办法呢？</font>
								</span>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">
										<span lang="EN-US">
												<span style="mso-tab-count: 1">
														<font face="Times New Roman">       </font>
												</span>
										</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">先看图。Ｓｅｑ［０］它有两个等价类１１，４。这样直接输出０，１１，４。是否可行呢？答案是不行的，你看下４结点还有两个等价类７，０。当然已知０，４是等价的了，</span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">但７你是忽略的了（因为传递性：０，４等价且４，７等价就必然有０，７等价。所以７也应该被输出）。还有</span>
										<span lang="EN-US">
												<font face="Times New Roman">11</font>
										</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">节点下的２你也没算……</span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">
										<span lang="EN-US">
												<span style="mso-tab-count: 1">
														<font face="Times New Roman">       </font>
												</span>
										</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们可以采用类似ＤＦＳ（深度优先搜索）的策略对每个集合的元素进行遍历。例如：</span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
										<font size="3">开始从０节点搜起，把它下面的两个直接等价类入栈，然后依次出栈，每次出栈后对出栈元素的直接等价类再进行一次类似的ＤＦＳ，直到包含０节点的等价集合被全部输出。程序如下：</font>
								</span>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">void display()<br />{  <br /> stack&lt;int&gt; S;<br /> int t;node *p;<br /> for(int i=0;i&lt;N;i++)<br /> {<br />  if(!outed[i])  //是否输出过的标记<br />  { <br />    cout&lt;&lt;"new class"&lt;&lt;'{';<br />    S.push(i);<br />    cout&lt;&lt;i&lt;&lt;' ';<br />    outed[i]=1;<br />    while(!S.empty())<br />    {<br />    t=S.top();<br />    S.pop();<br />    p=seq[t];<br />    while(p!=NULL)<br />    {<br />     if(!outed[p-&gt;data])<br />     {<br />      cout&lt;&lt;p-&gt;data&lt;&lt;' ';<br />      S.push(p-&gt;data);<br />      outed[p-&gt;data]=1;<br />     }<br />     p=p-&gt;next;<br />    }//while<br />   }//while<br />    cout&lt;&lt;'}'&lt;&lt;endl;<br />  }//if<br /> }//for<br />}<br /></font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
										<font size="3">其实有比这个方便快速的数据结构来实现这个问题，那就是并查集。</font>
								</span>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
										<font size="3">并查集对这个问题的处理思想是开始把每一个对象看作是一个单元素集合，然后依次按顺序（就是读入等价对）将属于同一等价类的元素所在的集合合并。在此过程中将重复地使用一个搜索运算，确定一个元素在哪一个集合中。当读入一个等价对ＡＢ时，先检测这两个等价对是否同属一个集合，如是，则不用合并。不是，则用个合并算法把这两个包含ＡＢ的集合合并，使两个集合的任两个元素都是等价的（由传递性）。</font>
								</span>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">
										<span lang="EN-US">
												<span style="mso-tab-count: 1">
														<font face="Times New Roman">       </font>
												</span>
										</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为了方便，我们通常用一个集合的根结点序号来表示这个集合。</span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
										<font size="3">来看下具体结构实现：</font>
								</span>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">定义个Ｐａｒｅｎｔ［Ｎ］的数组，作为结构。Ｐａｒｅｎｔ中存的就是序号结点的父亲结点的序号，例：如果Ｐａｒｅｎｔ［３］＝４就是说３号结点的双亲是４号结点。如果一个结点的父结点是负数的话，我们就认为它是一个集合的根结点，因为数组中没有序号是负的。并且用负的绝对值作为这个集合中所含节点个数，如：</span>
										<span lang="EN-US">
												<font face="Times New Roman">parent[6]=-4;</font>
										</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">说明６号节点是个集合根结点，这个集合有４个元素。初始时，所有Ｐａｒｅｎｔ赋为</span>
										<span lang="EN-US">
												<font face="Times New Roman">-1</font>
										</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，说明每个结点都是根结点（Ｎ个独立节点集合），只包含一个元素（就是自己了）。</span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">
										<span lang="EN-US">
												<span style="mso-tab-count: 1">
														<font face="Times New Roman">       </font>
												</span>
										</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">实现这个数据结构主要有三个函数：如下：</span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">void UFset()  //初始化<br />{<br /> for(int i=0;i&lt;N;i++)<br />  parent[i]=-1;<br />}</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">
								</font> </p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">int Find(int x)  //返回第Ｘ节点所属集合的根结点<br />{<br /> for(int i=x;parent[i]&gt;=0;i=parent[i]);<br /> while(i!=x)   //优化方案――压缩路径<br /> {<br />  int tmp=parent[x];<br />  parent[x]=i;<br />     x=tmp;<br /> }<br /> return i;<br />}</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">
								</font> </p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
								<font size="3">void Union(int R1,int R2)  //将两个不同集合的元素进行合并，使两个集合中任两个元素都连通<br />{<br /> int tmp=parent[R1]+parent[R2];<br /> if(parent[R1]&gt;parent[R2]) //优化方案――加权法则<br /> {<br />  parent[R1]=R2;<br />  parent[R2]=tmp;<br /> }<br /> else<br /> {<br />  parent[R2]=R1;<br />  parent[R1]=tmp;<br /> }<br />}</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
								<font size="3">
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在Ｆｉｎｄ函数中如果仅仅靠一个循环来直接得到节点的所属集合根结点的话。通过多次的Ｕｎｉｏｎ操作就会有很多节点在树的比较深层次中，再Ｆｉｎｄ起来就会很费时。通过加一个Ｗｈｉｌｅ循环（压缩路径）每次都把从</span>
										<span lang="EN-US">
												<font face="Times New Roman">i</font>
										</span>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">到集合根结点的路过结点的双亲直接设为集合的根结点。虽然这增加了时间，但以后的Ｆｉｎｄ会快。平均效能而言，这是个高效方法。</span>
								</font>
						</p>
						<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
												<font size="3">
														<img src="http://blog.programfan.com/upfile/200607/2006072720103.jpg" />
												</font>
										</span>
								</span>
						</p>
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
												<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
														<font size="3">两个集合并时，任一方可做为另一方的孩子。怎样来处理呢，现在一般采用加权合并，把两个集合中元素个数少的做为个数多的孩子。有什么优势呢？直观上看，可以减少集合树的深层元素的个数，减少Ｆｉｎｄ时间。</font>
												</span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
												<font size="3">
														<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如从０开始到Ｎ不断合并</span>
														<span lang="EN-US">
																<font face="Times New Roman">i</font>
														</span>
														<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</span>
														<span lang="EN-US">
																<font face="Times New Roman">i+1</font>
														</span>
														<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">结点会怎样呢？</span>
												</font>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
												<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
														<font size="3">
																<img src="http://blog.programfan.com/upfile/200607/20060727201053.jpg" />
														</font>
												</span>
										</p>
										<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
												<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
														<font size="3">
																<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这样Ｆｉｎｄ任一节点所属集合的时间复杂度几乎都是Ｏ</span>
																<span lang="EN-US">
																		<font face="Times New Roman">(1)</font>
																</span>
																<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">！！</span>
														</font>
												</p>
												<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
														<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
																<font size="3">不用加权规则就会得到</font>
														</span>
												</p>
												<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
														<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
																<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
																		<font size="3">
																				<img src="http://blog.programfan.com/upfile/200607/20060727201248.jpg" />
																		</font>
																</span>
														</span>
												</p>
												<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
														<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
																<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
																		<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
																				<font size="3">这就是典型的退化树现象，再Ｆｉｎｄ起来就会很费时（如找Ｎ－１节点看看）。</font>
																		</span>
																</p>
																<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
																		<font size="3">
																				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">以下是读入等价对后的</span>
																				<span lang="EN-US">
																						<font face="Times New Roman">parent[N]</font>
																				</span>
																				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">查找合并过程状态：</span>
																		</font>
																</p>
																<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
																		<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
																				<font size="3">
																						<img src="http://blog.programfan.com/upfile/200607/20060727201337.jpg" />
																				</font>
																		</span>
																</p>
														</span>
												</span>
												<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
														<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
																<font size="3">
																		<img src="http://blog.programfan.com/upfile/200607/2006072720142.jpg" />
																</font>
														</span>
												</p>
												<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
														<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt">
																<font size="3">
																		<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">再说一个并查集应用最完美的地方：最小生成树的</span>
																		<span lang="EN-US">
																				<font face="Times New Roman">kruskal</font>
																		</span>
																		<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">算法：</span>
																</font>
														</p>
														<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
																<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
																		<font size="3">算法基本思想是：</font>
																</span>
														</p>
														<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">
																<font size="3">
																		<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">开始把所有节点作为各自的一个单独集合，以为每次从边信息中得到一个最短的边，如果这个边邻接了两个不同集合的节点，就把这两个节点的所属集合结合起来，否则继续搜索。直至所有节点都同属一个集合，就生成了一个最小生成树。</span>int kruskal(int parent[],int N)<br />{<br /> int i,j,k,x,y;<br /> int min;<br /> while(k&lt;=N-1) //产生Ｎ－１条边<br /> {<br />  min=MAX_INT;<br />  for(i=1;i&lt;=N;i++) <br />   for(j=1;j&lt;=N;j++)<br />   {<br />    if(sign[i][j]==0&amp;&amp;i!=j) //sign[N][N]是标志节点是否被访问过或已被排除……<br />    {<br />     if(arcs[i][j]&lt;min)　//arcs[N][N]存放边的长度<br />     {<br />      min=arcs[i][j];<br />      x=i;<br />      y=j;<br />     }//if<br />    }//if<br />   }//for<br />  if(Find(parent,x)==Find(parent,y)) //如Ｘ，Ｙ已经属同一连通分量，则不合并，排除……<br />   sign[x][y]=1;<br />  else<br />   {<br />    Union(parent,x,y);<br />    Sign[x][y]=1;<br />   }<br /> k++;<br /> }//while<br />}</font>
														</p>
												</span>
										</span>
								</span>
						</span>
				</div>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/11302.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-08-16 20:26 <a href="http://www.cppblog.com/qywyh/articles/11302.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>GCD和组合数</title><link>http://www.cppblog.com/qywyh/articles/11300.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Wed, 16 Aug 2006 11:05:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/11300.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/11300.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/11300.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/11300.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/11300.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">  #include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />__int64 gcd(__int64 a, __int64 b)<br /><img id="Codehighlighter1_78_134_Open_Image" onclick="this.style.display='none'; Codehighlighter1_78_134_Open_Text.style.display='none'; Codehighlighter1_78_134_Closed_Image.style.display='inline'; Codehighlighter1_78_134_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_78_134_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_78_134_Closed_Text.style.display='none'; Codehighlighter1_78_134_Open_Image.style.display='inline'; Codehighlighter1_78_134_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_78_134_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_78_134_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (b </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">) <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> a;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> gcd(b, a</span>
						<span style="COLOR: #000000">%</span>
						<span style="COLOR: #000000">b);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />__int64 C(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> b)<br /><img id="Codehighlighter1_161_310_Open_Image" onclick="this.style.display='none'; Codehighlighter1_161_310_Open_Text.style.display='none'; Codehighlighter1_161_310_Closed_Image.style.display='inline'; Codehighlighter1_161_310_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_161_310_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_161_310_Closed_Text.style.display='none'; Codehighlighter1_161_310_Open_Image.style.display='inline'; Codehighlighter1_161_310_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_161_310_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_161_310_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    __int64 x</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">, y</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    __int64 r;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i;<br /><img src="http://www.cppblog.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">b; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_224_293_Open_Image" onclick="this.style.display='none'; Codehighlighter1_224_293_Open_Text.style.display='none'; Codehighlighter1_224_293_Closed_Image.style.display='inline'; Codehighlighter1_224_293_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_224_293_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_224_293_Closed_Text.style.display='none'; Codehighlighter1_224_293_Open_Image.style.display='inline'; Codehighlighter1_224_293_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_224_293_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_224_293_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        x </span>
								<span style="COLOR: #000000">*=</span>
								<span style="COLOR: #000000"> (a</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">i); <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        y </span>
								<span style="COLOR: #000000">*=</span>
								<span style="COLOR: #000000"> (b</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">i);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        r </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> gcd(x, y);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        x </span>
								<span style="COLOR: #000000">/=</span>
								<span style="COLOR: #000000"> r;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        y </span>
								<span style="COLOR: #000000">/=</span>
								<span style="COLOR: #000000"> r;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> x </span>
						<span style="COLOR: #000000">/</span>
						<span style="COLOR: #000000"> y;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()<br /><img id="Codehighlighter1_324_427_Open_Image" onclick="this.style.display='none'; Codehighlighter1_324_427_Open_Text.style.display='none'; Codehighlighter1_324_427_Closed_Image.style.display='inline'; Codehighlighter1_324_427_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_324_427_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_324_427_Closed_Text.style.display='none'; Codehighlighter1_324_427_Open_Image.style.display='inline'; Codehighlighter1_324_427_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_324_427_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_324_427_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    printf(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">gcd(100, 15) = %I64d\n</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">, gcd(</span>
						<span style="COLOR: #000000">100</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">15</span>
						<span style="COLOR: #000000">));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    printf(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">C(4, 2) = %I64d\n</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">, C(</span>
						<span style="COLOR: #000000">4</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">2</span>
						<span style="COLOR: #000000">));<br /><img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/11300.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-08-16 19:05 <a href="http://www.cppblog.com/qywyh/articles/11300.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>单源最短路径Dijkstra</title><link>http://www.cppblog.com/qywyh/articles/11045.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Wed, 09 Aug 2006 06:56:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/11045.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/11045.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/11045.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/11045.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/11045.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 id="Codehighlighter1_0_78_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_78_Open_Text.style.display='none'; Codehighlighter1_0_78_Closed_Image.style.display='inline'; Codehighlighter1_0_78_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
				<img id="Codehighlighter1_0_78_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_0_78_Closed_Text.style.display='none'; Codehighlighter1_0_78_Open_Image.style.display='inline'; Codehighlighter1_0_78_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				<span id="Codehighlighter1_0_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_0_78_Open_Text">
						<span style="COLOR: #008000">/*</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> *    beg : 起点;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> *  end : 终点;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> *  n : 顶点个数;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> *  g : 邻接矩阵, 为全局变量, 下标(1, 1)起;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /> </span>
						<span style="COLOR: #008000">*/</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> pre[MAXN];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> dijkstra(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> beg, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> end, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_134_676_Open_Image" onclick="this.style.display='none'; Codehighlighter1_134_676_Open_Text.style.display='none'; Codehighlighter1_134_676_Closed_Image.style.display='inline'; Codehighlighter1_134_676_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_134_676_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_134_676_Closed_Text.style.display='none'; Codehighlighter1_134_676_Open_Image.style.display='inline'; Codehighlighter1_134_676_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_134_676_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_134_676_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i, j, u, min;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">dist </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">new</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">[n</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">visit </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">new</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">[n</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_233_276_Open_Image" onclick="this.style.display='none'; Codehighlighter1_233_276_Open_Text.style.display='none'; Codehighlighter1_233_276_Closed_Image.style.display='inline'; Codehighlighter1_233_276_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_233_276_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_233_276_Closed_Text.style.display='none'; Codehighlighter1_233_276_Open_Image.style.display='inline'; Codehighlighter1_233_276_Open_Text.style.display='inline';" src="http://www.cppblog.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">; i</span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000">n; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) </span>
						<span id="Codehighlighter1_233_276_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_233_276_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        dist[i] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> MAXNUM;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        visit[i] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">false</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    dist[beg] </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">; pre[beg] </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 id="Codehighlighter1_331_654_Open_Image" onclick="this.style.display='none'; Codehighlighter1_331_654_Open_Text.style.display='none'; Codehighlighter1_331_654_Closed_Image.style.display='inline'; Codehighlighter1_331_654_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_331_654_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_331_654_Closed_Text.style.display='none'; Codehighlighter1_331_654_Open_Image.style.display='inline'; Codehighlighter1_331_654_Open_Text.style.display='inline';" src="http://www.cppblog.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">n; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) </span>
						<span id="Codehighlighter1_331_654_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_331_654_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        min </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> MAXNUM;<br /><img id="Codehighlighter1_372_449_Open_Image" onclick="this.style.display='none'; Codehighlighter1_372_449_Open_Text.style.display='none'; Codehighlighter1_372_449_Closed_Image.style.display='inline'; Codehighlighter1_372_449_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_372_449_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_372_449_Closed_Text.style.display='none'; Codehighlighter1_372_449_Open_Image.style.display='inline'; Codehighlighter1_372_449_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (j</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">; j</span>
								<span style="COLOR: #000000">&lt;=</span>
								<span style="COLOR: #000000">n; j</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">) </span>
								<span id="Codehighlighter1_372_449_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_372_449_Open_Text">
										<span style="COLOR: #000000">{    <br /><img id="Codehighlighter1_410_445_Open_Image" onclick="this.style.display='none'; Codehighlighter1_410_445_Open_Text.style.display='none'; Codehighlighter1_410_445_Closed_Image.style.display='inline'; Codehighlighter1_410_445_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_410_445_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_410_445_Closed_Text.style.display='none'; Codehighlighter1_410_445_Open_Image.style.display='inline'; Codehighlighter1_410_445_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (min </span>
										<span style="COLOR: #000000">&gt;</span>
										<span style="COLOR: #000000"> dist[j] </span>
										<span style="COLOR: #000000">&amp;&amp;</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">!</span>
										<span style="COLOR: #000000">visit[j]) </span>
										<span id="Codehighlighter1_410_445_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_410_445_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                u </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> j;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                min </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> dist[j];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (min </span>
								<span style="COLOR: #000000">==</span>
								<span style="COLOR: #000000"> MAXNUM) </span>
								<span style="COLOR: #0000ff">break</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        visit[u] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">true</span>
								<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_521_626_Open_Image" onclick="this.style.display='none'; Codehighlighter1_521_626_Open_Text.style.display='none'; Codehighlighter1_521_626_Closed_Image.style.display='inline'; Codehighlighter1_521_626_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_521_626_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_521_626_Closed_Text.style.display='none'; Codehighlighter1_521_626_Open_Image.style.display='inline'; Codehighlighter1_521_626_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (j</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">; j</span>
								<span style="COLOR: #000000">&lt;=</span>
								<span style="COLOR: #000000">n; j</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">) </span>
								<span id="Codehighlighter1_521_626_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_521_626_Open_Text">
										<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_570_622_Open_Image" onclick="this.style.display='none'; Codehighlighter1_570_622_Open_Text.style.display='none'; Codehighlighter1_570_622_Closed_Image.style.display='inline'; Codehighlighter1_570_622_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_570_622_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_570_622_Closed_Text.style.display='none'; Codehighlighter1_570_622_Open_Image.style.display='inline'; Codehighlighter1_570_622_Open_Text.style.display='inline';" src="http://www.cppblog.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">visit[j] </span>
										<span style="COLOR: #000000">&amp;&amp;</span>
										<span style="COLOR: #000000"> dist[j] </span>
										<span style="COLOR: #000000">&gt;</span>
										<span style="COLOR: #000000"> dist[u]</span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000">g[u][j]) </span>
										<span id="Codehighlighter1_570_622_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_570_622_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                dist[j] </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> dist[u]</span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000">g[u][j];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                pre[j] </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> u;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (u </span>
								<span style="COLOR: #000000">==</span>
								<span style="COLOR: #000000"> end) </span>
								<span style="COLOR: #0000ff">break</span>
								<span style="COLOR: #000000">;        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> dist[end];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/11045.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-08-09 14:56 <a href="http://www.cppblog.com/qywyh/articles/11045.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>高精度运算永远不最终版(更新优化中..)</title><link>http://www.cppblog.com/qywyh/articles/6704.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Sun, 07 May 2006 08:13:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/6704.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/6704.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/6704.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/6704.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/6704.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: #include 				&lt;				iostream				&gt;																#include 				&lt;				string				&gt;																#include 				&lt;				algorithm				&gt;																				...&nbsp;&nbsp;<a href='http://www.cppblog.com/qywyh/articles/6704.html'>阅读全文</a><img src ="http://www.cppblog.com/qywyh/aggbug/6704.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-05-07 16:13 <a href="http://www.cppblog.com/qywyh/articles/6704.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Eratosthenes素数筛法</title><link>http://www.cppblog.com/qywyh/articles/6528.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Mon, 01 May 2006 15:06:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/6528.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/6528.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/6528.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/6528.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/6528.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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">memset(prime, </span>
				<span style="COLOR: #0000ff">true</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #0000ff">sizeof</span>
				<span style="COLOR: #000000">(prime));<br /><img id="Codehighlighter1_61_203_Open_Image" onclick="this.style.display='none'; Codehighlighter1_61_203_Open_Text.style.display='none'; Codehighlighter1_61_203_Closed_Image.style.display='inline'; Codehighlighter1_61_203_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_61_203_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_61_203_Closed_Text.style.display='none'; Codehighlighter1_61_203_Open_Image.style.display='inline'; Codehighlighter1_61_203_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.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"> </span>
				<span style="COLOR: #000000">2</span>
				<span style="COLOR: #000000">; i </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> MAX; i</span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000">) </span>
				<span id="Codehighlighter1_61_203_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_61_203_Open_Text">
						<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_84_201_Open_Image" onclick="this.style.display='none'; Codehighlighter1_84_201_Open_Text.style.display='none'; Codehighlighter1_84_201_Closed_Image.style.display='inline'; Codehighlighter1_84_201_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_84_201_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_84_201_Closed_Text.style.display='none'; Codehighlighter1_84_201_Open_Image.style.display='inline'; Codehighlighter1_84_201_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">(prime[i]) </span>
						<span id="Codehighlighter1_84_201_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_84_201_Open_Text">
								<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_129_191_Open_Image" onclick="this.style.display='none'; Codehighlighter1_129_191_Open_Text.style.display='none'; Codehighlighter1_129_191_Closed_Image.style.display='inline'; Codehighlighter1_129_191_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_129_191_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_129_191_Closed_Text.style.display='none'; Codehighlighter1_129_191_Open_Image.style.display='inline'; Codehighlighter1_129_191_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />                </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000">(j </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">2</span>
								<span style="COLOR: #000000">; i</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">j </span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000"> MAX; j</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">) </span>
								<span id="Codehighlighter1_129_191_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_129_191_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                        prime[i</span>
										<span style="COLOR: #000000">*</span>
										<span style="COLOR: #000000">j] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">false</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />                }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/6528.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-05-01 23:06 <a href="http://www.cppblog.com/qywyh/articles/6528.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>最小生成树prim算法</title><link>http://www.cppblog.com/qywyh/articles/6511.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Mon, 01 May 2006 04:06:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/6511.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/6511.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/6511.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/6511.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/6511.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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> CNST_NumGrphNodes </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">101</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.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_62_89_Open_Image" onclick="this.style.display='none'; Codehighlighter1_62_89_Open_Text.style.display='none'; Codehighlighter1_62_89_Closed_Image.style.display='inline'; Codehighlighter1_62_89_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_62_89_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_62_89_Closed_Text.style.display='none'; Codehighlighter1_62_89_Open_Image.style.display='inline'; Codehighlighter1_62_89_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000"> TTreeEdge </span>
				<span id="Codehighlighter1_62_89_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_62_89_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> v1, v2; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">double</span>
						<span style="COLOR: #000000"> w;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">候选集元素</span>
				<span style="COLOR: #008000">
						<br />
						<img id="Codehighlighter1_117_146_Open_Image" onclick="this.style.display='none'; Codehighlighter1_117_146_Open_Text.style.display='none'; Codehighlighter1_117_146_Closed_Image.style.display='inline'; Codehighlighter1_117_146_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_117_146_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_117_146_Closed_Text.style.display='none'; Codehighlighter1_117_146_Open_Image.style.display='inline'; Codehighlighter1_117_146_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000"> TCloseRec </span>
				<span id="Codehighlighter1_117_146_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_117_146_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">double</span>
						<span style="COLOR: #000000"> lowCost;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> vec;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_217_902_Open_Image" onclick="this.style.display='none'; Codehighlighter1_217_902_Open_Text.style.display='none'; Codehighlighter1_217_902_Closed_Image.style.display='inline'; Codehighlighter1_217_902_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_217_902_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_217_902_Closed_Text.style.display='none'; Codehighlighter1_217_902_Open_Image.style.display='inline'; Codehighlighter1_217_902_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> MST_prim(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> g[][CNST_NumGrphNodes], </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> n, TTreeEdge </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">minTree) </span>
				<span id="Codehighlighter1_217_902_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_217_902_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i, j, k;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    TCloseRec </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">close </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">new</span>
						<span style="COLOR: #000000"> TCloseRec[n];    <br /><img id="Codehighlighter1_293_346_Open_Image" onclick="this.style.display='none'; Codehighlighter1_293_346_Open_Text.style.display='none'; Codehighlighter1_293_346_Closed_Image.style.display='inline'; Codehighlighter1_293_346_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_293_346_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_293_346_Closed_Text.style.display='none'; Codehighlighter1_293_346_Open_Image.style.display='inline'; Codehighlighter1_293_346_Open_Text.style.display='inline';" src="http://www.cppblog.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">; i</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">n; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) </span>
						<span id="Codehighlighter1_293_346_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_293_346_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        close[i].vec </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        close[i].lowCost </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> g[i][</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    close[</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">].lowCost </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 id="Codehighlighter1_395_872_Open_Image" onclick="this.style.display='none'; Codehighlighter1_395_872_Open_Text.style.display='none'; Codehighlighter1_395_872_Closed_Image.style.display='inline'; Codehighlighter1_395_872_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_395_872_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_395_872_Closed_Text.style.display='none'; Codehighlighter1_395_872_Open_Image.style.display='inline'; Codehighlighter1_395_872_Open_Text.style.display='inline';" src="http://www.cppblog.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">n</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) </span>
						<span id="Codehighlighter1_395_872_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_395_872_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.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_427_480_Open_Image" onclick="this.style.display='none'; Codehighlighter1_427_480_Open_Text.style.display='none'; Codehighlighter1_427_480_Closed_Image.style.display='inline'; Codehighlighter1_427_480_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_427_480_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_427_480_Closed_Text.style.display='none'; Codehighlighter1_427_480_Open_Image.style.display='inline'; Codehighlighter1_427_480_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (k</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">; k</span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000">n; k</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">) </span>
								<span id="Codehighlighter1_427_480_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_427_480_Open_Text">
										<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_460_476_Open_Image" onclick="this.style.display='none'; Codehighlighter1_460_476_Open_Text.style.display='none'; Codehighlighter1_460_476_Closed_Image.style.display='inline'; Codehighlighter1_460_476_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_460_476_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_460_476_Closed_Text.style.display='none'; Codehighlighter1_460_476_Open_Image.style.display='inline'; Codehighlighter1_460_476_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (close[k].lowCost </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">) </span>
										<span id="Codehighlighter1_460_476_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_460_476_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span>
												<span style="COLOR: #0000ff">break</span>
												<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img id="Codehighlighter1_506_613_Open_Image" onclick="this.style.display='none'; Codehighlighter1_506_613_Open_Text.style.display='none'; Codehighlighter1_506_613_Closed_Image.style.display='inline'; Codehighlighter1_506_613_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_506_613_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_506_613_Closed_Text.style.display='none'; Codehighlighter1_506_613_Open_Image.style.display='inline'; Codehighlighter1_506_613_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (j</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">k</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">n; j</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">) </span>
								<span id="Codehighlighter1_506_613_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_506_613_Open_Text">
										<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_539_609_Open_Image" onclick="this.style.display='none'; Codehighlighter1_539_609_Open_Text.style.display='none'; Codehighlighter1_539_609_Closed_Image.style.display='inline'; Codehighlighter1_539_609_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_539_609_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_539_609_Closed_Text.style.display='none'; Codehighlighter1_539_609_Open_Image.style.display='inline'; Codehighlighter1_539_609_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (close[j].lowCost </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">) </span>
										<span id="Codehighlighter1_539_609_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_539_609_Open_Text">
												<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_586_604_Open_Image" onclick="this.style.display='none'; Codehighlighter1_586_604_Open_Text.style.display='none'; Codehighlighter1_586_604_Closed_Image.style.display='inline'; Codehighlighter1_586_604_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_586_604_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_586_604_Closed_Text.style.display='none'; Codehighlighter1_586_604_Open_Image.style.display='inline'; Codehighlighter1_586_604_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />                </span>
												<span style="COLOR: #0000ff">if</span>
												<span style="COLOR: #000000"> (close[j].lowCost </span>
												<span style="COLOR: #000000">&lt;</span>
												<span style="COLOR: #000000"> close[k].lowCost) </span>
												<span id="Codehighlighter1_586_604_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</span>
												<span id="Codehighlighter1_586_604_Open_Text">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    k </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> j;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />                }</span>
												</span>
												<span style="COLOR: #000000">
														<br />
														<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">加入树中</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        minTree[i].v1 </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> k;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        minTree[i].v2 </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> close[k].vec;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        minTree[i].w </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> close[k].lowCost;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        close[k].lowCost </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.cppblog.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_769_869_Open_Image" onclick="this.style.display='none'; Codehighlighter1_769_869_Open_Text.style.display='none'; Codehighlighter1_769_869_Closed_Image.style.display='inline'; Codehighlighter1_769_869_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_769_869_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_769_869_Closed_Text.style.display='none'; Codehighlighter1_769_869_Open_Image.style.display='inline'; Codehighlighter1_769_869_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.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">1</span>
								<span style="COLOR: #000000">; j</span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000">n; j</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">) </span>
								<span id="Codehighlighter1_769_869_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_769_869_Open_Text">
										<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_806_865_Open_Image" onclick="this.style.display='none'; Codehighlighter1_806_865_Open_Text.style.display='none'; Codehighlighter1_806_865_Closed_Image.style.display='inline'; Codehighlighter1_806_865_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_806_865_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_806_865_Closed_Text.style.display='none'; Codehighlighter1_806_865_Open_Image.style.display='inline'; Codehighlighter1_806_865_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (close[j].lowCost </span>
										<span style="COLOR: #000000">&gt;</span>
										<span style="COLOR: #000000"> g[j][k]) </span>
										<span id="Codehighlighter1_806_865_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_806_865_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                close[j].lowCost </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> g[j][k];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                close[j].vec </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> k;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    delete []close;<br /><img src="http://www.cppblog.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.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/6511.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-05-01 12:06 <a href="http://www.cppblog.com/qywyh/articles/6511.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>整型转字符串</title><link>http://www.cppblog.com/qywyh/articles/6391.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Thu, 27 Apr 2006 11:00:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/6391.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/6391.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/6391.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/6391.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/6391.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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">string</span>
				<span style="COLOR: #000000"> changeIntToString(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a)<br /><img id="Codehighlighter1_32_205_Open_Image" onclick="this.style.display='none'; Codehighlighter1_32_205_Open_Text.style.display='none'; Codehighlighter1_32_205_Closed_Image.style.display='inline'; Codehighlighter1_32_205_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_32_205_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_32_205_Closed_Text.style.display='none'; Codehighlighter1_32_205_Open_Image.style.display='inline'; Codehighlighter1_32_205_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_32_205_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_32_205_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">string</span>
						<span style="COLOR: #000000"> ans;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">string</span>
						<span style="COLOR: #000000"> ans1;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> k </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">10</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000"> (a </span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_90_128_Open_Image" onclick="this.style.display='none'; Codehighlighter1_90_128_Open_Text.style.display='none'; Codehighlighter1_90_128_Closed_Image.style.display='inline'; Codehighlighter1_90_128_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_90_128_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_90_128_Closed_Text.style.display='none'; Codehighlighter1_90_128_Open_Image.style.display='inline'; Codehighlighter1_90_128_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_90_128_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_90_128_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        ans </span>
								<span style="COLOR: #000000">+=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">char</span>
								<span style="COLOR: #000000">(a</span>
								<span style="COLOR: #000000">%</span>
								<span style="COLOR: #000000">10</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">48</span>
								<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        a </span>
								<span style="COLOR: #000000">/=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">10</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">ans.size()</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">&gt;=</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">--</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_168_189_Open_Image" onclick="this.style.display='none'; Codehighlighter1_168_189_Open_Text.style.display='none'; Codehighlighter1_168_189_Closed_Image.style.display='inline'; Codehighlighter1_168_189_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_168_189_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_168_189_Closed_Text.style.display='none'; Codehighlighter1_168_189_Open_Image.style.display='inline'; Codehighlighter1_168_189_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_168_189_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_168_189_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        ans1 </span>
								<span style="COLOR: #000000">+=</span>
								<span style="COLOR: #000000"> ans[i];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> ans1;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/6391.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-04-27 19:00 <a href="http://www.cppblog.com/qywyh/articles/6391.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>最长公共子序列函数 O(n^2) </title><link>http://www.cppblog.com/qywyh/articles/5577.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Fri, 14 Apr 2006 12:57:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/5577.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/5577.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/5577.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/5577.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/5577.html</trackback:ping><description><![CDATA[
		<p>做 Commen Subsequence 时写的:</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.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> lcs(</span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">x, </span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">y)<br /><img id="Codehighlighter1_25_524_Open_Image" onclick="this.style.display='none'; Codehighlighter1_25_524_Open_Text.style.display='none'; Codehighlighter1_25_524_Closed_Image.style.display='inline'; Codehighlighter1_25_524_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_25_524_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_25_524_Closed_Text.style.display='none'; Codehighlighter1_25_524_Open_Image.style.display='inline'; Codehighlighter1_25_524_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_25_524_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_25_524_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> m </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> strlen(x)</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> n </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> strlen(y)</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> record[MAX][MAX];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i, j;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.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">m; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_128_151_Open_Image" onclick="this.style.display='none'; Codehighlighter1_128_151_Open_Text.style.display='none'; Codehighlighter1_128_151_Closed_Image.style.display='inline'; Codehighlighter1_128_151_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_128_151_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_128_151_Closed_Text.style.display='none'; Codehighlighter1_128_151_Open_Image.style.display='inline'; Codehighlighter1_128_151_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_128_151_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_128_151_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        record[i][</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (j</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">; j</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">n; j</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_175_198_Open_Image" onclick="this.style.display='none'; Codehighlighter1_175_198_Open_Text.style.display='none'; Codehighlighter1_175_198_Closed_Image.style.display='inline'; Codehighlighter1_175_198_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_175_198_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_175_198_Closed_Text.style.display='none'; Codehighlighter1_175_198_Open_Image.style.display='inline'; Codehighlighter1_175_198_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_175_198_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_175_198_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        record[</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">][j] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.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">1</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">m; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_223_496_Open_Image" onclick="this.style.display='none'; Codehighlighter1_223_496_Open_Text.style.display='none'; Codehighlighter1_223_496_Closed_Image.style.display='inline'; Codehighlighter1_223_496_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_223_496_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_223_496_Closed_Text.style.display='none'; Codehighlighter1_223_496_Open_Image.style.display='inline'; Codehighlighter1_223_496_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_223_496_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_223_496_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (j</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">; j</span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000">n; j</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_249_493_Open_Image" onclick="this.style.display='none'; Codehighlighter1_249_493_Open_Text.style.display='none'; Codehighlighter1_249_493_Closed_Image.style.display='inline'; Codehighlighter1_249_493_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_249_493_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_249_493_Closed_Text.style.display='none'; Codehighlighter1_249_493_Open_Image.style.display='inline'; Codehighlighter1_249_493_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_249_493_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_249_493_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (x[i</span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">] </span>
										<span style="COLOR: #000000">==</span>
										<span style="COLOR: #000000"> y[j</span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">])<br /><img id="Codehighlighter1_279_325_Open_Image" onclick="this.style.display='none'; Codehighlighter1_279_325_Open_Text.style.display='none'; Codehighlighter1_279_325_Closed_Image.style.display='inline'; Codehighlighter1_279_325_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_279_325_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_279_325_Closed_Text.style.display='none'; Codehighlighter1_279_325_Open_Image.style.display='inline'; Codehighlighter1_279_325_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span id="Codehighlighter1_279_325_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_279_325_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                record[i][j] </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> record[i</span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">][j</span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">] </span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">else</span>
										<span style="COLOR: #000000">
												<br />
												<img id="Codehighlighter1_338_489_Open_Image" onclick="this.style.display='none'; Codehighlighter1_338_489_Open_Text.style.display='none'; Codehighlighter1_338_489_Closed_Image.style.display='inline'; Codehighlighter1_338_489_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
												<img id="Codehighlighter1_338_489_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_338_489_Closed_Text.style.display='none'; Codehighlighter1_338_489_Open_Image.style.display='inline'; Codehighlighter1_338_489_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span id="Codehighlighter1_338_489_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_338_489_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span>
												<span style="COLOR: #0000ff">if</span>
												<span style="COLOR: #000000"> (record[i</span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">][j] </span>
												<span style="COLOR: #000000">&gt;</span>
												<span style="COLOR: #000000"> record[i][j</span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">])<br /><img id="Codehighlighter1_385_427_Open_Image" onclick="this.style.display='none'; Codehighlighter1_385_427_Open_Text.style.display='none'; Codehighlighter1_385_427_Closed_Image.style.display='inline'; Codehighlighter1_385_427_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_385_427_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_385_427_Closed_Text.style.display='none'; Codehighlighter1_385_427_Open_Image.style.display='inline'; Codehighlighter1_385_427_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />                </span>
												<span id="Codehighlighter1_385_427_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</span>
												<span id="Codehighlighter1_385_427_Open_Text">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    record[i][j] </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> record[i</span>
														<span style="COLOR: #000000">-</span>
														<span style="COLOR: #000000">1</span>
														<span style="COLOR: #000000">][j];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />                }</span>
												</span>
												<span style="COLOR: #000000">
														<br />
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span>
												<span style="COLOR: #0000ff">else</span>
												<span style="COLOR: #000000">
														<br />
														<img id="Codehighlighter1_442_484_Open_Image" onclick="this.style.display='none'; Codehighlighter1_442_484_Open_Text.style.display='none'; Codehighlighter1_442_484_Closed_Image.style.display='inline'; Codehighlighter1_442_484_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
														<img id="Codehighlighter1_442_484_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_442_484_Closed_Text.style.display='none'; Codehighlighter1_442_484_Open_Image.style.display='inline'; Codehighlighter1_442_484_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />                </span>
												<span id="Codehighlighter1_442_484_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</span>
												<span id="Codehighlighter1_442_484_Open_Text">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    record[i][j] </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> record[i][j</span>
														<span style="COLOR: #000000">-</span>
														<span style="COLOR: #000000">1</span>
														<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />                }</span>
												</span>
												<span style="COLOR: #000000">
														<br />
														<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> record[m</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">][n</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/5577.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-04-14 20:57 <a href="http://www.cppblog.com/qywyh/articles/5577.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>高精度加减法  (a绝对值&gt;b绝对值)</title><link>http://www.cppblog.com/qywyh/articles/3653.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Thu, 02 Mar 2006 13:59:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/3653.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/3653.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/3653.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/3653.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/3653.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: int				 Dec(				char				 				*				a,				char				 				*				b,				char				 				*				ans){    				int				 aLen,bLen;    				int				 aLast,bLast,ansLast;    aLen 				=...&nbsp;&nbsp;<a href='http://www.cppblog.com/qywyh/articles/3653.html'>阅读全文</a><img src ="http://www.cppblog.com/qywyh/aggbug/3653.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-03-02 21:59 <a href="http://www.cppblog.com/qywyh/articles/3653.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>有序数列的二分查找</title><link>http://www.cppblog.com/qywyh/articles/2355.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Mon, 02 Jan 2006 03:40:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/2355.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/2355.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/2355.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/2355.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/2355.html</trackback:ping><description><![CDATA[<P>&nbsp;</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.cppblog.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">#include</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">iostream</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top>#include</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">vector</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">using</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">namespace</SPAN><SPAN style="COLOR: #000000">&nbsp;std;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;main()<BR><IMG id=Codehighlighter1_70_591_Open_Image onclick="this.style.display='none'; Codehighlighter1_70_591_Open_Text.style.display='none'; Codehighlighter1_70_591_Closed_Image.style.display='inline'; Codehighlighter1_70_591_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_70_591_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_70_591_Closed_Text.style.display='none'; Codehighlighter1_70_591_Open_Image.style.display='inline'; Codehighlighter1_70_591_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_70_591_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_70_591_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;vector</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;vec(</SPAN><SPAN style="COLOR: #000000">5</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;fnum;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;tdo</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</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.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;low</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,high</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">vec.size()</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">,mid;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;i</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">5</SPAN><SPAN style="COLOR: #000000">;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_181_198_Open_Image onclick="this.style.display='none'; Codehighlighter1_181_198_Open_Text.style.display='none'; Codehighlighter1_181_198_Closed_Image.style.display='inline'; Codehighlighter1_181_198_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_181_198_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_181_198_Closed_Text.style.display='none'; Codehighlighter1_181_198_Open_Image.style.display='inline'; Codehighlighter1_181_198_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_181_198_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_181_198_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vec[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">;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">假设有序数列升序</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;cout</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">please&nbsp;input&nbsp;fnum=?</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">endl;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;cin</SPAN><SPAN style="COLOR: #000000">&gt;&gt;</SPAN><SPAN style="COLOR: #000000">fnum;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">while</SPAN><SPAN style="COLOR: #000000">(low</SPAN><SPAN style="COLOR: #000000">&lt;=</SPAN><SPAN style="COLOR: #000000">high)<BR><IMG id=Codehighlighter1_279_508_Open_Image onclick="this.style.display='none'; Codehighlighter1_279_508_Open_Text.style.display='none'; Codehighlighter1_279_508_Closed_Image.style.display='inline'; Codehighlighter1_279_508_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_279_508_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_279_508_Closed_Text.style.display='none'; Codehighlighter1_279_508_Open_Image.style.display='inline'; Codehighlighter1_279_508_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_279_508_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_279_508_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mid</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">(low</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">high)</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(fnum</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">vec[mid])<BR><IMG id=Codehighlighter1_324_408_Open_Image onclick="this.style.display='none'; Codehighlighter1_324_408_Open_Text.style.display='none'; Codehighlighter1_324_408_Closed_Image.style.display='inline'; Codehighlighter1_324_408_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_324_408_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_324_408_Closed_Text.style.display='none'; Codehighlighter1_324_408_Open_Image.style.display='inline'; Codehighlighter1_324_408_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_324_408_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_324_408_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">tdo=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&lt;&lt;++</SPAN><SPAN style="COLOR: #000000">tdo</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">endl;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">vec[</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">mid</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">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">fnum</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">endl;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">break</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(fnum</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">vec[mid])<BR><IMG id=Codehighlighter1_437_466_Open_Image onclick="this.style.display='none'; Codehighlighter1_437_466_Open_Text.style.display='none'; Codehighlighter1_437_466_Closed_Image.style.display='inline'; Codehighlighter1_437_466_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_437_466_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_437_466_Closed_Text.style.display='none'; Codehighlighter1_437_466_Open_Image.style.display='inline'; Codehighlighter1_437_466_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_437_466_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_437_466_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tdo</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;high</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">mid</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_477_505_Open_Image onclick="this.style.display='none'; Codehighlighter1_477_505_Open_Text.style.display='none'; Codehighlighter1_477_505_Closed_Image.style.display='inline'; Codehighlighter1_477_505_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_477_505_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_477_505_Closed_Text.style.display='none'; Codehighlighter1_477_505_Open_Image.style.display='inline'; Codehighlighter1_477_505_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_477_505_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_477_505_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tdo</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;low</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">mid</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(low</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">high)<BR><IMG id=Codehighlighter1_525_589_Open_Image onclick="this.style.display='none'; Codehighlighter1_525_589_Open_Text.style.display='none'; Codehighlighter1_525_589_Closed_Image.style.display='inline'; Codehighlighter1_525_589_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_525_589_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_525_589_Closed_Text.style.display='none'; Codehighlighter1_525_589_Open_Image.style.display='inline'; Codehighlighter1_525_589_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_525_589_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_525_589_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">tdo=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&lt;&lt;++</SPAN><SPAN style="COLOR: #000000">tdo</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">endl;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">not&nbsp;found&nbsp;fnum</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">endl;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV><img src ="http://www.cppblog.com/qywyh/aggbug/2355.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-01-02 11:40 <a href="http://www.cppblog.com/qywyh/articles/2355.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>冒泡排序的优化算法</title><link>http://www.cppblog.com/qywyh/articles/1633.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Thu, 08 Dec 2005 09:52:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/articles/1633.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/1633.html</wfw:comment><comments>http://www.cppblog.com/qywyh/articles/1633.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/1633.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/1633.html</trackback:ping><description><![CDATA[<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">&nbsp;sort(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;a[],</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;length)<BR><IMG id=Codehighlighter1_30_394_Open_Image onclick="this.style.display='none'; Codehighlighter1_30_394_Open_Text.style.display='none'; Codehighlighter1_30_394_Closed_Image.style.display='inline'; Codehighlighter1_30_394_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_30_394_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_30_394_Closed_Text.style.display='none'; Codehighlighter1_30_394_Open_Image.style.display='inline'; Codehighlighter1_30_394_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_30_394_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_30_394_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;k</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">length</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">,j,kk,temp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">k为最后一次调换的位置,kk为临时计数器</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">while</SPAN><SPAN style="COLOR: #000000">(k</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_108_377_Open_Image onclick="this.style.display='none'; Codehighlighter1_108_377_Open_Text.style.display='none'; Codehighlighter1_108_377_Closed_Image.style.display='inline'; Codehighlighter1_108_377_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_108_377_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_108_377_Closed_Text.style.display='none'; Codehighlighter1_108_377_Open_Image.style.display='inline'; Codehighlighter1_108_377_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_108_377_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_108_377_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;kk</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">(j</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;j</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">k;j</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_162_355_Open_Image onclick="this.style.display='none'; Codehighlighter1_162_355_Open_Text.style.display='none'; Codehighlighter1_162_355_Closed_Image.style.display='inline'; Codehighlighter1_162_355_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_162_355_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_162_355_Closed_Text.style.display='none'; Codehighlighter1_162_355_Open_Image.style.display='inline'; Codehighlighter1_162_355_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_162_355_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_162_355_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(a[j]</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">a[j</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">])<BR><IMG id=Codehighlighter1_209_344_Open_Image onclick="this.style.display='none'; Codehighlighter1_209_344_Open_Text.style.display='none'; Codehighlighter1_209_344_Closed_Image.style.display='inline'; Codehighlighter1_209_344_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_209_344_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_209_344_Closed_Text.style.display='none'; Codehighlighter1_209_344_Open_Image.style.display='inline'; Codehighlighter1_209_344_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_209_344_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_209_344_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;temp</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">a[j];<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[j]</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">a[j</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">];<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[j</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">]</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">temp;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;kk</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">j;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">kk;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;a;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></SPAN></DIV><BR><BR><BR><img src ="http://www.cppblog.com/qywyh/aggbug/1633.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2005-12-08 17:52 <a href="http://www.cppblog.com/qywyh/articles/1633.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>