Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求解释

Posted by gczsjdy1994 at 2010-11-02 15:04:54 on Problem 1201
1.写SPFA,用样例得到的答案是4,debug了一下后发现,可能是因为在变长相等时没有进行更新而导致后面没有更新dist值的max。于是就在一开始使所有点都入队。
我的问题是,什么情况下需要这样做,什么情况下只需要入队一个点就可以了?
代码:(比较喜欢敲回车~)
#include<stdio.h>
int first[500005],next[500005],cc[500005],value[500005],cnt=0;
void add(int a,int b,int c)
{
    int t;
    if(!first[a])
    {
      first[a]=++cnt;
      cc[cnt]=b;
      value[cnt]=c;
    }
    else
    {
      t=first[a];
      while(next[t])
      t=next[t];
      next[t]=++cnt;
      cc[cnt]=b;
      value[cnt]=c;
    }
    
    
}
int v[50005],queue[10000000],dist[50005]={0};
int main()
{
    int n;
    int x,y,z,t;
    int i,m=0;
    int begin=1,end;
    scanf("%d",&n);
    for(i=0;i<=50000;i++)
    {
        add(i,i+1,0);
        add(i+1,i,-1);
    }
    for(i=1;i<=n;i++)
    {
     scanf("%d%d%d",&x,&y,&z);
     if(x>y)
     {
       t=x;
       x=y;
       y=t;
     }
     if(y>m)
     m=y;
     x-=1;
     add(x,y,z);
    }
    for(i=0;i<=m;i++)
    {
    queue[i+1]=i;
    v[i]=1;
    }
    end=m+1;
    while(begin<=end)
    {
        x=queue[begin++];
        v[x]=0;
        for(i=first[x];i;i=next[i])
        {
           if(dist[x]+value[i]>dist[cc[i]])
           {
             dist[cc[i]]=value[i]+dist[x];
             if(!v[cc[i]])
             {
                v[cc[i]]=1;
                queue[++end]=cc[i];
             }
           }
        }
    }
    printf("%d",dist[m]);
    system("pause");
    
}

2.求解释“差分约束系统”这个名字。

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator