锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久精品国产只有精品66 ,精品人妻伦九区久久AAA片69,亚洲国产成人精品无码久久久久久综合 http://www.shnenglu.com/rakerichard/archive/2010/04/04/111604.htmllee1rlee1rSun, 04 Apr 2010 11:18:00 GMThttp://www.shnenglu.com/rakerichard/archive/2010/04/04/111604.htmlhttp://www.shnenglu.com/rakerichard/comments/111604.htmlhttp://www.shnenglu.com/rakerichard/archive/2010/04/04/111604.html#Feedback2http://www.shnenglu.com/rakerichard/comments/commentRss/111604.htmlhttp://www.shnenglu.com/rakerichard/services/trackbacks/111604.html浠ヤ笅鏄垜鐨勪唬鐮侊紝浠ヤ笅浠g爜蹇呴』淇濊瘉杈撳叆鐨勬槸鍚堟硶鐨勮〃杈懼紡錛屾瘮濡備笉鑳藉嚭鐜?^0 mod b錛?br>
long exp_mod(long a,long n,long b)
{
    
long t;
    
if(n==0return 1%b;
    
if(n==1return a%b;
    t
=exp_mod(a,n/2,b);
    t
=t*t%b;
    
if((n&1)==1) t=t*a%b;
    
return t;
}




lee1r 2010-04-04 19:18 鍙戣〃璇勮
]]>
鏈灝忚垂鐢ㄦ渶澶ф祦綆楁硶http://www.shnenglu.com/rakerichard/archive/2010/04/01/111336.htmllee1rlee1rThu, 01 Apr 2010 15:04:00 GMThttp://www.shnenglu.com/rakerichard/archive/2010/04/01/111336.htmlhttp://www.shnenglu.com/rakerichard/comments/111336.htmlhttp://www.shnenglu.com/rakerichard/archive/2010/04/01/111336.html#Feedback0http://www.shnenglu.com/rakerichard/comments/commentRss/111336.htmlhttp://www.shnenglu.com/rakerichard/services/trackbacks/111336.html浠ヤ笅鏄垜鐨勪唬鐮侊紝浠呬緵鍙傝冿細
#include<stdio.h>
#define maxn 507
#define INF 200000007
FILE 
*fin=fopen("data.in","r"),*fout=fopen("data.out","w");
typedef 
struct
{
    
long count,front,rear,item[maxn];
}queue;
void Clear(queue &q)
{
    q.count
=0;q.front=0;q.rear=-1;
}
void Push(queue &q,long x)
{
    q.count
++;q.rear++;
    
if(q.rear>=maxn) q.rear=0;
    q.item[q.rear]
=x;
}
void Pop(queue &q,long &x)
{
    q.count
--;x=q.item[q.front];
    q.front
++;
    
if(q.front>=maxn) q.front=0;
}
bool Empty(queue &q)
{
    
return (q.count==0);
}

long n,m,cap[maxn][maxn],cost[maxn][maxn];
long s,t,minc,maxf,flow[maxn][maxn];
long min(long a,long b)
{
return (a<b?a:b);}
void input()
{
    fscanf(fin,
"%ld%ld",&n,&m);
    
for(long i=1;i<=n;i++)
      
for(long j=1;j<=n;j++)
      {
         cap[i][j]
=0;cost[i][j]=INF;
      }
    
for(long i=1;i<=m;i++)
    {
       
long a,b,c,d;
       fscanf(fin,
"%ld%ld%ld%ld",&a,&b,&c,&d);
       cap[a][b]
=c;cost[a][b]=d;
    }
}
void Mincost_Maxflow()
{
    
long tmp,d[maxn],father[maxn];
    
bool inq[maxn];
    queue q;Clear(q);
    s
=1;t=n;
    
for(long i=1;i<=n;i++)
      
for(long j=1;j<=n;j++)
        flow[i][j]
=0;
    minc
=0;maxf=0;
    
while(true)
    {
       
for(long i=1;i<=n;i++)
       {
          d[i]
=(i==s?0:INF);
          father[i]
=0;
          inq[i]
=false;
       }
       d[s]
=0;Push(q,s);inq[s]=true;
       
while(!Empty(q))
       {
          
long i;Pop(q,i);inq[i]=false;
          
for(long j=1;j<=n;j++)
            
if(cap[i][j]>flow[i][j]&&cost[i][j]<INF&&d[i]+cost[i][j]<d[j])
            {
               d[j]
=d[i]+cost[i][j];
               father[j]
=i;
               
if(!inq[j])
               {Push(q,j);inq[j]
=true;}
            }
       }
       
if(d[t]>=INF) break;
       tmp
=INF;
       
for(long i=t;i!=s;i=father[i]) tmp=min(tmp,cap[father[i]][i]-flow[father[i]][i]);
       
for(long i=t;i!=s;i=father[i])
       {
          flow[father[i]][i]
+=tmp;
          flow[i][father[i]]
-=tmp;
       }
       minc
+=tmp*d[t];
       maxf
+=tmp;
    }
}
void output()
{
    fprintf(fout,
"Mincost := %ld\nMaxflow := %ld\n",minc,maxf);
}
int main()
{
    input();
    Mincost_Maxflow();
    output();
return 0;
}




lee1r 2010-04-01 23:04 鍙戣〃璇勮
]]>
鏁扮粍妯℃嫙閾捐〃鎿嶄綔http://www.shnenglu.com/rakerichard/archive/2010/03/16/109854.htmllee1rlee1rTue, 16 Mar 2010 14:39:00 GMThttp://www.shnenglu.com/rakerichard/archive/2010/03/16/109854.htmlhttp://www.shnenglu.com/rakerichard/comments/109854.htmlhttp://www.shnenglu.com/rakerichard/archive/2010/03/16/109854.html#Feedback0http://www.shnenglu.com/rakerichard/comments/commentRss/109854.htmlhttp://www.shnenglu.com/rakerichard/services/trackbacks/109854.html浠ヤ笅鏄垜鐨勪唬鐮侊細
insert(a,b)錛氬湪閾捐〃涓間負b鐨勫厓绱犲墠闈㈡彃鍏錛屽鏋滄壘涓嶅埌b錛屽皢a鎻掑叆閾捐〃鏈錛?br>print()錛氶亶鍘嗘暣涓摼琛紝騫惰緭鍑恒?br>
#include<stdio.h>
#include
<string.h>
#define maxn 1007
long n,a[maxn],next[maxn];
void insert(long x,long y)
{
    
long p=0;
    n
++;a[n]=x;
    
while(next[p]&&a[next[p]]!=y)
      p
=next[p];
    next[n]
=next[p];
    next[p]
=n;
}
void print()
{
    
long p=next[0];
    
bool first=true;
    
while(p)
    {
       
if(first) first=false;
       
else printf(" ");
       printf(
"%ld",a[p]);
       p
=next[p];
    }
}
int main()
{
    freopen(
"data.in","r",stdin);
    freopen(
"data.out","w",stdout);
    
long m,a,b;
    
char cmd[maxn];
    n
=0;
    memset(next,
0,sizeof(next));
    scanf(
"%ld",&m);
    
while(m--)
    {
       scanf(
"%s",cmd);
       
if(cmd[0]=='I')
       {
          scanf(
"%ld%ld",&a,&b);
          insert(a,b);
       }
       
else
       {
          print();putchar(
'\n');
       }
    }
return 0;
}




lee1r 2010-03-16 22:39 鍙戣〃璇勮
]]>
Splay鏍戠殑鍩烘湰鎿嶄綔http://www.shnenglu.com/rakerichard/archive/2010/03/12/109577.htmllee1rlee1rFri, 12 Mar 2010 14:28:00 GMThttp://www.shnenglu.com/rakerichard/archive/2010/03/12/109577.htmlhttp://www.shnenglu.com/rakerichard/comments/109577.htmlhttp://www.shnenglu.com/rakerichard/archive/2010/03/12/109577.html#Feedback0http://www.shnenglu.com/rakerichard/comments/commentRss/109577.htmlhttp://www.shnenglu.com/rakerichard/services/trackbacks/109577.html浠ヤ笅鏄垜鐨凷play鏍戜唬鐮侊細
#include<stdio.h>
#define maxn 10007
typedef 
struct
{
    
long data,fa,ls,rs;
}Node;
Node splay[maxn];
long m,root;
long n;
void Zig(long node)
{
    
long t=splay[node].fa;
    splay[t].rs
=splay[node].ls;
    
if(splay[node].ls)
      splay[splay[node].ls].fa
=t;
    splay[node].fa
=splay[t].fa;
    splay[node].ls
=t;
    
if(splay[t].fa)
    {
       
if(t==splay[splay[t].fa].ls) splay[splay[t].fa].ls=node;
       
else splay[splay[t].fa].rs=node;
    }
    splay[t].fa
=node;
}
void Zag(long node)
{
    
long t=splay[node].fa;
    splay[t].ls
=splay[node].rs;
    
if(splay[node].rs)
      splay[splay[node].rs].fa
=t;
    splay[node].fa
=splay[t].fa;
    splay[node].rs
=t;
    
if(splay[t].fa)
    {
       
if(t==splay[splay[t].fa].ls) splay[splay[t].fa].ls=node;
       
else splay[splay[t].fa].rs=node;
    }
    splay[t].fa
=node;
}
void Splay(long node)
{
    
long t;
    
while(splay[node].fa)
    {
       t
=splay[node].fa;
       
if(splay[t].fa==0)
       {
          
if(node==splay[t].ls) Zag(node);
          
else Zig(node);
          
break;
       }
       
if(t==splay[splay[t].fa].ls)
       {
          
if(node==splay[t].ls)
          {Zag(t);Zag(node);}
          
else {Zig(node);Zag(node);}
       }
       
else
       {
          
if(node==splay[t].ls)
          {Zag(node);Zig(node);}
          
else {Zig(t);Zig(node);}
       }
    }
    root
=node;
}
void Insert(long x)
{
    
long p,q;
    m
++;
    splay[m].data
=x;
    splay[m].fa
=splay[m].ls=splay[m].rs=0;
    
if(root==0)
    {
       root
=m;return;
    }
    
for(p=root;p; )
    {
       q
=p;
       
if(x<=splay[p].data) p=splay[p].ls;
       
else p=splay[p].rs;
    }
    splay[m].fa
=q;
    
if(x<=splay[q].data) splay[q].ls=m;
    
else splay[q].rs=m;
    Splay(m);
}
int main()
{
    freopen(
"data.in","r",stdin);
    freopen(
"data.out","w",stdout);
    scanf(
"%ld",&n);
    m
=root=0;
    
for(long i=1;i<=n;i++)
      splay[i].data
=splay[i].fa=splay[i].ls=splay[i].rs=0;
    
for(long i=1;i<=n;i++)
    {
       
long t;
       scanf(
"%ld",&t);
       Insert(t);
    }
    Splay(
1);
    
for(long i=1;i<=n;i++)
    printf(
"No.%ld data.%ld fa.%ld ls.%ld rs.%ld\n",i,splay[i].data,splay[i].fa,splay[i].ls,splay[i].rs);
return 0;
}



lee1r 2010-03-12 22:28 鍙戣〃璇勮
]]>
Miller-Rabbin绱犳暟嫻嬭瘯http://www.shnenglu.com/rakerichard/archive/2010/02/20/108099.htmllee1rlee1rSat, 20 Feb 2010 08:02:00 GMThttp://www.shnenglu.com/rakerichard/archive/2010/02/20/108099.htmlhttp://www.shnenglu.com/rakerichard/comments/108099.htmlhttp://www.shnenglu.com/rakerichard/archive/2010/02/20/108099.html#Feedback0http://www.shnenglu.com/rakerichard/comments/commentRss/108099.htmlhttp://www.shnenglu.com/rakerichard/services/trackbacks/108099.html浠ヤ笅鏄垜鐨刴iller_rabbin绱犳暟嫻嬭瘯鐨勪唬鐮侊細
#include<stdio.h>
#include
<stdlib.h>
#include
<time.h>
#define maxTest 5
typedef 
long long int64;
int64 random(int64 n)
{
    
return (int64)((double)rand()/RAND_MAX*n+0.5);
}
int64 mod_exp(int64 a,int64 b,int64 n)
{
    
long ans;
    
if(b==1return a%n;
    ans
=mod_exp(a,b/2,n);
    
if(b%2==0return ans*ans%n;
    
else return ans*ans%n*a%n;
}
bool miller_rabbin(int64 n)
{
    
for(long i=1;i<=maxTest;i++)
    {
       
long a=random(n-2)+1;
       
if(mod_exp(a,n-1,n)!=1return false;
    }
    
return true;
}
int main()
{
    
/*
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
    //
*/
    srand(time(NULL));
    int64 n;
    
while(scanf("%I64d",&n)==1)
      
if(miller_rabbin(n))
        printf(
"True\n\n");
      
else printf("False\n\n");
return 0;
}



lee1r 2010-02-20 16:02 鍙戣〃璇勮
]]>
絎竴涓嚎孌墊爲紼嬪簭http://www.shnenglu.com/rakerichard/archive/2010/02/17/107961.htmllee1rlee1rWed, 17 Feb 2010 05:33:00 GMThttp://www.shnenglu.com/rakerichard/archive/2010/02/17/107961.htmlhttp://www.shnenglu.com/rakerichard/comments/107961.htmlhttp://www.shnenglu.com/rakerichard/archive/2010/02/17/107961.html#Feedback0http://www.shnenglu.com/rakerichard/comments/commentRss/107961.htmlhttp://www.shnenglu.com/rakerichard/services/trackbacks/107961.html鍔熻兘錛氬垱寤轟竴媯電嚎孌墊爲錛涚粰a[i]鍔犱笂涓涓鹼紱姹備竴涓尯闂寸殑鏈澶у箋?br>浠ヤ笅鏄垜鐨勪唬鐮侊細
/*
    Author >>  Lee1R
    Time >> 02,16,2010 23:37
//
*/

#include
<stdio.h>
const long maxn=10007;
typedef 
struct NODE
{
    
long a,b,sum;
    
long left,right;
}node;
long n,m,a[maxn];
node tree[maxn];
long tot;
void creat(long begin,long end)
{
    
long now,mid=(begin+end)/2;
    tot
++;now=tot;
    tree[now].a
=begin;tree[now].b=end;
    
if(end-begin<=1)
    {
       tree[now].left
=-1;
       tree[now].right
=-1;
       tree[now].sum
=a[begin]+a[end];
    }
    
else
    {
       tree[now].left
=tot+1;creat(begin,mid);
       tree[now].right
=tot+1;creat(mid,end);
       tree[now].sum
=tree[tree[now].left].sum+tree[tree[now].right].sum-a[mid];
    }
}
void add(long pos,long det,long node)
{
    
long begin=tree[node].a,end=tree[node].b,mid=(begin+end)/2;
    tree[node].sum
+=det;
    
if(end-begin==1return;
    
if(pos>=begin&&pos<=mid)
      add(pos,det,tree[node].left);
    
if(pos>=mid&&pos<=end)
      add(pos,det,tree[node].right);
}
long getsum(long begin,long end,long node)
{
    
long re=0,t=(tree[node].a+tree[node].b)/2;
    
if(tree[node].b-tree[node].a==1) re=tree[node].sum;
    
else
    {
       
if(end<=t)
         re
=getsum(begin,end,tree[node].left);
       
else if(begin>=t)
         re
=getsum(begin,end,tree[node].right);
       
else
         re
=getsum(begin,t,tree[node].left)+getsum(t,end,tree[node].right)-a[t];
    }
    
return re;
}
int main()
{
    
//*
    freopen("data.in","r",stdin);
    freopen(
"data.out","w",stdout);
    
//*/
    scanf("%ld",&n);
    
for(long i=1;i<=n;i++) scanf("%ld",&a[i]);
    tot
=0;creat(1,n);
    
//  Init
    scanf("%ld",&m);
    
for(long i=1;i<=m;i++)
    {
       
long t,b,c;
       scanf(
"%ld%ld%ld",&t,&b,&c);
       
switch(t)
       {
          
case 1:
               a[b]
+=c;
               add(b,c,
1);
               
break;
          
case 2:
               
if(b==c) printf("%ld\n",a[b]);
               
else printf("%ld\n",getsum(b,c,1));
               
break;
       }
    }
return 0;
}




lee1r 2010-02-17 13:33 鍙戣〃璇勮
]]>
鍚勯《鐐歸棿鐨勬渶鐭礬鈥斺擣loyed綆楁硶http://www.shnenglu.com/rakerichard/archive/2010/01/21/106190.htmllee1rlee1rThu, 21 Jan 2010 15:10:00 GMThttp://www.shnenglu.com/rakerichard/archive/2010/01/21/106190.htmlhttp://www.shnenglu.com/rakerichard/comments/106190.htmlhttp://www.shnenglu.com/rakerichard/archive/2010/01/21/106190.html#Feedback0http://www.shnenglu.com/rakerichard/comments/commentRss/106190.htmlhttp://www.shnenglu.com/rakerichard/services/trackbacks/106190.html
for(long k=1;k<=n;k++)
  
for(long i=1;i<=n;i++)
    
for(long j=1;j<=n;j++)
      
if(k!=i&&i!=j&&j!=k)
        d[i][j]
=min(d[i][j],d[i][k]+d[k][j])




lee1r 2010-01-21 23:10 鍙戣〃璇勮
]]>
鏈灝忕敓鎴愭爲鈥斺擪ruskal綆楁硶http://www.shnenglu.com/rakerichard/archive/2010/01/21/106189.htmllee1rlee1rThu, 21 Jan 2010 15:04:00 GMThttp://www.shnenglu.com/rakerichard/archive/2010/01/21/106189.htmlhttp://www.shnenglu.com/rakerichard/comments/106189.htmlhttp://www.shnenglu.com/rakerichard/archive/2010/01/21/106189.html#Feedback0http://www.shnenglu.com/rakerichard/comments/commentRss/106189.htmlhttp://www.shnenglu.com/rakerichard/services/trackbacks/106189.html
#include<stdio.h>
const long maxn=107,INF=10000007;
typedef 
struct
{
    
long u,v,w;
}edge;
long n,m,g[maxn][maxn],mst;
edge E[maxn
*maxn];
long f[maxn];
long Getf(long x)
{
    
if(f[x]==x) return x;
    f[x]
=Getf(f[x]);
    
return f[x];
}
bool Judge(long x,long y)
{
    
return (Getf(x)==Getf(y));
}
void Union(long x,long y)
{
    
long i=Getf(x),j=Getf(y);
    
if(i==j) return ;
    f[i]
=j;
}
void Qsort(edge *a,long begin,long end)
{
    
long i=begin,j=end,mid=a[(begin+end)/2].w;
    edge t;
    
do{
         
while(a[i].w<mid) i++;
         
while(a[j].w>mid) j--;
         
if(i<=j)
         {
            t
=a[i];a[i]=a[j];a[j]=t;
            i
++;j--;
         }
    }
while(i<=j);
    
if(begin<j) Qsort(a,begin,j);
    
if(i<end)   Qsort(a,i,end);
}
int main()
{
    freopen(
"data.in","r",stdin);
    freopen(
"data.out","w",stdout);
    scanf(
"%ld%ld",&n,&m);
    
for(long i=1;i<=n;i++)
      
for(long j=1;j<=n;j++)
        g[i][j]
=INF;
    
for(long i=1;i<=m;i++)
      scanf(
"%ld%ld%ld",&E[i].u,&E[i].v,&E[i].w);
    
//  Read In
    Qsort(E,1,m);
    
//  Qsort
    for(long i=1;i<=n;i++) f[i]=i;
    
//  Init
    mst=0;
    
long i=0,j=1;
    
while(i<n-1)
    {
       
long a=E[j].u,b=E[j].v;
       
if(!Judge(a,b))
       {
          mst
+=E[j].w;
          Union(a,b);
          i
++;
       }
       j
++;
    }
    printf(
"%ld\n",mst);
return 0;
}




lee1r 2010-01-21 23:04 鍙戣〃璇勮
]]>
闃熷垪鐨勫父鐢ㄦ搷浣滃嚱鏁?/title><link>http://www.shnenglu.com/rakerichard/archive/2010/01/21/106188.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Thu, 21 Jan 2010 14:44:00 GMT</pubDate><guid>http://www.shnenglu.com/rakerichard/archive/2010/01/21/106188.html</guid><wfw:comment>http://www.shnenglu.com/rakerichard/comments/106188.html</wfw:comment><comments>http://www.shnenglu.com/rakerichard/archive/2010/01/21/106188.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/rakerichard/comments/commentRss/106188.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/rakerichard/services/trackbacks/106188.html</trackback:ping><description><![CDATA[浠ヤ笅鏄垜鐨勪唬鐮侊細<br> <div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #0000ff;">const</span><span style="color: #000000;"> </span><span style="color: #0000ff;">long</span><span style="color: #000000;"> maxn</span><span style="color: #000000;">=</span><span style="color: #000000;">1007</span><span style="color: #000000;">;<br>typedef </span><span style="color: #0000ff;">struct</span><span style="color: #000000;"><br>{<br>    </span><span style="color: #0000ff;">long</span><span style="color: #000000;"> front,rear,count,item[maxn];<br>}queue;<br></span><span style="color: #0000ff;">void</span><span style="color: #000000;"> clear(queue </span><span style="color: #000000;">&</span><span style="color: #000000;">q)<br>{<br>    q.count</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>    q.front</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>    q.rear</span><span style="color: #000000;">=-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br>}<br></span><span style="color: #0000ff;">bool</span><span style="color: #000000;"> empty(queue </span><span style="color: #000000;">&</span><span style="color: #000000;">q)<br>{<br>    </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> (q.count</span><span style="color: #000000;">==</span><span style="color: #000000;">0</span><span style="color: #000000;">);<br>}<br></span><span style="color: #0000ff;">void</span><span style="color: #000000;"> put(queue </span><span style="color: #000000;">&</span><span style="color: #000000;">q,</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> x)<br>{<br>    q.rear</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br>    q.item[q.rear]</span><span style="color: #000000;">=</span><span style="color: #000000;">x;<br>    q.count</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br>}<br></span><span style="color: #0000ff;">void</span><span style="color: #000000;"> </span><span style="color: #0000ff;">get</span><span style="color: #000000;">(queue </span><span style="color: #000000;">&</span><span style="color: #000000;">q,</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> </span><span style="color: #000000;">&</span><span style="color: #000000;">x)<br>{<br>    x</span><span style="color: #000000;">=</span><span style="color: #000000;">q.item[q.front];<br>    q.front</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br>    q.count</span><span style="color: #000000;">--</span><span style="color: #000000;">;<br>}</span></div> <br><br><img src ="http://www.shnenglu.com/rakerichard/aggbug/106188.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/rakerichard/" target="_blank">lee1r</a> 2010-01-21 22:44 <a href="http://www.shnenglu.com/rakerichard/archive/2010/01/21/106188.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鏍堢殑甯哥敤鎿嶄綔鍑芥暟http://www.shnenglu.com/rakerichard/archive/2010/01/21/106187.htmllee1rlee1rThu, 21 Jan 2010 14:39:00 GMThttp://www.shnenglu.com/rakerichard/archive/2010/01/21/106187.htmlhttp://www.shnenglu.com/rakerichard/comments/106187.htmlhttp://www.shnenglu.com/rakerichard/archive/2010/01/21/106187.html#Feedback0http://www.shnenglu.com/rakerichard/comments/commentRss/106187.htmlhttp://www.shnenglu.com/rakerichard/services/trackbacks/106187.html
#include<stdio.h>
const long maxn=1007;
typedef 
struct
{
    
long top,count,item[maxn];
}stack;
void clear(stack &q)
{
    q.count
=0;
    q.top
=-1;
}
bool empty(stack &q)
{
    
return (q.count==0);
}
void push(stack &q,long x)
{
    q.top
++;
    q.item[q.top]
=x;
    q.count
++;
}
void pop(stack &q,long &x)
{
    x
=q.item[q.top];
    q.top
--;
    q.count
--;
}
int main()
{
    stack s;clear(s);
    
for(long i=1;i<=10;i++) push(s,i);
    
while(!empty(s))
    {
       
long x;
       pop(s,x);
       printf(
"%ld\n",x);
    }
    getchar();
return 0;
}




lee1r 2010-01-21 22:39 鍙戣〃璇勮
]]>
澧炲箍璺畻娉曗斺擡dmonds-Karp綆楁硶http://www.shnenglu.com/rakerichard/archive/2010/01/20/106087.htmllee1rlee1rWed, 20 Jan 2010 13:58:00 GMThttp://www.shnenglu.com/rakerichard/archive/2010/01/20/106087.htmlhttp://www.shnenglu.com/rakerichard/comments/106087.htmlhttp://www.shnenglu.com/rakerichard/archive/2010/01/20/106087.html#Feedback0http://www.shnenglu.com/rakerichard/comments/commentRss/106087.htmlhttp://www.shnenglu.com/rakerichard/services/trackbacks/106087.html浠ヤ笅鏄垜鐨勪唬鐮侊細
#include<stdio.h>
const long maxn=107,INF=2000007;
typedef 
struct
{
    
long front,rear,count,item[maxn];
}queue;
void clear(queue &q)
{
    q.count
=0;
    q.front
=0;
    q.rear
=-1;
}
bool empty(queue &q)
{
    
return (q.count==0);
}
void push(queue &q,long x)
{
    q.rear
++;
    q.item[q.rear]
=x;
    q.count
++;
}
void pop(queue &q,long &x)
{
    x
=q.item[q.front];
    q.front
++;
    q.count
--;
}
//  Queue

long n,m,cap[maxn][maxn],flow[maxn][maxn];
long s,t,fmax;

long min(long a,long b)
{
    
return (a<b?a:b);
}
void read()
{
    scanf(
"%ld%ld",&n,&m);
    s
=1;t=n;
    
for(long i=1;i<=n;i++)
      
for(long j=1;j<=n;j++)
        cap[i][j]
=0;
    
for(long i=1;i<=m;i++)
    {
       
long a,b,w;
       scanf(
"%ld%ld%ld",&a,&b,&w);
       cap[a][b]
=w;
    }
}
void EK()
{
    
long tmp[maxn],father[maxn];
    queue q;clear(q);
    
for(long i=1;i<=n;i++)
      
for(long j=1;j<=n;j++)
        flow[i][j]
=0;
    fmax
=0;
    
while(true)
    {
       
for(long i=1;i<=n;i++) tmp[i]=father[i]=0;
       tmp[s]
=INF;
       push(q,s);
       
while(!empty(q))
       {
          
long i;
          pop(q,i);
          
for(long j=1;j<=n;j++)
            
if(!tmp[j]&&cap[i][j]>flow[i][j])
            {
               tmp[j]
=min(tmp[i],cap[i][j]-flow[i][j]);
               father[j]
=i;
               push(q,j);
            }
       }
       
if(tmp[t]==0break;
       
for(long i=t;i!=s;i=father[i])
       {
          flow[father[i]][i]
+=tmp[t];
          flow[i][father[i]]
-=tmp[t];
       }
       fmax
+=tmp[t];
    }
    printf(
"%ld\n",fmax);
}
int main()
{
    freopen(
"data.in","r",stdin);
    freopen(
"data.out","w",stdout);
    read();
    EK();
return 0;
}


lee1r 2010-01-20 21:58 鍙戣〃璇勮
]]>
浜屽垎鏌ユ壘鍙婃嫇灞?/title><link>http://www.shnenglu.com/rakerichard/archive/2010/01/10/105324.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Sun, 10 Jan 2010 06:05:00 GMT</pubDate><guid>http://www.shnenglu.com/rakerichard/archive/2010/01/10/105324.html</guid><wfw:comment>http://www.shnenglu.com/rakerichard/comments/105324.html</wfw:comment><comments>http://www.shnenglu.com/rakerichard/archive/2010/01/10/105324.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/rakerichard/comments/commentRss/105324.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/rakerichard/services/trackbacks/105324.html</trackback:ping><description><![CDATA[bsearch()鍔熻兘錛氬湪鏈夊簭鏁扮粍a鐨刐begin,end)鍖洪棿涓煡鎵炬暟瀛梮錛屽鏋滄壘涓嶅埌錛岃繑鍥?錛?br>low_search()鍔熻兘錛氬湪鏈夊簭鏁扮粍a鐨刐begin,end)鍖洪棿涓彃鍏ヤ竴涓暟瀛梮錛寈灝介噺鍚戝墠鎻掑叆錛岃繑鍥瀤搴旇鎻掑叆鐨勪綅緗紱<br>high_search()鍔熻兘錛氬湪鏈夊簭鏁扮粍a鐨刐begin,end)鍖洪棿涓彃鍏ヤ竴涓暟瀛梮錛寈灝介噺鍚戝悗鎻掑叆錛岃繑鍥瀤搴旇鎻掑叆鐨勪綅緗?br>浠ヤ笅鏄垜鐨勪唬鐮侊細<br> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000;">#include</span><span style="color: #000000;"><</span><span style="color: #000000;">stdio.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br></span><span style="color: #0000ff;">long</span><span style="color: #000000;"> bsearch(</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">a,</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> begin,</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> end,</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> x)<br>{</span><span style="color: #008000;">//</span><span style="color: #008000;">  [begin,end)</span><span style="color: #008000;"><br></span><span style="color: #000000;">    </span><span style="color: #0000ff;">long</span><span style="color: #000000;"> mid;<br>    </span><span style="color: #0000ff;">while</span><span style="color: #000000;">(begin</span><span style="color: #000000;"><</span><span style="color: #000000;">end)<br>    {<br>       mid</span><span style="color: #000000;">=</span><span style="color: #000000;">(begin</span><span style="color: #000000;">+</span><span style="color: #000000;">end)</span><span style="color: #000000;">/</span><span style="color: #000000;">2</span><span style="color: #000000;">;<br>       </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(a[mid]</span><span style="color: #000000;">==</span><span style="color: #000000;">x) </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> mid;<br>       </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(a[mid]</span><span style="color: #000000;">></span><span style="color: #000000;">x) end</span><span style="color: #000000;">=</span><span style="color: #000000;">mid;<br>       </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> begin</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>    }<br>    </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>}<br></span><span style="color: #0000ff;">long</span><span style="color: #000000;"> low_search(</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">a,</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> begin,</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> end,</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> x)<br>{<br>    </span><span style="color: #0000ff;">long</span><span style="color: #000000;"> mid;<br>    </span><span style="color: #0000ff;">while</span><span style="color: #000000;">(begin</span><span style="color: #000000;"><</span><span style="color: #000000;">end)<br>    {<br>       mid</span><span style="color: #000000;">=</span><span style="color: #000000;">(begin</span><span style="color: #000000;">+</span><span style="color: #000000;">end)</span><span style="color: #000000;">/</span><span style="color: #000000;">2</span><span style="color: #000000;">;<br>       </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(a[mid]</span><span style="color: #000000;">>=</span><span style="color: #000000;">x) end</span><span style="color: #000000;">=</span><span style="color: #000000;">mid;<br>       </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> begin</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>    }<br>    </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> begin;<br>}<br></span><span style="color: #0000ff;">long</span><span style="color: #000000;"> high_search(</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">a,</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> begin,</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> end,</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> x)<br>{<br>    </span><span style="color: #0000ff;">long</span><span style="color: #000000;"> mid;<br>    </span><span style="color: #0000ff;">while</span><span style="color: #000000;">(begin</span><span style="color: #000000;"><</span><span style="color: #000000;">end)<br>    {<br>       mid</span><span style="color: #000000;">=</span><span style="color: #000000;">(begin</span><span style="color: #000000;">+</span><span style="color: #000000;">end)</span><span style="color: #000000;">/</span><span style="color: #000000;">2</span><span style="color: #000000;">;<br>       </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(a[mid]</span><span style="color: #000000;"><=</span><span style="color: #000000;">x) begin</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>       </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> end</span><span style="color: #000000;">=</span><span style="color: #000000;">mid;<br>    }<br>    </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> begin;<br>}<br></span><span style="color: #0000ff;">int</span><span style="color: #000000;"> main()<br>{<br>    </span><span style="color: #008000;">//</span><span style="color: #008000;">*</span><span style="color: #008000;"><br></span><span style="color: #000000;">    freopen(</span><span style="color: #000000;">"</span><span style="color: #000000;">data.in</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>    freopen(</span><span style="color: #000000;">"</span><span style="color: #000000;">data.out</span><span style="color: #000000;">"</span><span style="color: #000000;">,</span><span style="color: #000000;">"</span><span style="color: #000000;">w</span><span style="color: #000000;">"</span><span style="color: #000000;">,stdout);<br>    </span><span style="color: #008000;">//</span><span style="color: #008000;">*/</span><span style="color: #008000;"><br></span><span style="color: #000000;">    </span><span style="color: #0000ff;">const</span><span style="color: #000000;"> </span><span style="color: #0000ff;">long</span><span style="color: #000000;"> maxn</span><span style="color: #000000;">=</span><span style="color: #000000;">108</span><span style="color: #000000;">;<br>    </span><span style="color: #0000ff;">long</span><span style="color: #000000;"> n</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">,a[maxn];<br>    </span><span style="color: #0000ff;">while</span><span style="color: #000000;">(scanf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%ld</span><span style="color: #000000;">"</span><span style="color: #000000;">,</span><span style="color: #000000;">&</span><span style="color: #000000;">a[n</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">])</span><span style="color: #000000;">==</span><span style="color: #000000;">1</span><span style="color: #000000;">) n</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br>    <br></span><span style="color: #0000ff;">return</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>}<br></span></div> <br><br><img src ="http://www.shnenglu.com/rakerichard/aggbug/105324.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/rakerichard/" target="_blank">lee1r</a> 2010-01-10 14:05 <a href="http://www.shnenglu.com/rakerichard/archive/2010/01/10/105324.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>褰掑茍鎺掑簭涓庨嗗簭瀵?/title><link>http://www.shnenglu.com/rakerichard/archive/2010/01/09/105260.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Sat, 09 Jan 2010 10:26:00 GMT</pubDate><guid>http://www.shnenglu.com/rakerichard/archive/2010/01/09/105260.html</guid><wfw:comment>http://www.shnenglu.com/rakerichard/comments/105260.html</wfw:comment><comments>http://www.shnenglu.com/rakerichard/archive/2010/01/09/105260.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/rakerichard/comments/commentRss/105260.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/rakerichard/services/trackbacks/105260.html</trackback:ping><description><![CDATA[<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000;">#include</span><span style="color: #000000;"><</span><span style="color: #000000;">stdio.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br></span><span style="color: #0000ff;">void</span><span style="color: #000000;"> msort(</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">a,</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">t,</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> begin,</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> end)<br>{<br>    </span><span style="color: #0000ff;">long</span><span style="color: #000000;"> mid</span><span style="color: #000000;">=</span><span style="color: #000000;">(begin</span><span style="color: #000000;">+</span><span style="color: #000000;">end)</span><span style="color: #000000;">/</span><span style="color: #000000;">2</span><span style="color: #000000;">,p</span><span style="color: #000000;">=</span><span style="color: #000000;">begin,q</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;">,i</span><span style="color: #000000;">=</span><span style="color: #000000;">begin;<br>    </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(begin</span><span style="color: #000000;"><</span><span style="color: #000000;">end)<br>    {<br>       msort(a,t,begin,mid);<br>       msort(a,t,mid</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">,end);<br>       </span><span style="color: #0000ff;">while</span><span style="color: #000000;">(i</span><span style="color: #000000;"><=</span><span style="color: #000000;">end)<br>       {<br>          </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(q</span><span style="color: #000000;">></span><span style="color: #000000;">end</span><span style="color: #000000;">||</span><span style="color: #000000;">a[p]</span><span style="color: #000000;"><=</span><span style="color: #000000;">a[q]) t[i</span><span style="color: #000000;">++</span><span style="color: #000000;">]</span><span style="color: #000000;">=</span><span style="color: #000000;">a[p</span><span style="color: #000000;">++</span><span style="color: #000000;">];<br>          </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> t[i</span><span style="color: #000000;">++</span><span style="color: #000000;">]</span><span style="color: #000000;">=</span><span style="color: #000000;">a[q</span><span style="color: #000000;">++</span><span style="color: #000000;">];<br>       }<br>       </span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> i</span><span style="color: #000000;">=</span><span style="color: #000000;">begin;i</span><span style="color: #000000;"><=</span><span style="color: #000000;">end;i</span><span style="color: #000000;">++</span><span style="color: #000000;">) a[i]</span><span style="color: #000000;">=</span><span style="color: #000000;">t[i];<br>    }<br>}<br></span><span style="color: #0000ff;">int</span><span style="color: #000000;"> main()<br>{<br>    </span><span style="color: #008000;">//</span><span style="color: #008000;">*</span><span style="color: #008000;"><br></span><span style="color: #000000;">    freopen(</span><span style="color: #000000;">"</span><span style="color: #000000;">data.in</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>    freopen(</span><span style="color: #000000;">"</span><span style="color: #000000;">data.out</span><span style="color: #000000;">"</span><span style="color: #000000;">,</span><span style="color: #000000;">"</span><span style="color: #000000;">w</span><span style="color: #000000;">"</span><span style="color: #000000;">,stdout);<br>    </span><span style="color: #008000;">//</span><span style="color: #008000;">*/</span><span style="color: #008000;"><br></span><span style="color: #000000;">    </span><span style="color: #0000ff;">const</span><span style="color: #000000;"> </span><span style="color: #0000ff;">long</span><span style="color: #000000;"> maxn</span><span style="color: #000000;">=</span><span style="color: #000000;">108</span><span style="color: #000000;">;<br>    </span><span style="color: #0000ff;">long</span><span style="color: #000000;"> n</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">,a[maxn],t[maxn];<br>    </span><span style="color: #0000ff;">bool</span><span style="color: #000000;"> first</span><span style="color: #000000;">=</span><span style="color: #0000ff;">true</span><span style="color: #000000;">;<br>    </span><span style="color: #0000ff;">while</span><span style="color: #000000;">(scanf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%ld</span><span style="color: #000000;">"</span><span style="color: #000000;">,</span><span style="color: #000000;">&</span><span style="color: #000000;">a[n</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">])</span><span style="color: #000000;">==</span><span style="color: #000000;">1</span><span style="color: #000000;">) n</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br>    </span><span style="color: #008000;">//</span><span style="color: #008000;">  Read In</span><span style="color: #008000;"><br></span><span style="color: #000000;">    msort(a,t,</span><span style="color: #000000;">1</span><span style="color: #000000;">,n);<br>    </span><span style="color: #008000;">//</span><span style="color: #008000;">  M_sort</span><span style="color: #008000;"><br></span><span style="color: #000000;">    </span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">long</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;"><=</span><span style="color: #000000;">n;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br>    {<br>       </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(first) first</span><span style="color: #000000;">=</span><span style="color: #0000ff;">false</span><span style="color: #000000;">;<br>       </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> printf(</span><span style="color: #000000;">"</span><span style="color: #000000;"> </span><span style="color: #000000;">"</span><span style="color: #000000;">);<br>       printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%ld</span><span style="color: #000000;">"</span><span style="color: #000000;">,a[i]);<br>    }<br>    putchar(</span><span style="color: #000000;">'</span><span style="color: #000000;">\n</span><span style="color: #000000;">'</span><span style="color: #000000;">);<br></span><span style="color: #0000ff;">return</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>}<br></span></div> 鍦ㄤ笂闈㈢殑褰掑茍鎺掑簭紼嬪簭鐨勫熀紜涓婏紝寰堝鏄撲慨鏀瑰緱鍑烘眰涓涓簭鍒楅嗗簭瀵逛釜鏁扮殑紼嬪簭銆?br>浠ヤ笅鏄垜鐨勪唬鐮侊紝鍙粰鍑哄嚱鏁幫紝main()涓庝笂闈㈢殑鍩烘湰鐩稿悓錛?br> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #0000ff;">long</span><span style="color: #000000;"> count(</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">a,</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">t,</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> begin,</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> end)<br>{<br>    </span><span style="color: #0000ff;">long</span><span style="color: #000000;"> mid</span><span style="color: #000000;">=</span><span style="color: #000000;">(begin</span><span style="color: #000000;">+</span><span style="color: #000000;">end)</span><span style="color: #000000;">/</span><span style="color: #000000;">2</span><span style="color: #000000;">,p</span><span style="color: #000000;">=</span><span style="color: #000000;">begin,q</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;">,i</span><span style="color: #000000;">=</span><span style="color: #000000;">begin,re</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>    </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(begin</span><span style="color: #000000;"><</span><span style="color: #000000;">end)<br>    {<br>       re</span><span style="color: #000000;">+=</span><span style="color: #000000;">count(a,t,begin,mid);<br>       re</span><span style="color: #000000;">+=</span><span style="color: #000000;">count(a,t,mid</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">,end);<br>       </span><span style="color: #0000ff;">while</span><span style="color: #000000;">(i</span><span style="color: #000000;"><=</span><span style="color: #000000;">end)<br>       {<br>          </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(q</span><span style="color: #000000;">></span><span style="color: #000000;">end</span><span style="color: #000000;">||</span><span style="color: #000000;">a[p]</span><span style="color: #000000;"><=</span><span style="color: #000000;">a[q]) t[i</span><span style="color: #000000;">++</span><span style="color: #000000;">]</span><span style="color: #000000;">=</span><span style="color: #000000;">a[p</span><span style="color: #000000;">++</span><span style="color: #000000;">];<br>          </span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br>          {<br>             t[i</span><span style="color: #000000;">++</span><span style="color: #000000;">]</span><span style="color: #000000;">=</span><span style="color: #000000;">a[q</span><span style="color: #000000;">++</span><span style="color: #000000;">];<br>             re</span><span style="color: #000000;">+=</span><span style="color: #000000;">mid</span><span style="color: #000000;">-</span><span style="color: #000000;">p</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br>          }<br>       }<br>       </span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">long</span><span style="color: #000000;"> i</span><span style="color: #000000;">=</span><span style="color: #000000;">begin;i</span><span style="color: #000000;"><=</span><span style="color: #000000;">end;i</span><span style="color: #000000;">++</span><span style="color: #000000;">) a[i]</span><span style="color: #000000;">=</span><span style="color: #000000;">t[i];<br>    }<br>    </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> re;<br>}</span></div> <br> <img src ="http://www.shnenglu.com/rakerichard/aggbug/105260.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/rakerichard/" target="_blank">lee1r</a> 2010-01-09 18:26 <a href="http://www.shnenglu.com/rakerichard/archive/2010/01/09/105260.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>瀵逛簬09 NOIphttp://www.shnenglu.com/rakerichard/archive/2010/01/06/104949.htmllee1rlee1rWed, 06 Jan 2010 10:28:00 GMThttp://www.shnenglu.com/rakerichard/archive/2010/01/06/104949.htmlhttp://www.shnenglu.com/rakerichard/comments/104949.htmlhttp://www.shnenglu.com/rakerichard/archive/2010/01/06/104949.html#Feedback0http://www.shnenglu.com/rakerichard/comments/commentRss/104949.htmlhttp://www.shnenglu.com/rakerichard/services/trackbacks/104949.html涓杞溂錛屼竴騫寸殑鏃墮棿鍙堣繃鍘諱簡錛屼竴騫翠竴嬈$殑NOIp鍙堣鍒頒簡銆傜粡榪囦竴騫寸殑瀛︿範錛屾劅瑙夎嚜宸辨瘮鍘熸潵榪涙浜嗚澶氥傚湪09NOIp涓鑷繁鎻愬嚭鍑犵偣瑕佹眰鍜屾敞鎰忎簨欏廣?/span>

1銆?/span>鏃跺埢淇濇寔鍐烽潤鐨勫ご鑴戯紱

2銆?/span>涓嶈鏄粈涔堥鐩紙鍋氳繃鎴栨槸娌″仛榪囷紝姘撮鎴栭毦棰橈級錛岄兘瑕佷粩緇嗛槄璇婚鐩紱

3銆?/span>寮濮嬬紪鐮佷箣鍓嶏紝鍏堝啓鍑虹▼搴忓ぇ綰詫紝鍐欏嚭闇瑕佺紪鍐欑殑鍑芥暟錛?/span>

4銆?/span>灝介噺涓嶈浣跨敤鍏ㄥ眬鍙橀噺錛堢壒鍒槸鐢ㄤ簬寰幆鐨勫彉閲忥級錛屼竴瀹氶伩鍏嶅彉閲忛噸鍚嶏紱

5銆?/span>鎼滅儲鏃訛紝璁捐鐨勫壀鏋濈瓥鐣ユ棤娉曞嚭瑙f椂錛屽湪淇濊瘉姝g‘鎬х殑鎯呭喌涓嬶紝閫傚綋鏀懼鎼滅儲鏉′歡錛?/span>

6銆?/span>鍔ㄦ佽鍒掓椂錛屼竴瀹氭椂鍒繪槑紜姸鎬佺殑瀹氫箟錛岀‘瀹氳竟鐣屾潯浠訛紱

7銆?/span>妯℃嫙鏃訛紝鐞嗘竻閫昏緫鍏崇郴錛?/span>

8銆佸湪涓嶅獎鍝嶇粨鏋滅殑鏃跺欙紝鍑芥暟璋冪敤鍙互浣跨敤鍦板潃浼犻掞紝鏁堢巼杈冮珮銆?/font>



lee1r 2010-01-06 18:28 鍙戣〃璇勮
]]>
鍏充簬鍫嗐?/title><link>http://www.shnenglu.com/rakerichard/archive/2010/01/06/104945.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Wed, 06 Jan 2010 10:23:00 GMT</pubDate><guid>http://www.shnenglu.com/rakerichard/archive/2010/01/06/104945.html</guid><wfw:comment>http://www.shnenglu.com/rakerichard/comments/104945.html</wfw:comment><comments>http://www.shnenglu.com/rakerichard/archive/2010/01/06/104945.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/rakerichard/comments/commentRss/104945.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/rakerichard/services/trackbacks/104945.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.shnenglu.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> heap_adjust(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> a[],</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> begin,</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> end)<br><img id=Codehighlighter1_47_263_Open_Image onclick="this.style.display='none'; Codehighlighter1_47_263_Open_Text.style.display='none'; Codehighlighter1_47_263_Closed_Image.style.display='inline'; Codehighlighter1_47_263_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_47_263_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_47_263_Closed_Text.style.display='none'; Codehighlighter1_47_263_Open_Image.style.display='inline'; Codehighlighter1_47_263_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_47_263_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.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_47_263_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> i,m;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    m</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[begin];<br><img src="http://www.shnenglu.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">begin</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">end;i</span><span style="COLOR: #000000">*=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_114_245_Open_Image onclick="this.style.display='none'; Codehighlighter1_114_245_Open_Text.style.display='none'; Codehighlighter1_114_245_Closed_Image.style.display='inline'; Codehighlighter1_114_245_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_114_245_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_114_245_Closed_Text.style.display='none'; Codehighlighter1_114_245_Open_Image.style.display='inline'; Codehighlighter1_114_245_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>    </span><span id=Codehighlighter1_114_245_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.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_114_245_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.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">end </span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000"> a[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">] )<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>          i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>       </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">( m</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">a[i] )<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>          </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>       a[begin]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[i];<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>       begin</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>    }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    a[begin]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">m;<br><img id=Codehighlighter1_268_281_Open_Image onclick="this.style.display='none'; Codehighlighter1_268_281_Open_Text.style.display='none'; Codehighlighter1_268_281_Closed_Image.style.display='inline'; Codehighlighter1_268_281_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_268_281_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_268_281_Closed_Text.style.display='none'; Codehighlighter1_268_281_Open_Image.style.display='inline'; Codehighlighter1_268_281_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>}</span></span><span style="COLOR: #000000">    </span><span id=Codehighlighter1_268_281_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id=Codehighlighter1_268_281_Open_Text><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">璋冩暣錛屼嬌涔嬫垚涓轟竴涓爢</span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span></div> <p><font face=瀹嬩綋 size=3>Ps錛?/font></p> <p><font face=瀹嬩綋 size=3>    1.瀵瑰爢鐨勮皟鏁翠粠欏惰嚦涓嬭繘琛屻?/font></p> <p><font face=瀹嬩綋 size=3>    2.鍒涘緩涓涓柊鍫嗗簲璇ヤ粠鏈鍚庝竴涓彾緇撶偣鐨勭埗緇撶偣寮濮嬮愭鍚戜笂璋冩暣銆?/font></p> <p><font face=瀹嬩綋 size=3>    3.瀵筯eap[s..m]鑳藉璋冩暣鎴愬姛錛岄渶瑕乭eap[s+1..m]涓ユ牸婊¤凍鍫嗙殑瀹氫箟銆?/font></p> <img src ="http://www.shnenglu.com/rakerichard/aggbug/104945.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/rakerichard/" target="_blank">lee1r</a> 2010-01-06 18:23 <a href="http://www.shnenglu.com/rakerichard/archive/2010/01/06/104945.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>閾捐〃甯哥敤鎿嶄綔http://www.shnenglu.com/rakerichard/archive/2010/01/06/104944.htmllee1rlee1rWed, 06 Jan 2010 10:22:00 GMThttp://www.shnenglu.com/rakerichard/archive/2010/01/06/104944.htmlhttp://www.shnenglu.com/rakerichard/comments/104944.htmlhttp://www.shnenglu.com/rakerichard/archive/2010/01/06/104944.html#Feedback0http://www.shnenglu.com/rakerichard/comments/commentRss/104944.htmlhttp://www.shnenglu.com/rakerichard/services/trackbacks/104944.html#include<stdio.h>
#include
<stdlib.h>
struct node
{
       
int data;
       
struct node *next;
}
;//緇撴瀯綾誨瀷鐨勮鏄?/span>

struct node *stack(struct node *head)
{
     
int i;
     
struct node *p;
     p 
= (struct node*)malloc(sizeof(struct node));
     p
->next = NULL;
     
for(i=0;i<10;i++)
       
{
         head 
= (struct node*)malloc(sizeof(struct node));
         p
->data = i;
         head
->next = p;
         p 
= head;;
       }

     
return (head);
}
//鏍?/span>

struct node *team(struct node *head)
{
     
int i;
     
struct node *tail,*p;
     head 
= (struct node*)malloc(sizeof(struct node));
     tail 
= head;
     
for(i=0;i<10;i++)
       
{
         p 
= (struct node*)malloc(sizeof(struct node));
         p
->data = i;
         tail
->next = p;
         tail 
= p;
       }

     tail
->next = NULL;
     
return (head);
}
//闃熷垪

void print_list(struct node *head)
{
     
struct node *p;
     p 
= head->next;
     printf(
"Begin");
     
while(p != NULL)
       
{
         printf(
"->%d",p->data);
         p 
= p->next;
       }

     printf(
"->End\n");
}
//閾捐〃杈撳嚭

void detele_x(struct node *head,int x)
{
     
struct node *p,*q;
     p 
= head;
     q 
= head->next;
     
while(q->data != x && q->next != NULL)
       
{ p = q; q = q->next; }
     
if(q->data == x)
       p
->next = q->next;
     free(q);
}
//鍒犻櫎鏁版嵁鍩熶負x鐨勭粨鐐?/span>

void add_x_y(struct node *head,int x,int y)
{
     
struct node *add_new,*p,*q;
     add_new 
= (struct node*)malloc(sizeof(struct node));
     add_new
->data = x;
     p 
= head;
     q 
= head->next;
     
while(q != NULL && q->data != y)
       
{ p = q; q = q->next; }
     p
->next = add_new;
     add_new
->next = q;
}
//鍦ㄦ暟鎹負y鐨勭粨鐐瑰墠鎻掑叆鏁版嵁鍩熶負x鐨勭粨鐐?br>

