Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
why??为什么用dijkstra算法求每个点对间的最长路径就wa啊 代码如下 #include<stdio.h> #include<string.h> #define MAXN 32 double mat[MAXN][MAXN]; double min[MAXN]; int count=1; int dijkstra(int n,int s,double mat[MAXN][MAXN],double min[]) { int i,j,flag; for (i=0;i<n;i++) { min[i]=0; } min[s]=10.0; do { flag=1; for (j=0;j<n;j++) { if(min[j]>0.00) { for (i=0;i<n;i++) if(mat[j][i]) { if (min[j]*mat[j][i]>min[i]) { min[i]=min[j]*mat[j][i]; flag=0; } } } } }while(!(flag||min[s]>10.0)); if(min[s]>10.0) return 1; else return 0; } int main() { int a,b,c,i,j,t,m,start,end,flag,len; char str[MAXN][MAXN]; char xx[MAXN],yy[MAXN]; double rate; while(scanf("%d",&t)!=EOF&&t!=0) { getchar(); memset(mat,0,sizeof(mat)); for(i=0;i<MAXN;i++) str[i][0]='\n'; for(i=0;i<t;i++) { scanf("%s",str[i]); } scanf("%d",&m); for(i=0;i<m;i++) { scanf("%s%lf%s",xx,&rate,yy); for(j=0;j<t;j++) { if(strcmp(str[j],xx)==0) a=j; if(strcmp(str[j],yy)==0) b=j; } mat[a][b]=rate; } flag=0; for(i=0;i<t;i++) { a=dijkstra(t,i,mat,min); if(a==1) { flag=1; break; } } printf("Case %d: ",count++); if(flag) printf("YES\n"); else printf("NO\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator