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

这题难道不是DIJ?

Posted by Essence_me at 2005-09-07 01:04:37 on Problem 2472
In Reply To:WA,难道是精度问题?大家帮忙看看啊:) Posted by:Essence_me at 2005-09-03 22:08:37
> #include <stdio.h>
> #include <memory.h>
> #define true  1
> #define false 0
> #define I  0
> #define N  100
> 
> double cost[N][N];
> double dist[N],max;
> int v0,v1;
> 
> void main()
> {
> 	int final[N],i,v,w,n,m;
> 	while(1)
> 	{
> 		scanf("%d",&n);
> 		if(n==0)break;
> 		scanf("%d",&m);
> 		v0=0;v1=n-1;
> 		memset(cost,0,sizeof(double)*n*n);
> 		for(i=0;i<m;i++)
> 		{
> 			int x,y,rate;
> 			scanf("%d%d%d",&x,&y,&rate);
> 			x--;y--;
> 			if(cost[x][y]!=0)
> 				if(rate<cost[x][y]*100)continue;
> 			cost[x][y]=(double)rate/100;
> 			cost[y][x]=(double)rate/100;
> 		}
> 		for(v=0;v<n;v++)
> 		{
> 			final[v]=false;
> 			dist[v]=cost[v0][v];
> 		}
> 		final[v0] = true;
> 
> 		while(1)
> 		{
> 			max=0;
> 			for(w=0;w<n;w++)
> 			{
> 				if(!final[w]&&dist[w]>max)
> 				{
> 					max=dist[w];
> 					v=w;
> 				}
> 			}
> 			final[v]=true;
> 			if(final[v1]==true)break;
> 			for(w=0;w<n;w++)
> 			{
> 				if(!final[w]&&dist[v]*cost[v][w]>dist[w])
> 				{
> 					dist[w]=dist[v]*cost[v][w];
> 				}
> 			}
> 		}
> 		printf("%.6lf percent\n",dist[v1]*100);
> 	}
> 
> }

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