lee1r 2010-01-06 18:22 鍙戣〃璇勮
]]>
鍔ㄦ佽鍒掗殢璁?/title><link>http://www.shnenglu.com/rakerichard/archive/2010/01/06/104943.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Wed, 06 Jan 2010 10:20:00 GMT</pubDate><guid>http://www.shnenglu.com/rakerichard/archive/2010/01/06/104943.html</guid><wfw:comment>http://www.shnenglu.com/rakerichard/comments/104943.html</wfw:comment><comments>http://www.shnenglu.com/rakerichard/archive/2010/01/06/104943.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/rakerichard/comments/commentRss/104943.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/rakerichard/services/trackbacks/104943.html</trackback:ping><description><![CDATA[<p><font face=瀹嬩綋 size=3>//------------------------------------------------------------</font></p> <p><font face=瀹嬩綋 size=3>瀵逛簬鐜艦鐨勫姩鎬佽鍒掞紝</font></p> <p><font face=瀹嬩綋 size=3>鍙互鎶婃暟緇勪笅鏍囧鍒朵竴浠界劧鍚庤繘琛屽姩鎬佽鍒?/font></p> <p><font face=瀹嬩綋 size=3>//------------------------------------------------------------</font></p> <p><span><font face=瀹嬩綋 size=3>鍦ㄥ姩鎬佽鍒掔殑鍏蜂綋緙栫▼涓紝鍙兘璁稿鏃跺欏啓鍑轟簡姝g‘鐨勭姸鎬佽漿縐繪柟紼嬶紝浣嗙紪鍐欏悗鐨勭▼搴忓嵈寰椾笉鍒版紜В錛岃繖寰堟湁鍙兘鏄洜涓哄姩鎬佽鍒掔殑寰幆鐨勯『閫嗗簭錛屾垨鑰呭驚鐜殑鍐呭灞傚嚭鐜頒簡閿欒銆?/font></span></p> <p><span><font face=瀹嬩綋 size=3>鍦ㄨ繖閲屽拷鐣ュ叾浠栬祫鏂欎腑鐨勭悊璁虹煡璇嗭紝鑰屽叿浣撹鍔ㄦ佽鍒掓槸濡備綍瀹炵幇鐨勩?/font></span></p> <p><font face=瀹嬩綋><font size=3><span>//<span> </span></span><span>鍦ㄨ繖閲岀殑緇欏嚭鐨勫叏閮ㄤ唬鐮侀兘娌℃湁緇忚繃璋冭瘯鑰岀洿鎺ュ啓鍑?/span></font></font></p> <p><font face=瀹嬩綋><font size=3><span>//<span> </span></span><span>濡傛灉鍑虹幇閿欒錛岃鎸囧嚭</span></font></font></p> <p><font face=瀹嬩綋><font size=3><span>浠?/span><span>01</span><span>鑳屽寘寮濮嬭璧楓?/span></font></font></p> <p><span><font face=瀹嬩綋 size=3>紼嶅井鎺屾彙鍔ㄦ佽鍒掔殑浜洪兘鍙互鐔熺粌鍦板啓鍑哄涓嬩唬鐮侊細</font></span></p> <p> </p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top><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"><=</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.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">v;j</span><span style="COLOR: #000000">>=</span><span style="COLOR: #000000">c[i];j</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top>    d[j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">max(d[j],d[j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">c[i]]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">w[i])錛?br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span></div> <p> </p> <p><span><font face=瀹嬩綋 size=3>涓鑸殑鍔ㄦ佽鍒掗兘鏄厛鏋氫婦鐘舵佸啀鏋氫婦鍐崇瓥錛屽彲鑳藉垵瀛﹁呬笉鏄庣櫧浠ヤ笂鐨勪唬鐮佹槸鎬庝箞鍥炰簨錛屽洜涓鴻繖鏄檷緇翠箣鍚庣殑鐘舵佽〃紺猴紝闄嶇淮涔嬪墠鐨勬槸錛?/font></span></p> <p><font face=瀹嬩綋><font size=3><span>d[i][j]=max(d[i-1][j],d[i-1][j-c[i]]+w[i])</span><span>錛?/span></font></font></p> <p><font face=瀹嬩綋><font size=3><span>涔嬫墍浠ュ彲浠ラ檷緇存槸鍥犱負錛氳瀵熺姸鎬佽漿縐繪柟紼嬶紝絎?/span><span>i</span><span>嬈$殑鍐崇瓥鍙笌絎?/span><span>i-1</span><span>嬈℃墍璁板綍鐨勭姸鎬佹湁鍏籌紝浜庢槸鎯籌紝鑳戒笉鑳芥湁涓縐嶆柟娉曞彧鐢ㄤ竴緇存暟緇勶紝灝卞彲浠ュ湪鐘舵佽漿縐昏兘澶熸紜繘琛岋紵絳旀鏄偗瀹氱殑錛岄偅灝辨槸絎簩灞備嬌鐢ㄩ嗗簭寰幆銆?/span></font></font></p> <p> </p> <p><font face=瀹嬩綋><font size=3><span>NOIp 2006 </span><span>閲戞槑鐨勯綆楁柟妗?/span></font></font></p> <p><span><font face=瀹嬩綋 size=3>鍏堝鐞嗕竴涓嬬粰鍑虹殑鐗╁搧錛屽垎鎴愯嫢騫茬粍錛岃漿鍖栦負鍒嗙粍鑳屽寘闂銆?/font></span></p> <p><span><font face=瀹嬩綋 size=3>鍐欏嚭鍒嗙粍鑳屽寘鐨勭姸鎬佽漿縐繪柟紼嬶細</font></span></p> <p><font face=瀹嬩綋><font size=3><span>d[k][j]=max(d[k-1][j],d[k-1][j-c[k][i]]+w[k][i])</span><span>錛?/span></font></font></p> <p><span><font face=瀹嬩綋 size=3>瀵逛簬鍒嗙粍鑳屽寘錛岀粰鍑哄涓嬩唬鐮侊細</font></span></p> <p><font face=瀹嬩綋><font size=3><span> </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.shnenglu.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> 鎵鏈夌粍k<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.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">V to </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> 鎵鏈夌墿鍝乮灞炰簬緇刱<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top>      d[j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">max(d[j],d[j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">c[k][i]]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">w[k][i])錛?br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span></div> <p></span></font></font> </p> <p><font face=瀹嬩綋><font size=3><span>//<span> </span></span><span>銆婅儗鍖呴棶棰樹節璁層嬩腑鐨勪唬鐮佷技涔庢湁鐐歸敊璇?/span></font></font></p> <p><font face=瀹嬩綋><font size=3><span>鍚屾牱錛屽厛瑙傚療鐘舵佽漿縐繪柟紼嬶紝榪樻槸鍙彇鍐充簬絎?/span><span>k-1</span><span>緇勮褰曠殑鐘舵侊紝鍙堣浣挎瘡緇勪腑鐗╁搧鍙変竴浠舵垨鑰呬竴浠墮兘涓嶉夈傝繖鏍峰氨紜畾浜嗗垎緇勮儗鍖呭彧鑳芥槸涓婇潰鐨勫驚鐜搴忥紝鍥犱負鍙湁榪欐牱鍦ㄧ</span><span>k</span><span>緇勫喅絳栫殑鏃跺欐墠鑳戒繚璇佷粠絎?/span><span>k-1</span><span>緇勭殑鐘舵佽漿縐昏屾潵錛涚畝鍗曞湴璇村氨鏄紝鍦ㄧ浜屽眰鍥哄畾浜嗗墠</span><span>k</span><span>緇勭墿鍝佸崰鐢ㄧ殑絀洪棿錛岄偅涔堟棤璁洪夋嫨鍝竴涓?/span><span>i</span><span>錛屾渶緇堣繖涓姸鎬侀兘鍙兘琚</span><span>k</span><span>緇勭殑涓涓墿鍝佸崰鐢紱璇曟兂濡傛灉鍍忋婅儗鍖呴棶棰樹節璁層嬩腑閭f牱鎶婄浜屽眰寰幆鍜岀涓夊眰寰幆棰犲掕繃鏉ワ紝閭d箞灝辨湁鍙兘絎?/span><span>k</span><span>灞傜殑鐘舵佺敱絎?/span><span>k</span><span>灞傜殑鐘舵佽漿縐昏屾潵錛屼粠鑰屼笉鑳戒繚璇佹渶澶氶夋嫨涓浠剁墿鍝併?/span></font></font></p> <p> </p> <p><span><font face=瀹嬩綋 size=3>Vijos GF</font></span></p> <p><span><font face=瀹嬩綋 size=3>浜岀淮璐圭敤鐨勮儗鍖呫?/font></span></p> <p><span><font face=瀹嬩綋 size=3>鐘舵佽漿縐繪柟紼嬬洿鎺ョ粰鍑哄涓嬶細</font></span></p> <p><font face=瀹嬩綋><font size=3><span>d[i][j][k]=max(d[i-1][j][k],d[i-1][j-c1[i]][k-c2[i]]+w[i])</span><span>錛?/span></font></font></p> <p><font face=瀹嬩綋><font size=3><span>鍚屾牱鍙互闄嶅埌浜岀淮錛屽洜涓烘槸姣忎釜</span><span>GF</span><span>鍙兘閫夋嫨涓嬈★紙棰樼洰涓ソ鍍忔病鏈夎繖涔堣錛屽緢涔呬箣鍓嶅仛鐨勪簡錛屼笉澶寰椾簡錛屼絾鏄幇瀹炵敓媧諱腑鐨勭粡楠屽憡璇夋垜浠瘡涓?/span><span>GF</span><span>鍙兘閫夋嫨涓嬈★級錛屾墍浠ュ湪寰幆鏋氫婦</span><span>j</span><span>鍜?/span><span>k</span><span>鐨勬椂鍊欒浣跨敤閫嗗簭銆?/span></font></font></p> <p> </p> <p><font face=瀹嬩綋><font size=3><span>Vijos </span><span>鎯呮晫</span></font></font></p> <p><span><font face=瀹嬩綋 size=3>褰撶劧鍙互鐞嗚В涓哄拰“閲戞槑鐨勯綆楁柟妗?#8221;涓鏍鳳紝鏄湁渚濊禆鍏崇郴鐨勮儗鍖呴棶棰橈紝浣嗘槸榪欓亾棰樺嵈鍦ㄦ暟鎹殑瑙勬ā涓婂憡璇夋垜浠敤閭g鏂規硶鏄笉鍙鐨勩傛洿濂界殑鍋氭硶鏄悳绱㈠拰鍔ㄦ佽鍒掔粨鍚堬紝姣忔鏋氫婦瓚呯駭鎯呮晫鍦ㄧ涓涓湀娑堢伃銆佺浜屼釜鏈堟秷鐏佺涓変釜鏈堟秷鐏紙鍗充笉娑堢伃錛夛紝鐒跺悗瀵瑰叾浣欐儏鏁岃繘琛屽姩鎬佽鍒掋?/font></span></p> <p><span><font face=瀹嬩綋 size=3>鐪佺暐鎼滅儲閮ㄥ垎錛岃岀潃閲嶈璇村姩鎬佽鍒掋?/font></span></p> <p><span><font face=瀹嬩綋 size=3>鐘舵佽漿縐繪柟紼嬶細</font></span></p> <p><font face=瀹嬩綋><font size=3><span>d[i][j][k]=max(d[i-1][j][k],d[i-1][j-c1[i]][k],d[i-1][j][k-c2[i]])</span><span>錛?/span></font></font></p> <p><font face=瀹嬩綋><font size=3><span>鐢變簬鏈夊彲鑳芥煇涓秴綰ф儏鏁屾病鏈夎娑堢伃錛岃屽湪鏋氫婦</span><span>i</span><span>鐨勬椂鍊欐灇涓句簡榪欎釜瓚呯駭鎯呮晫錛屽鏋滃湪榪欐椂鐩存帴鍒ゆ柇鍚?/span><span>continue</span><span>錛屽彲鑳介犳垚</span><span>d[i]</span><span>灞傜殑絀虹己錛屼互鑷充簬</span><span>d[i+1]</span><span>灞傜殑閿欒銆傛墍浠ュ湪澶勭悊榪欐牱鍙兘鍑虹幇鏌愪竴灞傚嚭鐜扮┖緙虹殑鎯呭喌鏃訛紝瑕佹妸絀虹己鐨勯偅涓灞傚叏閮ㄤ粠瀹冪殑涓婁竴灞傛妸鐘舵佺戶鎵夸笅鏉ワ紝浠ヤ繚璇佸悗鏉ョ殑鐘舵佽漿縐葷殑姝g‘銆?/span></font></font></p> <p> </p> <p><span><font face=瀹嬩綋 size=3>鎬葷粨涓涓嬨?/font></span></p> <p><span><font face=瀹嬩綋 size=3>瀵逛簬涓閬撻鐩啓鍑虹姸鎬佽漿縐繪柟紼嬩箣鍚庯紝紼嬪簭鐨勫疄鐜版湁鏃跺欐槸鏄捐屾槗瑙佺殑錛屼絾鏈夋椂鍊欏嵈鍙堥渶瑕佹濊冧竴鐣傝繖鏃跺欒繕鏄渶瑕佺珛瓚充簬鐘舵佽漿縐繪柟紼嬶紝鍙﹀榪樿鑰冭檻鍒伴鐩腑鐨勪竴浜涢檺鍒舵潯浠訛紝璁捐鍚堥傜殑寰幆欏洪嗗簭鍜屽唴澶栧眰銆?/font></span></p> <p><font face=瀹嬩綋 size=3>//------------------------------------------------------------</font></p> <img src ="http://www.shnenglu.com/rakerichard/aggbug/104943.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/rakerichard/" target="_blank">lee1r</a> 2010-01-06 18:20 <a href="http://www.shnenglu.com/rakerichard/archive/2010/01/06/104943.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>浼樺寲鐨凚ellman-Ford鈥斺擲PFAhttp://www.shnenglu.com/rakerichard/archive/2010/01/06/104942.htmllee1rlee1rWed, 06 Jan 2010 10:17:00 GMThttp://www.shnenglu.com/rakerichard/archive/2010/01/06/104942.htmlhttp://www.shnenglu.com/rakerichard/comments/104942.htmlhttp://www.shnenglu.com/rakerichard/archive/2010/01/06/104942.html#Feedback0http://www.shnenglu.com/rakerichard/comments/commentRss/104942.htmlhttp://www.shnenglu.com/rakerichard/services/trackbacks/104942.htmlSPFA鐨勫熀鏈濊礬鏄細鍙湁琚慨鏀硅繃鏈鐭礬鐨勯《鐐癸紝鎵嶆湁鍙兘瀵艱嚧淇敼涓庡畠閭繪帴鐨勯《鐐圭殑鏈鐭礬銆備簬鏄緢瀹規槗鎯沖埌鐢ㄤ竴涓槦鍒楃淮鎶ゃ?br>浠ヤ笅鏄垜鐨勪唬鐮侊細

