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 jisuan at 2010-12-03 23:40:42 on Problem 2472
#include <iostream>
#include <iomanip>
#include <cstdio>
using namespace std;
#define min 0
#define start 1
void Dijkstra(int n);

	double road[101][101]={0};
	double dist[101];
	bool s[101];

int main()
{
	int n,m;
	int i;
	int a,b,p;

	scanf("%d",&n);
	while(n)
	{
		scanf("%d",&m);

		for(i=1;i<=n;i++)
			for(int j=1;j<=n;j++)		road[i][j]=min;

		while(m--)
		{
			scanf("%d%d%d",&a,&b,&p);
			road[a][b]=p/100.000;
			road[b][a]=p/100.000;
		}

		Dijkstra(n);

		printf("%.6lf percent\n",dist[n]*100);

		scanf("%d",&n);
	}

	return 0;
}//main
void Dijkstra(int n)
{
	int i,j;
	for(i=1;i<=n;i++)
	{
		dist[i]=road[start][i];
		s[i]=false;
	}
	dist[start]=0;
	s[start]=true;

	for(i=1;i<n;i++)
	{
		double tmp=min;
		int u=start;
		for(j=1;j<=n;j++)
			if( (!s[j]) && (dist[j]>tmp) )		{u=j;tmp=dist[j];}

			s[u]=true;
			for(j=1;j<=n;j++)
				if( (!s[j]) && (road[u][j]>min) )
				{
					double newdist=dist[u]*road[u][j];
					if(newdist>dist[j]) dist[j]=newdist;
				}
	}
}

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