锘??xml version="1.0" encoding="utf-8" standalone="yes"?>99久久精品国产一区二区蜜芽 ,久久精品成人免费网站,国产一区二区久久久http://www.shnenglu.com/lzmagic/category/10078.html鍗氬 瀹¢棶 鎱庢?鏄庤鯨 絎冭zh-cnSat, 11 Apr 2009 11:28:04 GMTSat, 11 Apr 2009 11:28:04 GMT60Floyd_Warshall綆楁硶http://www.shnenglu.com/lzmagic/archive/2009/04/11/79566.htmllzmagiclzmagicFri, 10 Apr 2009 19:14:00 GMThttp://www.shnenglu.com/lzmagic/archive/2009/04/11/79566.htmlhttp://www.shnenglu.com/lzmagic/comments/79566.htmlhttp://www.shnenglu.com/lzmagic/archive/2009/04/11/79566.html#Feedback0http://www.shnenglu.com/lzmagic/comments/commentRss/79566.htmlhttp://www.shnenglu.com/lzmagic/services/trackbacks/79566.html/**
 * FLOYD_WARSHALL 鎵鏈夐《鐐瑰鐨勬渶鐭礬寰勭畻娉?nbsp;(All-Pairs Shortest Path Algorithm)
 * 杈撳叆錛氬浘g
 * 杈撳嚭錛氭墍鏈夐《鐐瑰鐨勬渶鐭礬寰勯暱
 * 緇撴瀯錛氬浘g鐢ㄩ偦鎺ョ煩闃佃〃紺?br> * 綆楁硶錛欶loyd_Warshall綆楁硶(鍔ㄦ佽鍒?
 * 澶嶆潅搴︼細O(|V|^3) 
 
*/

#include 
<iostream>
#include 
<string>
#include 
<vector>
#include 
<deque>
#include 
<list>
#include 
<stack>
#include 
<queue>
#include 
<iterator>
#include 
<algorithm>
#include 
<numeric>
#include 
<functional>
#include 
<climits>
using namespace std;

int n;
vector
<vector<int> > g;
vector
<vector<int> > dist;

void Floyd_Warshall()
{
    
// 鍒濆鍖杁ist錛岄《鐐歸棿(鏃犱腑闂撮《鐐?鏈鐭礬寰勯暱涓鴻竟闀匡紝欏剁偣鍒拌嚜韜殑鏈鐭礬寰勯暱涓?銆?nbsp;
    dist = g;
    
for (int i = 0; i < n; ++i)  
        dist[i][i] 
= 0;
    
// 浠庨《鐐筰鍒板畾鐐筳涓斾腑闂撮《鐐圭殕灞炰簬闆嗗悎{0, 1, 2, , k}鐨勬渶鐭礬寰勯暱銆?nbsp;
    for (int k = 0; k < n; ++k)
        
for (int i = 0; i < n; ++i)
            
for (int j = 0; j < n; ++j)
                
if (dist[i][k] < INT_MAX && dist[k][j] < INT_MAX)
                    dist[i][j] 
= min(dist[i][j], dist[i][k] + dist[k][j]);
}


int main()
{
    n 
= 5;    
    g.assign(n, vector
<int>(n, INT_MAX));
    g[
0][1= 3; g[0][2= 8; g[0][4= -4;
    g[
1][3= 1; g[1][4= 7;
    g[
2][1= 4
    g[
3][0= 2; g[3][2= -5;
    g[
4][3= 6;
     
    Floyd_Warshall();
    
    
for (int i = 0; i < n; ++i)
    
{
        
for (int j = 0; j < n; ++j)
            cout 
<< dist[i][j] << ' ';
        cout 
<< endl;        
    }

    
    system(
"pause");
    
return 0;
}



lzmagic 2009-04-11 03:14 鍙戣〃璇勮
]]>
Kruskal綆楁硶http://www.shnenglu.com/lzmagic/archive/2009/04/10/79542.htmllzmagiclzmagicFri, 10 Apr 2009 11:41:00 GMThttp://www.shnenglu.com/lzmagic/archive/2009/04/10/79542.htmlhttp://www.shnenglu.com/lzmagic/comments/79542.htmlhttp://www.shnenglu.com/lzmagic/archive/2009/04/10/79542.html#Feedback0http://www.shnenglu.com/lzmagic/comments/commentRss/79542.htmlhttp://www.shnenglu.com/lzmagic/services/trackbacks/79542.html/**
 * KRUSKAL 鏈灝忕敓鎴愭爲綆楁硶 (Minimum Spanning Tree) 
 * 杈撳叆錛氬浘g錛?nbsp;                // 鏈夊悜鍥炬垨鑰呮棤鍚戝浘 
 * 杈撳嚭錛?1)鏈灝忕敓鎴愭爲闀縮um錛?nbsp;
 *         (2)鏈灝忕敓鎴愭爲mst銆?br> * 緇撴瀯: 鍥緂鐢ㄩ《鐐規暟n鍜岃竟闆唀dges(浼樺厛闃熷垪)琛ㄧず錛屼袱鐐規槸鍚﹁繛閫氱敤騫舵煡闆嗗疄鐜般?nbsp;
 * 綆楁硶錛欿ruskal綆楁硶  
 * 澶嶆潅搴︼細O(|E|*log|E|)~O(|E|*log|V|) 
 
*/
 
#include 
<iostream>
#include 
<string>
#include 
<vector>
#include 
<deque>
#include 
<list>
#include 
<stack>
#include 
<queue>
#include 
<set>
#include 
<map>
#include 
<bitset>
#include 
<iterator>
#include 
<algorithm>
#include 
<numeric>
#include 
<functional>
#include 
<climits>
using namespace std;

struct Edge
{
    
int u, v, w;        // u銆乿:涓や釜欏剁偣  w:鏉?nbsp;
    Edge() { }
    Edge(
int u0, int v0, int w0):u(u0), v(v0), w(w0) { }
}
;

int n;                    // n : 欏剁偣涓暟 
vector<Edge> edges;        // edges : 鍥緂鐨勬墍鏈夎竟 
int sum;                // sum : 鏈灝忕敓鎴愭爲闀?nbsp;
vector<Edge> mst;        // mst : 鏈灝忕敓鎴愭爲(鐢ㄨ竟闆嗚〃紺? 

class DisjSets
{
    vector
<int> s;
    
public:
        DisjSets(
int n) : s(n, -1{ };
        
int find (int x)
        
{
            
if (s[x] < 0return x;
            
else return s[x] = find(s[x]);   // 鍘嬬緝璺緞銆?nbsp;
        }
;
        
void unionSets(int root1, int root2)
        
{
            
if (s[root1] > s[root2])    // 鎸変釜鏁版眰騫?涓暟鐢ㄨ礋鏁拌〃紺?銆?nbsp;
            {
                s[root2] 
+= s[root1];
                s[root1] 
= root2;
            }

            
else
            
{
                s[root1] 
+= s[root2];
                s[root2] 
= root1;
            }

        }
;
}


bool Cmp(const Edge &lhs, const Edge &rhs)
{
    
return lhs.w > rhs.w;
}
 

bool Kruskal()
{
    DisjSets ds(n);
    make_heap(edges.begin(), edges.end(), Cmp);    
// 瀵硅竟闆嗗緩鍫嗐?nbsp;
    int root1, root2;
    Edge e;
    
while (!edges.empty())    // 閬嶅巻鎵鏈夎竟錛?nbsp;
    {
        e 
= edges.front(); pop_heap(edges.begin(), edges.end(), Cmp); edges.pop_back();// 浠庢湭閫夎竟闆嗕腑瀵繪壘鏈灝忔潈鐨勮竟e銆?nbsp;
        root1 = ds.find(e.u), root2 = ds.find(e.v);    // 鑾峰彇u銆乿鎵鍦ㄧ殑鐐歸泦錛?nbsp;
        if (root1 != root2)                // 濡傛灉u銆乿涓嶆槸鍚屼竴涓偣闆嗭紝 
        {
            sum 
+= e.w;                 // 璋冩暣鏈灝忕敓鎴愭爲闀?nbsp;
            mst.push_back(e);             // 鎶婅竟e鏀懼叆鏈灝忕敓鎴愭爲mst涓紝 
            ds.unionSets(root1, root2);    // 鍚堝茍涓ょ偣鎵鍦ㄧ殑鐐歸泦銆?nbsp;
        }

        
if (mst.size() == n - 1return true// 濡傛灉閫夊彇杈逛釜鏁頒負n - 1錛屾垚鍔熴?/span>
    }

    
return false;  
}


int main()
{
    n 
= 7;
    edges.clear();
    edges.push_back(Edge(
012)); edges.push_back(Edge(024));  edges.push_back(Edge(031));
    edges.push_back(Edge(
133)); edges.push_back(Edge(1410));
     edges.push_back(Edge(
232)); edges.push_back(Edge(255));
     edges.push_back(Edge(
347)); edges.push_back(Edge(358)); edges.push_back(Edge(364));
     edges.push_back(Edge(
466));
     edges.push_back(Edge(
561));
     
     sum 
= 0;
     mst.clear();
     
if(Kruskal())
     
{
        cout 
<< sum << endl;
        
for (vector<Edge>::iterator it = mst.begin(); it != mst.end(); ++it)
            cout 
<< it-><< "->" << it-><< endl;
    }

    
else
    
{
        cout 
<< "Some vertex cann't be reached." << endl; 
    }

     
    system(
"pause");
    
return 0;
}



lzmagic 2009-04-10 19:41 鍙戣〃璇勮
]]>
Prim綆楁硶http://www.shnenglu.com/lzmagic/archive/2009/04/10/79536.htmllzmagiclzmagicFri, 10 Apr 2009 11:11:00 GMThttp://www.shnenglu.com/lzmagic/archive/2009/04/10/79536.htmlhttp://www.shnenglu.com/lzmagic/comments/79536.htmlhttp://www.shnenglu.com/lzmagic/archive/2009/04/10/79536.html#Feedback0http://www.shnenglu.com/lzmagic/comments/commentRss/79536.htmlhttp://www.shnenglu.com/lzmagic/services/trackbacks/79536.html/**
 * PRIM(綆鍗曠増) 鏈灝忕敓鎴愭爲綆楁硶 (Minimum Spanning Tree) 
 * 杈撳叆錛氬浘g錛?nbsp;                // 鏈夊悜鍥炬垨鑰呮棤鍚戝浘 
 * 杈撳嚭錛?1)鏈灝忕敓鎴愭爲闀縮um錛?nbsp;
 *         (2)鏈灝忕敓鎴愭爲prev銆?br> * 緇撴瀯: 鍥緂鐢ㄩ偦鎺ョ煩闃佃〃紺猴紝鏈鐭竟闀縟ist鐢ㄦ暟緇勮〃紺恒?nbsp;
 * 綆楁硶錛歅rim綆楁硶  
 * 澶嶆潅搴︼細O(|V|^2) 
 
*/
 
#include 
<iostream>
#include 
<vector>
#include 
<list>
#include 
<iterator>
#include 
<algorithm>
#include 
<numeric>
#include 
<functional>
#include 
<climits>
using namespace std;

int n;                    // n : 欏剁偣涓暟 
vector<vector<int> > g; // g : 鍥?graph)(鐢ㄩ偦鎺ョ煩闃?adjacent matrix)琛ㄧず) 
vector<bool> known;        // known : 鍚勭偣鏄惁宸茬粡閫夊彇 
vector<int> dist;        // dist : 宸查夊彇鐐歸泦鍒版湭閫夊彇鐐圭殑鏈灝忚竟闀?nbsp;
vector<int> prev;        // prev : 鏈灝忕敓鎴愭爲涓悇鐐圭殑鍓嶄竴欏剁偣
int s;                    // s : 璧風偣(start) 
int sum;                // sum : 鏈灝忕敓鎴愭爲闀?nbsp;

bool Prim()                // 璐績綆楁硶(Greedy Algorithm) 
{
    known.assign(n, 
false);
    dist.assign(n, INT_MAX);
    prev.resize(n);            
// 鍒濆鍖杒nown銆乨ist銆乸rev銆?nbsp;
    dist[s] = 0;            // 鍒濆鍖栬搗鐐瑰埌鑷韓鐨勮礬寰勯暱涓?銆?/span>
    int i; 
    
for (i = 0; i < n; ++i)
    
{
        
int min = INT_MAX, v;
        
for (int i = 0; i < n; ++i)
            
if (!known[i] && min > dist[i])
                min 
= dist[i], v = i;    // 瀵繪壘鏈煡鐨勬渶鐭礬寰勯暱鐨勯《鐐箆錛?nbsp;
        if (min == INT_MAX) break;        // 濡傛灉鎵句笉鍒幫紝閫鍑猴紱 
        known[v] = true;                // 濡傛灉鎵懼埌錛屽皢欏剁偣v璁句負宸茬煡錛?/span>
        sum += dist[v];                 // 璋冩暣鏈灝忕敓鎴愭爲闀?nbsp;
        for (int w = 0; w < n; ++w)        // 閬嶅巻鎵鏈塿鎸囧悜鐨勯《鐐箇錛?nbsp;
            if (!known[w] && g[v][w] < INT_MAX && dist[w] > g[v][w])
                dist[w] 
= g[v][w], prev[w] = v;    // 璋冩暣欏剁偣w鐨勬渶鐭礬寰勯暱dist鍜屾渶鐭礬寰勭殑鍓嶄竴欏剁偣 prev銆?nbsp;
    }

    
return i == n; // 濡傛灉閫夊彇欏剁偣涓暟涓簄錛屾垚鍔熴?nbsp;
}


int main()
{
    n 
= 7;
    g.assign(n, vector
<int>(n, INT_MAX));
    g[
0][1= g[1][0= 2; g[0][2= g[2][0= 4;   g[0][3= g[3][0= 1;
    g[
1][3= g[3][1= 3; g[1][4= g[4][1= 10;
    g[
2][3= g[3][2= 2; g[2][5= g[5][2= 5;
    g[
3][4= g[4][3= 7; g[3][5= g[5][3= 8; g[3][6= g[6][3= 4;
    g[
4][6= g[6][4= 6;
    g[
5][6= g[6][5= 1
    
    s 
= 0;        // 璧風偣浠婚?nbsp;
    sum = 0;
    
if (Prim())
    
{
        cout 
<< sum << endl;
        
for (int i = 1; i < n; ++i)
            
if(i != s) cout << prev[i] << "->" << i << endl;
    }

    
else
    
{
        cout 
<< "Some vertex cann't be reached." << endl; 
    }

    
    system(
"pause");
    
return 0;
}



lzmagic 2009-04-10 19:11 鍙戣〃璇勮
]]>
Critical Path 鍏抽敭璺緞 http://www.shnenglu.com/lzmagic/archive/2009/04/09/79394.htmllzmagiclzmagicThu, 09 Apr 2009 15:02:00 GMThttp://www.shnenglu.com/lzmagic/archive/2009/04/09/79394.htmlhttp://www.shnenglu.com/lzmagic/comments/79394.htmlhttp://www.shnenglu.com/lzmagic/archive/2009/04/09/79394.html#Feedback0http://www.shnenglu.com/lzmagic/comments/commentRss/79394.htmlhttp://www.shnenglu.com/lzmagic/services/trackbacks/79394.html闃呰鍏ㄦ枃

lzmagic 2009-04-09 23:02 鍙戣〃璇勮
]]>
Bellman_Ford綆楁硶 SPFA綆楁硶http://www.shnenglu.com/lzmagic/archive/2009/04/09/79359.htmllzmagiclzmagicThu, 09 Apr 2009 11:16:00 GMThttp://www.shnenglu.com/lzmagic/archive/2009/04/09/79359.htmlhttp://www.shnenglu.com/lzmagic/comments/79359.htmlhttp://www.shnenglu.com/lzmagic/archive/2009/04/09/79359.html#Feedback0http://www.shnenglu.com/lzmagic/comments/commentRss/79359.htmlhttp://www.shnenglu.com/lzmagic/services/trackbacks/79359.html闃呰鍏ㄦ枃

lzmagic 2009-04-09 19:16 鍙戣〃璇勮
]]>
Dijkstra綆楁硶http://www.shnenglu.com/lzmagic/archive/2009/04/09/79329.htmllzmagiclzmagicThu, 09 Apr 2009 02:45:00 GMThttp://www.shnenglu.com/lzmagic/archive/2009/04/09/79329.htmlhttp://www.shnenglu.com/lzmagic/comments/79329.htmlhttp://www.shnenglu.com/lzmagic/archive/2009/04/09/79329.html#Feedback0http://www.shnenglu.com/lzmagic/comments/commentRss/79329.htmlhttp://www.shnenglu.com/lzmagic/services/trackbacks/79329.html/**
 * DIJKSTRA(綆鍗曠増) 鍗曟簮鏈鐭礬寰勭畻娉曪紙涓嶅厑璁稿瓨鍦ㄨ礋杈癸級
 * 杈撳叆錛?1)鍥緂錛?nbsp;       // 鏈夊悜鍥炬垨鑰呮棤鍚戝浘 
 *         (2)婧愮偣s銆?nbsp;
 * 杈撳嚭錛?1)婧愮偣s鍒板悇鐐圭殑鏈鐭礬寰勯暱dist錛?nbsp;
 *         (2)婧愮偣s鍒板悇鐐圭殑鏈鐭礬寰刾rev銆?br> * 緇撴瀯: 鍥緂鐢ㄩ偦鎺ョ煩闃佃〃紺猴紝鏈鐭礬寰勯暱dist鐢ㄦ暟緇勮〃紺恒?nbsp;
 * 綆楁硶錛欴ijkstra綆楁硶  
 * 澶嶆潅搴︼細O(|V|^2) 
 
*/
 
#include 
<iostream>
#include 
<vector>
#include 
<list>
#include 
<iterator>
#include 
<algorithm>
#include 
<numeric>
#include 
<functional>
#include 
<climits>
using namespace std;

int n;                    // n : 欏剁偣涓暟 
vector<vector<int> > g; // g : 鍥?graph)(鐢ㄩ偦鎺ョ煩闃?adjacent matrix)琛ㄧず) 
int s;                    // s : 婧愮偣(source) 
vector<bool> known;        // known : 鍚勭偣鏄惁鐭ラ亾鏈鐭礬寰?nbsp;
vector<int> dist;        // dist : 婧愮偣s鍒板悇鐐圭殑鏈鐭礬寰勯暱 
vector<int> prev;        // prev : 鍚勭偣鏈鐭礬寰勭殑鍓嶄竴欏剁偣

void Dijkstra()            // 璐績綆楁硶(Greedy Algorithm) 
{
    known.assign(n, 
false);
    dist.assign(n, INT_MAX);
    prev.resize(n);            
// 鍒濆鍖杒nown銆乨ist銆乸rev銆?nbsp;
    dist[s] = 0;            // 鍒濆鍖栨簮鐐箂鍒拌嚜韜殑璺緞闀夸負0銆?nbsp;
    for (;;)
    
{
        
int min = INT_MAX, v = s;
        
for (int i = 0; i < n; ++i)
            
if (!known[i] && min > dist[i])
                min 
= dist[i], v = i;    // 瀵繪壘鏈煡鐨勬渶鐭礬寰勯暱鐨勯《鐐箆錛?nbsp;
        if (min == INT_MAX) break;        // 濡傛灉鎵句笉鍒幫紝閫鍑猴紱 
        known[v] = true;                // 濡傛灉鎵懼埌錛屽皢欏剁偣v璁句負宸茬煡錛?nbsp;
        for (int w = 0; w < n; ++w)        // 閬嶅巻鎵鏈塿鎸囧悜鐨勯《鐐箇錛?nbsp;
            if (!known[w] && g[v][w] < INT_MAX && dist[w] > dist[v] + g[v][w])
                dist[w] 
= dist[v] + g[v][w], prev[w] = v;    // 璋冩暣欏剁偣w鐨勬渶鐭礬寰勯暱dist鍜屾渶鐭礬寰勭殑鍓嶄竴欏剁偣 prev銆?nbsp;
    }

}


void Print_SP(int v)
{
     
if (v != s) Print_SP(prev[v]);
     cout 
<< v << " ";
}


int main()
{
    n 
= 7;
    g.assign(n, vector
<int>(n, INT_MAX));
    g[
0][1= 2; g[0][3= 1
    g[
1][3= 3; g[1][4= 10
    g[
2][0= 4; g[2][5= 5
    g[
3][2= 2; g[3][4= 2; g[3][5= 8; g[3][6= 4
    g[
4][6= 6
    g[
6][5= 1;
    
    s 
= 0;
    Dijkstra();
    
    copy(dist.begin(), dist.end(), ostream_iterator
<int>(cout, " ")); cout << endl;
    
for (int i = 0; i < n; ++i)
        
if(dist[i] != INT_MAX)
        
{
            cout 
<< s << "->" << i << "";
            Print_SP(i); 
            cout 
<< endl; 
        }

    
    system(
"pause");
    
return 0;
}



lzmagic 2009-04-09 10:45 鍙戣〃璇勮
]]>
USP 鏃犳潈鏈鐭礬寰勭畻娉?/title><link>http://www.shnenglu.com/lzmagic/archive/2009/04/09/79328.html</link><dc:creator>lzmagic</dc:creator><author>lzmagic</author><pubDate>Thu, 09 Apr 2009 02:44:00 GMT</pubDate><guid>http://www.shnenglu.com/lzmagic/archive/2009/04/09/79328.html</guid><wfw:comment>http://www.shnenglu.com/lzmagic/comments/79328.html</wfw:comment><comments>http://www.shnenglu.com/lzmagic/archive/2009/04/09/79328.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/lzmagic/comments/commentRss/79328.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/lzmagic/services/trackbacks/79328.html</trackback:ping><description><![CDATA[<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img id=Codehighlighter1_0_253_Open_Image onclick="this.style.display='none'; Codehighlighter1_0_253_Open_Text.style.display='none'; Codehighlighter1_0_253_Closed_Image.style.display='inline'; Codehighlighter1_0_253_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_0_253_Closed_Image onclick="this.style.display='none'; Codehighlighter1_0_253_Closed_Text.style.display='none'; Codehighlighter1_0_253_Open_Image.style.display='inline'; Codehighlighter1_0_253_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif"><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_0_253_Closed_Text>/**/</span><span id=Codehighlighter1_0_253_Open_Text><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">*<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"> * USP 鏃犳潈鏈鐭礬寰勭畻娉?Unweighted Shortest Path Algorithm)<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"> * 杈撳叆錛?1)鍥緂錛?nbsp;       // 鏈夊悜鍥炬垨鑰呮棤鍚戝浘 <br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"> *         (2)婧愮偣s銆?nbsp;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"> * 杈撳嚭錛?1)婧愮偣s鍒板悇鐐圭殑鏃犳潈鏈鐭礬寰勯暱dist(璺緞鐨勮竟鏁版渶灝?錛?nbsp;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"> *         (2)婧愮偣s鍒板悇鐐圭殑鏃犳潈鏈鐭礬寰刾rev銆?nbsp;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"> * 緇撴瀯: 鍥緂鐢ㄩ偦鎺ヨ〃琛ㄧず錛屾渶鐭礬寰勯暱dist鐢ㄦ暟緇勮〃紺恒?nbsp;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"> * 綆楁硶錛氬箍搴︿紭鍏堟悳绱?BFS)<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"> * 澶嶆潅搴︼細O(|E|+|V|)~O(|E|)  <br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"> </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"> <br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">list</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">queue</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">iterator</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">algorithm</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">numeric</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">functional</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">climits</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></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 align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n;                        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> n : 欏剁偣涓暟 </span><span style="COLOR: #008000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">list</span><span style="COLOR: #000000"><</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: #000000"> g;        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> g : 鍥?graph)(鐢ㄩ偦鎺ヨ〃(adjacent list)琛ㄧず) </span><span style="COLOR: #008000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> s;                        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> s : 婧愮偣(source)</span><span style="COLOR: #008000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"> dist;            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> dist : 婧愮偣s鍒板悇鐐逛箣闂寸殑璺濈</span><span style="COLOR: #008000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"> prev;            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> prev : 鍚勭偣鏈鐭礬寰勭殑鍓嶄竴欏剁偣鍙?nbsp;</span><span style="COLOR: #008000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> USP()        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 騫垮害浼樺厛鎼滅儲(BFS)</span><span style="COLOR: #008000"><br><img id=Codehighlighter1_691_1150_Open_Image onclick="this.style.display='none'; Codehighlighter1_691_1150_Open_Text.style.display='none'; Codehighlighter1_691_1150_Closed_Image.style.display='inline'; Codehighlighter1_691_1150_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_691_1150_Closed_Image onclick="this.style.display='none'; Codehighlighter1_691_1150_Closed_Text.style.display='none'; Codehighlighter1_691_1150_Open_Image.style.display='inline'; Codehighlighter1_691_1150_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_691_1150_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_691_1150_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    queue</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"> que;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    dist.assign(n, INT_MAX);                     </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 鍒濆鍖杁ist錛?nbsp;</span><span style="COLOR: #008000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #000000">    prev.resize(n);                                </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 鍒濆鍖杙rev銆?nbsp;</span><span style="COLOR: #008000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #000000">    dist[s] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; que.push(s);                    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> s鍒拌嚜韜窛紱諱負0錛宻鍏ラ槦銆?nbsp;</span><span style="COLOR: #008000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">que.empty())                         <br><img id=Codehighlighter1_870_1148_Open_Image onclick="this.style.display='none'; Codehighlighter1_870_1148_Open_Text.style.display='none'; Codehighlighter1_870_1148_Closed_Image.style.display='inline'; Codehighlighter1_870_1148_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_870_1148_Closed_Image onclick="this.style.display='none'; Codehighlighter1_870_1148_Closed_Text.style.display='none'; Codehighlighter1_870_1148_Open_Image.style.display='inline'; Codehighlighter1_870_1148_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif">    </span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_870_1148_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_870_1148_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">        </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> v </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> que.front(); que.pop();            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> v鍑洪槦錛?nbsp;</span><span style="COLOR: #008000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (list</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">::iterator it </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> g[v].begin(); it </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> g[v].end(); </span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">it) </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 閬嶅巻v鐩擱偦鐐?it錛?nbsp;</span><span style="COLOR: #008000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #000000">            </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (dist[</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">it] </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> INT_MAX)            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 濡傛灉*it鏈闂紝 </span><span style="COLOR: #008000"><br><img id=Codehighlighter1_1050_1145_Open_Image onclick="this.style.display='none'; Codehighlighter1_1050_1145_Open_Text.style.display='none'; Codehighlighter1_1050_1145_Closed_Image.style.display='inline'; Codehighlighter1_1050_1145_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1050_1145_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1050_1145_Closed_Text.style.display='none'; Codehighlighter1_1050_1145_Open_Image.style.display='inline'; Codehighlighter1_1050_1145_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif"></span><span style="COLOR: #000000">            </span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1050_1145_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_1050_1145_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">                dist[</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">it] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> dist[v] </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; prev[</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">it] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> v;    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 璋冩暣鐐?it錛?nbsp;</span><span style="COLOR: #008000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #000000">                que.push(</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">it);                    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> *it鍏ラ槦銆?nbsp;</span><span style="COLOR: #008000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"></span><span style="COLOR: #000000">            }</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">    }</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> Print_SP(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> v)<br><img id=Codehighlighter1_1174_1229_Open_Image onclick="this.style.display='none'; Codehighlighter1_1174_1229_Open_Text.style.display='none'; Codehighlighter1_1174_1229_Closed_Image.style.display='inline'; Codehighlighter1_1174_1229_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1174_1229_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1174_1229_Closed_Text.style.display='none'; Codehighlighter1_1174_1229_Open_Image.style.display='inline'; Codehighlighter1_1174_1229_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1174_1229_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_1174_1229_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">     </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (v </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> s) Print_SP(prev[v]);<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">     cout </span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000"> v </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">;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main()<br><img id=Codehighlighter1_1243_1809_Open_Image onclick="this.style.display='none'; Codehighlighter1_1243_1809_Open_Text.style.display='none'; Codehighlighter1_1243_1809_Closed_Image.style.display='inline'; Codehighlighter1_1243_1809_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1243_1809_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1243_1809_Closed_Text.style.display='none'; Codehighlighter1_1243_1809_Open_Image.style.display='inline'; Codehighlighter1_1243_1809_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1243_1809_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_1243_1809_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    n </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">7</span><span style="COLOR: #000000">;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    g.assign(n, list</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">()); <br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    g[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">].push_back(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">); g[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">].push_back(</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">); <br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    g[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">].push_back(</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">); g[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">].push_back(</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">); <br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    g[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">].push_back(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">); g[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">].push_back(</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">); <br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    g[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">].push_back(</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">); g[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">].push_back(</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">); g[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">].push_back(</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">); g[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">].push_back(</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">); <br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    g[</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">].push_back(</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">); <br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    g[</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">].push_back(</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">);<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    <br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    s </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    USP();<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">       <br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    copy(dist.begin(), dist.end(), ostream_iterator</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">(cout, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)); cout </span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000"> endl;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </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"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; i </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000"> n; </span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i)<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(dist[i] </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> INT_MAX)<br><img id=Codehighlighter1_1692_1775_Open_Image onclick="this.style.display='none'; Codehighlighter1_1692_1775_Open_Text.style.display='none'; Codehighlighter1_1692_1775_Closed_Image.style.display='inline'; Codehighlighter1_1692_1775_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1692_1775_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1692_1775_Closed_Text.style.display='none'; Codehighlighter1_1692_1775_Open_Image.style.display='inline'; Codehighlighter1_1692_1775_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif">        </span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1692_1775_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_1692_1775_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">            cout </span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000"> s </span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</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"> i </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">;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">            Print_SP(i); <br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">            cout </span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000"> endl; <br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">        }</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">        <br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span></div> <img src ="http://www.shnenglu.com/lzmagic/aggbug/79328.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/lzmagic/" target="_blank">lzmagic</a> 2009-04-09 10:44 <a href="http://www.shnenglu.com/lzmagic/archive/2009/04/09/79328.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Topsort 鎷撴墤鎺掑簭http://www.shnenglu.com/lzmagic/archive/2009/04/06/79066.htmllzmagiclzmagicMon, 06 Apr 2009 01:40:00 GMThttp://www.shnenglu.com/lzmagic/archive/2009/04/06/79066.htmlhttp://www.shnenglu.com/lzmagic/comments/79066.htmlhttp://www.shnenglu.com/lzmagic/archive/2009/04/06/79066.html#Feedback2http://www.shnenglu.com/lzmagic/comments/commentRss/79066.htmlhttp://www.shnenglu.com/lzmagic/services/trackbacks/79066.html/**
 * TOPSORT(綆鍗曠増) 鎷撴墤鎺掑簭(Topological Sort) 
 * 杈撳叆錛氭湁鍚戝浘g 
 * 杈撳嚭錛氭槸鍚﹀瓨鍦ㄦ嫇鎵戞帓搴忥紝濡傛灉瀛樺湪錛岃幏鍙栨嫇鎵戞帓搴忓簭鍒梥eq
 * 緇撴瀯錛氬浘g鐢ㄩ偦鎺ョ煩闃佃〃紺?br> * 綆楁硶錛氬箍搴︿紭鍏堟悳绱?BFS) 
 * 澶嶆潅搴︼細O(|V|^2) 
 
*/

 
#include 
<iostream>
#include 
<vector>
#include 
<queue>
#include 
<iterator>
#include 
<algorithm>
#include 
<numeric>
#include 
<climits>
using namespace std;

int n;                            // n 錛氶《鐐逛釜鏁?nbsp;
vector<vector<int> > g;           // g 錛氬浘(graph)(鐢ㄩ偦鎺ョ煩闃?adjacent matrix)琛ㄧず)  
vector<int> seq;                // seq 錛氭嫇鎵戝簭鍒?sequence) 

bool TopSort()
{
    vector
<int> inc(n, 0);     
    
for (int i = 0; i < n; ++i)
        
for (int j = 0; j < n; ++j)
             
if (g[i][j] < INT_MAX) ++inc[j]; // 璁$畻姣忎釜欏剁偣鐨勫叆搴︼紝 
    queue<int> que;
    
for (int j = 0; j < n; ++j)
        
if (inc[j] == 0) que.push(j); // 濡傛灉欏剁偣鐨勫叆搴︿負0錛屽叆闃熴?/span>
    int seqc = 0;
    seq.resize(n);
    
while (!que.empty())     // 濡傛灉闃熷垪que闈炵┖錛?/span>
    {
        
int v = que.front(); que.pop();     
        seq[seqc
++= v;      // 欏剁偣v鍑洪槦錛屾斁鍏eq涓紝
        for (int w = 0; w < n; ++w)     // 閬嶅巻鎵鏈塿鎸囧悜鐨勯《鐐箇錛?/span>
            if (g[v][w] < INT_MAX)
                
if (--inc[w] == 0) que.push(w); // 璋冩暣w鐨勫叆搴︼紝濡傛灉w鐨勫叆搴︿負0錛屽叆闃熴?nbsp;
    }

    
return seqc == n; // 濡傛灉seq宸插鐞嗛《鐐規暟涓簄錛屽瓨鍦ㄦ嫇鎵戞帓搴忥紝鍚﹀垯瀛樺湪鍥炶礬銆?/span>
}


int main()
{
    n 
= 7;    
    g.assign(n, vector
<int>(n, INT_MAX));
    g[
0][1= 1, g[0][2= 1, g[0][3= 1;
    g[
1][3= 1, g[1][4= 1;
    g[
2][5= 1;
    g[
3][2= 1, g[3][5= 1, g[3][6= 1;
    g[
4][3= 1, g[4][6= 1;
    g[
6][5= 1;     

    
if (TopSort())
    
{
         copy(seq.begin(), seq.end(), ostream_iterator
<int>(cout, " "));
         cout 
<< endl;
    }

    
else
    
{
         cout 
<< "circles exist" << endl;
    }

    
    system(
"pause");
    
return 0;
}



lzmagic 2009-04-06 09:40 鍙戣〃璇勮
]]>
(姝e垯琛ㄨ揪寮?鏄惁鍖歸厤(瀛楃涓?http://www.shnenglu.com/lzmagic/archive/2009/04/04/78977.htmllzmagiclzmagicSat, 04 Apr 2009 14:58:00 GMThttp://www.shnenglu.com/lzmagic/archive/2009/04/04/78977.htmlhttp://www.shnenglu.com/lzmagic/comments/78977.htmlhttp://www.shnenglu.com/lzmagic/archive/2009/04/04/78977.html#Feedback2http://www.shnenglu.com/lzmagic/comments/commentRss/78977.htmlhttp://www.shnenglu.com/lzmagic/services/trackbacks/78977.html/**
 * IS_MATCHED
 * 杈撳叆錛?1)涓涓鍒欒〃杈懼紡錛氬甫鏈夋鍒欑鍙?*'銆?+'銆??'銆?.'(姝e垯絎﹀彿涓嶇浉閭?錛?nbsp;
 *          '*'錛氫換鎰忓涓換鎰忓瓧絎︼紱 
 *          '+'錛氳嚦灝?涓換鎰忓瓧絎︼紱 
 *          '?'錛?涓垨1涓換鎰忓瓧絎︼紱 
 *          '.'錛氭伆濂?涓換鎰忓瓧絎︺?nbsp;                                                                
 *       (2)涓涓瓧絎︿覆銆?nbsp;
 * 杈撳嚭錛氳姝e垯琛ㄨ揪寮忔槸鍚﹀尮閰嶈瀛楃銆?nbsp;
 
*/

#include 
<iostream>
#include 
<string>
#include 
<algorithm>
using namespace std;

bool Is_Matched(string &reg, string &str)
{
     
bool is_asterisk, is_plus, is_question, is_dot, is_ok(true);
     
string substr;
     
string::iterator reg_it(reg.begin()), str_it(str.begin()), str_it2;
     
while (is_ok && reg_it != reg.end())
     
{
         
// 鍒嗙姝e垯絎﹀彿緇檌s_asterisk銆乮s_plus銆乮s_question銆乮s_dot銆?nbsp;
         is_asterisk = *reg_it == '*';
         is_plus     
= *reg_it == '+';
         is_question 
= *reg_it == '?';
         is_dot      
= *reg_it == '.';
         
if ( is_asterisk || is_plus || is_question || is_dot) ++reg_it;
         
// 鍒嗙瀛愬瓧絎︿覆緇檚ubstr銆?nbsp;
         substr.clear();
         
for (reg_it = reg_it; reg_it != reg.end()
                           
&& *reg_it != '*'
                           
&& *reg_it != '+'
                           
&& *reg_it != '?'
                           
&& *reg_it != '.'++reg_it)// 璋冩暣reg_it銆?nbsp;
             substr.push_back(*reg_it);
         
// 鍖歸厤瀛愬瓧絎︿覆錛歴ubstr絀猴紝str_it2=>end()錛屽惁鍒檚tr_it2=>鍖歸厤鐐規垨end()銆?nbsp;
         if (substr.empty()) str_it2 = str.end();
         
else str_it2 = search(str_it, str.end(), substr.begin(), substr.end());
         
// 鏄惁鍖歸厤姝e垯絎﹀彿錛歩s_asterisk涓嶅仛鍒ゆ柇銆?nbsp;
         if (is_plus     && str_it ==  str_it2  
          
|| is_question && str_it != str_it2 && str_it != str_it2 - 1
          
|| is_dot      && str_it != str_it2 - 1) is_ok = false;
         
// 鏄惁鍖歸厤瀛愬瓧絎︿覆銆?nbsp;
         if (!substr.empty() && str_it2 == str.end()) is_ok = false;
         
else str_it = str_it2 + substr.size();       // 璋冩暣str_it銆?nbsp;
     }

     
// 鍖歸厤鎴愬姛錛歩s_ok涓簍rue錛宺eg_it鍒拌揪reg.end()錛宻tr_it鍒拌揪str.end()銆?nbsp;
     return is_ok && reg_it == reg.end() && str_it == str.end();
}


int main () 
{
    
string reg, str; // input : *l?m.g+ lzmagic ?zm lzmagic
    while (cin >> reg >> str)
    
{
          
if (Is_Matched(reg, str)) cout << "match" << endl;
          
else cout << "dismatch" << endl;
    }

    
    system(
"pause");
    
return 0;
}



lzmagic 2009-04-04 22:58 鍙戣〃璇勮
]]>
Quicksort 蹇熸帓搴?/title><link>http://www.shnenglu.com/lzmagic/archive/2009/04/03/78774.html</link><dc:creator>lzmagic</dc:creator><author>lzmagic</author><pubDate>Fri, 03 Apr 2009 01:53:00 GMT</pubDate><guid>http://www.shnenglu.com/lzmagic/archive/2009/04/03/78774.html</guid><wfw:comment>http://www.shnenglu.com/lzmagic/comments/78774.html</wfw:comment><comments>http://www.shnenglu.com/lzmagic/archive/2009/04/03/78774.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.shnenglu.com/lzmagic/comments/commentRss/78774.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/lzmagic/services/trackbacks/78774.html</trackback:ping><description><![CDATA[<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img id=Codehighlighter1_0_151_Open_Image onclick="this.style.display='none'; Codehighlighter1_0_151_Open_Text.style.display='none'; Codehighlighter1_0_151_Closed_Image.style.display='inline'; Codehighlighter1_0_151_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_0_151_Closed_Image onclick="this.style.display='none'; Codehighlighter1_0_151_Closed_Text.style.display='none'; Codehighlighter1_0_151_Open_Image.style.display='inline'; Codehighlighter1_0_151_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif"><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_0_151_Closed_Text>/**/</span><span id=Codehighlighter1_0_151_Open_Text><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">*<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"> * QUICKSORT : sort<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"> *        void sort(iterator beg, iterator end);<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"> *        void sort(iterator beg, iterator end, compare cmp);   <algorithm><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"> </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">iterator</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">algorithm</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">numeric</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></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 align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> Partition(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">a, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> lhs, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> rhs)<br><img id=Codehighlighter1_295_481_Open_Image onclick="this.style.display='none'; Codehighlighter1_295_481_Open_Text.style.display='none'; Codehighlighter1_295_481_Closed_Image.style.display='inline'; Codehighlighter1_295_481_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_295_481_Closed_Image onclick="this.style.display='none'; Codehighlighter1_295_481_Closed_Text.style.display='none'; Codehighlighter1_295_481_Open_Image.style.display='inline'; Codehighlighter1_295_481_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_295_481_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_295_481_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">       </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> key </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> a[rhs];<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">       </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> lhs </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">       </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> j </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> lhs; j </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000"> rhs; </span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">j)<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">             </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (a[j] </span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000"> key) swap(a[</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i], a[j]);<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">       swap(a[</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i], a[rhs]);<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">       </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> i;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> QuickSort(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">a, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> lhs, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> rhs)<br><img id=Codehighlighter1_525_693_Open_Image onclick="this.style.display='none'; Codehighlighter1_525_693_Open_Text.style.display='none'; Codehighlighter1_525_693_Closed_Image.style.display='inline'; Codehighlighter1_525_693_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_525_693_Closed_Image onclick="this.style.display='none'; Codehighlighter1_525_693_Closed_Text.style.display='none'; Codehighlighter1_525_693_Open_Image.style.display='inline'; Codehighlighter1_525_693_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_525_693_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_525_693_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">      </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (lhs </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000"> rhs)<br><img id=Codehighlighter1_554_691_Open_Image onclick="this.style.display='none'; Codehighlighter1_554_691_Open_Text.style.display='none'; Codehighlighter1_554_691_Closed_Image.style.display='inline'; Codehighlighter1_554_691_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_554_691_Closed_Image onclick="this.style.display='none'; Codehighlighter1_554_691_Closed_Text.style.display='none'; Codehighlighter1_554_691_Open_Image.style.display='inline'; Codehighlighter1_554_691_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif">      </span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_554_691_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_554_691_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">             </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> mid </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> Partition(a, lhs, rhs);<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">             QuickSort(a, lhs, mid </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">             QuickSort(a, mid </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">, rhs);<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">      }</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main()<br><img id=Codehighlighter1_707_1019_Open_Image onclick="this.style.display='none'; Codehighlighter1_707_1019_Open_Text.style.display='none'; Codehighlighter1_707_1019_Closed_Image.style.display='inline'; Codehighlighter1_707_1019_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_707_1019_Closed_Image onclick="this.style.display='none'; Codehighlighter1_707_1019_Closed_Text.style.display='none'; Codehighlighter1_707_1019_Open_Image.style.display='inline'; Codehighlighter1_707_1019_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_707_1019_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_707_1019_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> a[</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">];<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </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"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; i </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">; </span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i) a[i] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> i;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    random_shuffle(a, a </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">);<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    copy(a, a </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">, ostream_iterator</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">(cout, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)); cout </span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000"> endl </span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000"> endl;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    <br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    QuickSort(a, </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">99</span><span style="COLOR: #000000">);<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    copy(a, a </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">, ostream_iterator</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">(cout, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)); cout </span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000"> endl;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    <br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span></div> <img src ="http://www.shnenglu.com/lzmagic/aggbug/78774.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/lzmagic/" target="_blank">lzmagic</a> 2009-04-03 09:53 <a href="http://www.shnenglu.com/lzmagic/archive/2009/04/03/78774.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://www.shnenglu.com/" title="精品视频久久久久">精品视频久久久久</a> <div class="friend-links"> </div> </div> </footer> <a href="http://www.tuomao8.cn" target="_blank">国内精品久久久久久久涩爱</a>| <a href="http://www.sanling-group.com.cn" target="_blank">99精品久久久久久久婷婷</a>| <a href="http://www.114tmall.cn" target="_blank">久久99中文字幕久久</a>| <a href="http://www.knjmj.cn" target="_blank">国产精品99久久久久久www</a>| <a href="http://www.splh.net.cn" target="_blank">久久精品国产亚洲av瑜伽</a>| <a href="http://www.disidai.cn" target="_blank">久久精品综合网</a>| <a href="http://www.yixue114.cn" target="_blank">久久精品国产久精国产思思</a>| <a href="http://www.telaviv.com.cn" target="_blank">国产高潮国产高潮久久久91</a>| <a href="http://www.dmc-dz.cn" target="_blank">久久久久久精品成人免费图片</a>| <a href="http://www.licaidazhong.com.cn" target="_blank">精品无码久久久久久午夜</a>| <a href="http://www.vzts.cn" target="_blank">亚洲а∨天堂久久精品</a>| <a href="http://www.shensizxw.cn" target="_blank">久久国产精品成人片免费</a>| <a href="http://www.ilebo.cn" target="_blank">久久人人爽人人澡人人高潮AV</a>| <a href="http://www.qqhaobofangqi.cn" target="_blank">婷婷久久香蕉五月综合加勒比</a>| <a href="http://www.waygoing.com.cn" target="_blank">品成人欧美大片久久国产欧美</a>| <a href="http://www.ea52.cn" target="_blank">久久99国产精品尤物</a>| <a href="http://www.yadangxiawa.cn" target="_blank">色综合久久夜色精品国产</a>| <a href="http://www.mdg163.cn" target="_blank">99久久精品免费看国产</a>| <a href="http://www.12530downs.com.cn" target="_blank">久久国产色av免费看</a>| <a href="http://www.1758c.cn" target="_blank">久久久噜噜噜久久中文字幕色伊伊</a>| <a href="http://www.shaosang.cn" target="_blank">欧美熟妇另类久久久久久不卡</a>| <a href="http://www.izyph.cn" target="_blank">久久精品国产亚洲精品</a>| <a href="http://www.zg-ly.cn" target="_blank">中文字幕亚洲综合久久2</a>| <a href="http://www.686t5w.cn" target="_blank">奇米综合四色77777久久</a>| <a href="http://www.thelv.cn" target="_blank">久久精品亚洲AV久久久无码</a>| <a href="http://www.fragrancebeads.cn" target="_blank">精品久久久久久国产牛牛app</a>| <a href="http://www.16pk8.cn" target="_blank">久久精品国产亚洲av麻豆色欲</a>| <a href="http://www.niuav.cn" target="_blank">18岁日韩内射颜射午夜久久成人</a>| <a href="http://www.pqdaili.cn" target="_blank">久久噜噜久久久精品66</a>| <a href="http://www.tengfangwang.cn" target="_blank">久久久国产精品网站</a>| <a href="http://www.deiden.cn" target="_blank">国产午夜福利精品久久2021</a>| <a href="http://www.dygdgs.cn" target="_blank">亚洲国产精品久久久天堂 </a>| <a href="http://www.heqiaoluo.cn" target="_blank">久久久久久久波多野结衣高潮</a>| <a href="http://www.yizhangguan.cn" target="_blank">久久精品国产色蜜蜜麻豆</a>| <a href="http://www.520king.cn" target="_blank">久久国产精品久久</a>| <a href="http://www.mashar.cn" target="_blank">狠狠色婷婷综合天天久久丁香</a>| <a href="http://www.gdchengye.com.cn" target="_blank">亚洲精品tv久久久久久久久 </a>| <a href="http://www.cqmh.com.cn" target="_blank">99久久国语露脸精品国产</a>| <a href="http://www.ezchem.cn" target="_blank">久久妇女高潮几次MBA</a>| <a href="http://www.scstnysc.cn" target="_blank">欧美精品乱码99久久蜜桃</a>| <a href="http://www.2jg.com.cn" target="_blank">午夜精品久久久久久久无码</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>