#include<stdio.h>
#define min(a,b) (a<b?a:b)
const long maxn=507;
const long INF=100000007;
typedef 
struct
{
    
long front,rear,count,item[maxn];
}queue;
void clear(queue &q)
{
    q.count
=0;
    q.front
=0;
    q.rear
=-1;
}
bool empty(queue &q)
{
    
return (q.count==0);
}
void push(queue &q,long x)
{
    q.rear
++;
    q.item[q.rear]
=x;
    q.count
++;
}
long pop(queue &q)
{
    
long x=q.item[q.front];
    q.front
++;
    q.count
--;
    
return x;
}
//  Queue
typedef struct EDGE_NODE
{
    
long u,v,w;
    
struct EDGE_NODE *next;
}edge_node;
long n,m,d[maxn];
edge_node 
*a[maxn];
//  Var
void insert(long begin,long end,long weight)
{
    edge_node 
*p=new edge_node;
    p
->u=begin;p->v=end;p->w=weight;
    p
->next=a[begin]->next;
    a[begin]
->next=p;
}
bool bellman_ford(long s)
{
    
bool in[maxn];
    
long in_num[maxn];
    queue q;clear(q);
    edge_node 
*p;
    
for(long i=1;i<=n;i++)
    {
       d[i]
=(i==s?0:INF);
       
in[i]=false;
       in_num[i]
=0;
    }
    push(q,s);
    
in[s]=true;
    in_num[s]
++;
    
while(!empty(q))
    {
       
long i=pop(q);in[i]=false;
       
for(p=a[i]->next;p;p=p->next)
       {
          
long j=p->v;
          
if(d[i]+p->w<d[j])
          {
             d[j]
=d[i]+p->w;
             
if(!in[j])
             {
                push(q,j);
                
in[j]=true;
                in_num[j]
++;
                
if(in_num[j]>n) return false;
             }
          }
       }
    }
    
return true;
}
int main()
{
    
//*
    freopen("data.in","r",stdin);
    freopen(
"data.out","w",stdout);
    
//*/
    scanf("%ld%ld",&n,&m);
    
for(long i=1;i<=n;i++)
    {
       a[i]
=new edge_node;
       a[i]
->next=NULL;
    }
    
for(long i=1;i<=m;i++)
    {
       
long a,b,w;
       scanf(
"%ld%ld%ld",&a,&b,&w);
       insert(a,b,w);
       insert(b,a,w);
    }
    
if(bellman_ford(1))
    {
       
for(long i=1;i<=n;i++) printf("%ld ",d[i]);
       putchar(
'\n');
    }
    
else printf("Error\n");
return 0;
}


lee1r 2010-01-06 18:17 鍙戣〃璇勮
]]>
鎼滅儲綆楁硶灝忕粨http://www.shnenglu.com/rakerichard/archive/2010/01/06/104941.htmllee1rlee1rWed, 06 Jan 2010 10:11:00 GMThttp://www.shnenglu.com/rakerichard/archive/2010/01/06/104941.htmlhttp://www.shnenglu.com/rakerichard/comments/104941.htmlhttp://www.shnenglu.com/rakerichard/archive/2010/01/06/104941.html#Feedback0http://www.shnenglu.com/rakerichard/comments/commentRss/104941.htmlhttp://www.shnenglu.com/rakerichard/services/trackbacks/104941.html

鏈榪戜竴孌墊椂闂翠粩緇嗗湴瀛︿範浜嗘悳绱㈡柟闈㈢殑涔︾睄錛屽鎼滅儲鏈変簡涓浜涙柊鐨勪綋浼氥傛悳绱㈢殑綆楁硶鏈夊緢澶氾紝浠庢渶綆鍗曠殑DFS銆丅FS錛屽埌紼嶇◢鏈夌偣浼樺寲鐨勮凱浠e姞娣便佽凱浠e姞瀹斤紝鍐嶅埌A*銆両DA*……鎰熻瀵逛簬鎼滅儲鐨勫涔犲拰榪愮敤錛岀粷瀵逛笉鑳藉彧灞闄愪簬榪欎簺甯哥敤鐨勬柟娉曚腑錛岃屽簲璇ュ鍚勪釜鏂規硶鏈変竴涓暣浣撶殑鎶婃彙錛屽垎鏋愬悇縐嶆柟娉曠殑浼樼偣鍜岀己鐐癸紝瀛︿細姣旇緝鍚勭鏂規硶鐨勬椂絀烘ц兘錛岄拡瀵歸鐩殑鐗圭偣鍏ユ墜銆?/font>

DFS

鏈甯哥敤鐨勪竴縐嶆悳绱㈡柟娉曪紝鍑犱箮瀛﹁繃鎼滅儲鐨勯兘浼氥傞傜敤浜庢悳绱㈢殑娣卞害宸茬煡錛屾瘮杈冮傚悎鎼滅儲鍏ㄩ儴瑙c傚父鐢ㄧ殑浼樺寲鏂規硶鏄湪緇撶偣鎵╁睍鏃跺姞鍏ュ壀鏋濈瓥鐣ャ?/font>

BFS

鐩稿涓嶥FS鍙兘鐢ㄥ緱灝戜簡鐐癸紝浣嗕篃鏄繀浼氱殑鍩烘湰鏂規硶銆傚鏋滄悳绱㈢殑娣卞害涓嶇煡錛孌FS鍙兘闄峰叆姝誨驚鐜紝鍚屾椂錛屽鏋滅┖闂翠笂鍙互鎵垮彈錛岃繖鏃跺欏彲浠ヨ冭檻BFS銆備晶閲嶅姹傛渶浼樿В銆?/font>

鍙屽悜騫垮害浼樺厛鎼滅儲

