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 chenxuan123456789 at 2012-07-29 15:27:17 on Problem 1125
#include <stdio.h>
#define INF 999999
#define M 100+10
#define min(a,b) a>b?b:a
int map[M][M];
int n;
void init()
{
	int i,j;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
		{
			map[i][j]=INF;
			map[i][i]=0;
		}
}
void Flody()
{
	int i,j,k;
	for(k=1;k<=n;k++)
	{
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			map[i][j]=min(map[i][j],map[i][k]+map[k][j]);
		}
	}
}
void slove()
{
int i,j,k;
int ans=INF;
int ansnum;
int maxnum;
Flody();
for(i=1;i<=n;i++)
{
	maxnum=-1;
	for(j=1;j<=n;j++)
	{
		if(i!=j)
		{
			if(maxnum<map[i][j])
			{
				maxnum=map[i][j];
			}
		}
	}
	if(maxnum<ans)
	{
		ans=maxnum;
		ansnum=i;
	}
}
if(ans==INF)
printf("disjoint\n");
else
printf("%d %d\n",ansnum,ans);
}
int main()
{
	int i,j,k,m;
	while(scanf("%d",&n)!=EOF&&n)
	{  
		init();
		for(k=1;k<=n;k++)
		{
		scanf("%d",&m);
		for(;m>=1;m--)
		{
			scanf("%d%d",&i,&j);
			map[k][i]=j;
		}
	}
	slove();
	}
	return 1;
}




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