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

这道题的算法不是用Dijkstra 求从第一点到所有其他点的最短路径吗 ?

Posted by bingling at 2004-10-05 17:26:59 on Problem 1502
各位高手 帮忙看看 为什么错?是我题意没理解对吗?
#include<stdio.h>
int in[100][100];
int out[100];
int n;
void search()
{
	int i,min,sl,temp[100];
	temp[0]=0;
	for(i=1;i<n;i++)
		temp[i]=in[0][i];
	sl=1;
	do
	{
		min=1;
		for(i=2;i<n;i++)
			if(temp[i]>0&&temp[min]>temp[i])
				min=i;
		out[min]=temp[min];
		temp[min]=-2;
		for(i=1;i<n;i++)
		{
			if(in[min][i]!=-1&&(temp[i]>out[min]+in[min][i]||temp[i]==-1))
				temp[i]=out[min]+in[min][i];
		}
		sl++;
	}
	while(sl<n);
}
main()
{
	int i,j,max,k;
	char c='\0';
	scanf("%d",&n);
	in[0][0]=-1;
	for(i=1;i<n;i++)
	{
		in[i][i]=-1;
		for(j=0;j<i;j++)
		{
			k=0;
			do
			{
				while(c<'0'||c>'9'&&c!='x')
					scanf("%c",&c);
				if(c=='x')
					break;
				k=k*10+c-'0';
				scanf("%c",&c);
			}
			while(c>='0'&&c<'9');
			if(c=='x')	{ in[j][i]=in[i][j]=-1; scanf("%c",&c);}
			else in[j][i]=in[i][j]=k;
		}
	}
	search();
	for(i=1,max=0;i<n;i++)
		if(max<out[i])
			max=out[i];
	printf("%d\n",max);
}

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