閫傜敤浜庣煡閬撶洰鏍囩姸鎬侊紝姣忔鎵╁睍涓や釜緇撶偣錛屼絾涓嶄竴瀹氶潪瑕佹槸浜ゆ浛鎵╁睍錛屾墿灞曟柟寮忓緢澶氥傚鏋滅洰鏍囩姸鎬佸緇堜笉鍙橈紝鑰屾湁澶氫釜鍒濆鐘舵侊紝灝卞彲浠?#8220;鍛ㄧ晫鎼滅儲”銆傝娉ㄦ剰鐨勬槸錛屽浣曞垽鏂凡緇忔墿灞曠粨鐐規槸鍚﹀湪鍙︿竴绔殑鏂規硶錛屾槸闇瑕佽鐪熻冭檻錛岄夊彇鏈浼樺垽鏂柟娉曠殑銆?/font>

榪唬鍔犳繁鎼滅儲 ID

姣忔闄愬埗鎼滅儲鐨勬繁搴︼紝鎵懼埌瑙e氨鍋滄錛屽惁鍒欏姞澶ф繁搴﹀啀嬈℃悳绱€傜浉瀵逛簬DFS涓嶄細闄峰叆姝誨驚鐜紝鐩稿浜嶣FS涓嶄細鍦ㄧ┖闂翠笂鏈夊帇鍔涳紝涔熷彲浠ョ敤鏉ュ姹傛渶浼樿В錛屼笉榪囩己鐐規槸閲嶅鎼滅儲銆?/font>

榪唬鍔犲鎼滅儲 IB

娌℃湁澶鎺ヨЕ錛屾棤瑙?#8230;…

A*

鎸塮(s)鐨勫兼墿灞曠粨鐐癸紝鏄竴縐嶅惎鍙戝紡鎼滅儲銆傞渶瑕佷袱涓〃錛屾瘡嬈″垽鏂槸鍚﹀湪琛?涓佹槸鍚﹀湪琛ㄤ簩涓佸悓鏃跺湪琛ㄤ竴琛ㄤ簩涓紝鍒ゆ柇f(s)鍜宖(s')鐨勫ぇ灝忥紝閫夋嫨鏄惁鏇挎崲銆傚叾涓璮(s)=g(s)+h(s)錛宧(s)涓轟及浠峰嚱鏁般傝姹俬鍑芥暟鐩稿錛屽浜庤繖縐嶈娉曪紝鎴戣嚜宸辯殑鐞嗚В灝辨槸錛岀姸鎬佹瘡杞Щ涓嬈★紝h鍑忓皯閲忔渶澶氫負1銆侫*綆楁硶姹傚緱鐨勭涓涓В蹇呮槸鏈浼樿В銆傜己鐐逛緷鐒舵槸絀洪棿闇姹傚お澶с?/font>

IDA*

榪唬鍔犳繁鐨凙*銆傛瘡嬈℃悳绱㈠姞涓婁竴涓繁搴﹂檺鍒訛紝鎵╁睍鐨勬椂鍊欏垽鏂渶濂芥儏鍐墊槸鍚︿細瓚呰繃娣卞害錛屼篃綆楁槸涓縐嶆瀬绔硶鐨勫壀鏋濇濇兂銆傞傜敤涓庢繁搴︿笉瀹氾紝鏈浼樿В鐨勬繁搴﹀張涓嶄竴瀹氬緢娣憋紝鑰岀姸鎬佽漿縐葷殑鏂瑰紡鍙堟湁寰堝錛屼嬌寰楃姸鎬佺┖闂存棤娉曟壙鍙椼?/font>

鍏充簬鍓灊錛?銆佸彲琛屾у壀鏋?2銆佹渶浼樻у壀鏋?/font>

鍏蜂綋鎿嶄綔鏃訛細1銆佹瀬绔硶 2銆佹暟瀛︽柟娉?/font>



lee1r 2010-01-06 18:11 鍙戣〃璇勮
]]>
騫舵煡闆嗗父鐢ㄦ搷浣?/title><link>http://www.shnenglu.com/rakerichard/archive/2010/01/06/104939.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Wed, 06 Jan 2010 10:05:00 GMT</pubDate><guid>http://www.shnenglu.com/rakerichard/archive/2010/01/06/104939.html</guid><wfw:comment>http://www.shnenglu.com/rakerichard/comments/104939.html</wfw:comment><comments>http://www.shnenglu.com/rakerichard/archive/2010/01/06/104939.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/rakerichard/comments/commentRss/104939.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/rakerichard/services/trackbacks/104939.html</trackback:ping><description><![CDATA[<p><font face=瀹嬩綋 size=3>騫舵煡闆嗭紙Union-Find Sets錛夌殑涓ょ鍔熻兘錛氬悎騫朵袱涓泦鍚堬紱鏌ユ壘涓涓厓绱犲睘浜庡摢涓泦鍚堛?/font></p> <p><font face=瀹嬩綋 size=3>騫舵煡闆嗙殑涓や釜浼樺寲錛氬熀浜巖ank鐨勫惎鍙戝紡鍚堝茍錛涜礬寰勫帇緙┿?/font></p> <p><font face=瀹嬩綋 size=3>浠ヤ笅鏄垜鐨勪唬鐮?/font><span style="COLOR: #000000">:</span><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"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> maxn</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">10008</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> n,f[maxn],rank[maxn];<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> Init()<br>{<br>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">long</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"><=</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>    {<br>       f[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;<br>       rank[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>    }<br>}<br></span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> Getf(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> x)<br>{<br>    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(f[x]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">x) </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> x;<br>    f[x]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">Getf(f[x]);</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 璺緞鍘嬬緝 </span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> f[x];<br>}<br></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000"> Same(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> x,</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> y)<br>{<br>    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> (Getf(x)</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">Getf(y));<br>}<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> Union(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> x,</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> y)<br>{<br>    </span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> fx</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">Getf(x),fy</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">Getf(y);<br>    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(fx</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">fy)<br>    {<br>       </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(rank[fx]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">rank[fy])<br>       {<br>          f[fx]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">fy;<br>          rank[fy]</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>       }<br>       </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(rank[fx]</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">rank[fy])<br>         f[fx]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">fy;<br>       </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> f[fy]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">fx;<br>    }</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 鍚彂寮忓悎騫?nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">}<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main()<br>{<br>    n</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">;<br>    Init();<br></span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>}<br></span></div> <img src ="http://www.shnenglu.com/rakerichard/aggbug/104939.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/rakerichard/" target="_blank">lee1r</a> 2010-01-06 18:05 <a href="http://www.shnenglu.com/rakerichard/archive/2010/01/06/104939.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鎷撴墤鎺掑簭(topo sort)http://www.shnenglu.com/rakerichard/archive/2010/01/06/104935.htmllee1rlee1rWed, 06 Jan 2010 09:49:00 GMThttp://www.shnenglu.com/rakerichard/archive/2010/01/06/104935.htmlhttp://www.shnenglu.com/rakerichard/comments/104935.htmlhttp://www.shnenglu.com/rakerichard/archive/2010/01/06/104935.html#Feedback0http://www.shnenglu.com/rakerichard/comments/commentRss/104935.htmlhttp://www.shnenglu.com/rakerichard/services/trackbacks/104935.html#include<stdio.h>
const long maxv=108;
long v,e,count,a[maxv],used[maxv];
bool g[maxv][maxv],ans;
void init()
{
    scanf(
"%ld%ld",&v,&e);
    
for(long i=1;i<=v;i++)
      
for(long j=1;j<=v;j++)
        g[i][j]
=false;
    
for(long i=1;i<=e;i++)
    
{
       
long a,b;
       scanf(
"%ld%ld",&a,&b);
       g[a][b]
=true;
    }

}

void dfs(long now)
{
    
if(!ans) return;
    used[now]
=-1;
    
for(long i=1;i<=v;i++)
      
if(g[now][i])
      
{
         
if(used[i]==-1)
         
{
            ans
=false;
            
return;
         }

         
else if(!used[i])
           dfs(i);
      }

    a[count]
=now;count--;
    used[now]
=1;
}

void toposort()
{
    
long begin;
    ans
=false;
    
    
for(long i=1;i<=v;i++)
    
{
       
for(long j=1;j<=v;j++)
         
if(g[j][i])
           
break;
       begin
=i;
       ans
=true;
       
break;
    }

    
//  Find a Vertex to Start
    if(ans)
    
{
       
for(long i=1;i<=v;i++)
         used[i]
=0;
       count
=v;
       dfs(begin);
    }

    
//  Topo_Sort
    if(ans)
    
{
       
bool first=true;
       
for(long i=1;i<=v;i++)
       
{
          
if(first) first=false;
          
else putchar(' ');
          printf(
"%ld",a[i]);
       }

       putchar(
'\n');
    }

    
else
      printf(
"No answer.\n");
    
//  Write down the Answer
}

int main()
{
    
//*
    freopen("data.in","r",stdin);
    freopen(
"data.out","w",stdout);
    
//*/
    init();
    toposort();
return 0;
}



lee1r 2010-01-06 17:49 鍙戣〃璇勮
]]>
久久夜色精品国产噜噜噜亚洲AV| 国产激情久久久久久熟女老人| 久久综合噜噜激激的五月天| 国内精品久久久久影院一蜜桃| 国产精品久久午夜夜伦鲁鲁| 国产精品成人久久久久久久| 日本道色综合久久影院| 亚洲精品无码久久毛片| 男女久久久国产一区二区三区| 7国产欧美日韩综合天堂中文久久久久| 久久久久香蕉视频| 久久精品国产亚洲AV香蕉| 久久国产乱子伦精品免费午夜| 狼狼综合久久久久综合网| 久久久久亚洲AV无码专区桃色| 精品久久久噜噜噜久久久 | 久久精品人人做人人爽97| 香蕉久久夜色精品国产小说| 久久午夜羞羞影院免费观看| 久久这里有精品视频| 久久国产高清字幕中文| 久久天天躁狠狠躁夜夜avapp| 亚洲国产成人精品91久久久 | 青青青青久久精品国产h| 亚洲人成网亚洲欧洲无码久久| 久久精品二区| 99久久精品国产毛片| 久久综合综合久久97色| 麻豆一区二区99久久久久| 久久综合鬼色88久久精品综合自在自线噜噜| 久久人人爽人人爽人人片av高请| 免费精品久久天干天干| 亚洲精品NV久久久久久久久久| 亚洲午夜无码AV毛片久久| 久久精品国产精品亚洲下载| 久久精品成人一区二区三区| 久久久久国产视频电影| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 久久久久成人精品无码中文字幕 | 亚洲国产精品无码久久久不卡| 中文无码久久精品|