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

show一段有浓浓Pascal风格的c的AC代码

Posted by lwyzdxh at 2011-01-12 18:49:50 on Problem 1062
刚从Pascal转c,好诡异,枚举范围的
#include<stdio.h>
long head[10001],next[10001],link[10001],w[10001];
long lv[102],a[102];
long d[102],h[102];
long i,j,k,m,n,lim,tot,x,y,z;
short v[102];
long spfa(){
     long i,c,o;
     memset(d,60,sizeof(d));
     memset(v,0,sizeof(v));
     d[0]=0;h[1]=0;v[0]=1;c=1;o=2;
     do{
        i=head[h[c]];
        while (i!=0){
              if ((d[h[c]]+w[i]<d[link[i]])&&(lv[link[i]]>=lv[0])&&(lv[link[i]]<=lv[0]+m)){
                 d[link[i]]=w[i]+d[h[c]];
                 if (!v[link[i]]){
                    v[link[i]]=1;
                    h[o++]=link[i];
                    if (o>101)
                       o=1;
                 }
              }
              i=next[i];
        }
        v[h[c++]]=0;
        if (c>101)
           c=1;
     }while (c!=o);
     return d[1];
}
void add(long a,long b,long t){
     link[++tot]=b;
     w[tot]=t;
     next[tot]=head[a];
     head[a]=tot;
}
void qsort(long l,long r){
     long i,j,x,t;
     i=l;j=r;x=a[(l+r)>>1];
     while (i<=j){
           while (a[i]<x) i++;
           while (a[j]>x) j--;
           if (i<=j){
              t=a[i];a[i]=a[j];a[j]=t;
              i++;j--;
           }
     }
     if (l<j) qsort(l,j);
     if (i<r) qsort(i,r);
}
int main(){
    scanf("%ld%ld",&m,&n);
    tot=0;
    memset(head,0,sizeof(head));
    for (i=1;i<=n;i++){
        scanf("%ld%ld%ld",&x,&lv[i],&k);
        add(0,i,x);
        for (j=1;j<=k;j++){
            scanf("%ld%ld",&x,&y);
            add(x,i,y);
        }
    }
    memmove(a,lv,sizeof(lv));
    qsort(1,n);
    z=200000000;
    for (i=1;i<=n;i++){
        lv[0]=lv[i];
        x=spfa();
        if (x<z)
           z=x;
    }
    printf("%ld\n",z);
}

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