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

Re:求教Floyed RuntimeErr问题

Posted by supersense at 2009-09-15 15:06:23 on Problem 1125
In Reply To:求教Floyed RuntimeErr问题 Posted by:supersense at 2009-09-15 15:03:20
> 为什么我的代码老是runtimeerror,诸位指教一下,谢过~
> #include <stdio.h>
> #define INT_MAX 200000
> 
> int cost[100][100];
> int shortest[100][100];
> 
> void floyed(int n)
> {
> 	int i,j,k;
> 	for(i=1;i<=n;i++)
> 		for(j=1;j<=n;j++)
> 		{
> 			shortest[i][j]=cost[i][j];
> 		}
> 		
> 	for(k=1;k<=n;k++)
> 		for(i=1;i<=n;i++)
> 			for(j=1;j<=n;j++)
> 			{
> 				if(shortest[i][j]>(shortest[i][k]+shortest[k][j]))
> 				{
> 					shortest[i][j]=shortest[i][k]+shortest[k][j];
> 				}
> 			}
> }
> 
> int main()
> {
> 	
> 	int i,j,min_max,min,end,temp,n,m,num;
> 	
> 	while(1)
> 	{
> 	for(i=0;i<100;i++)
> 		for(j=0;j<100;j++)
> 		{
> 			if(i==j)
> 			{
> 				cost[i][j]=0;
> 			}
> 			else
> 			{
> 				cost[i][j]=INT_MAX;
> 			}
> 		}
> 	scanf("%d",&num);
> 	
> 	if(num!=0)
> 	{
> 	n=num;
> 	i=1;
> 	while(n)
> 	{
> 		scanf("%d",&m);
> 		while(m)
> 		{
> 			scanf("%d",&j);
> 			scanf("%d",&cost[i][j]);
> 			m--;
> 		}
> 		i++;
> 		n--;
> 	}
> 	floyed(num);
> 	
> 	min=INT_MAX;
> 	for(i=1;i<=num;i++)
> 	{
> 		min_max=0;
> 		for(j=1;j<=num;j++)
> 		{
> 			if(min_max<shortest[i][j])
> 			{
> 				min_max=shortest[i][j];
> 				temp=i;
> 			}
> 		}
> 		
> 		if(min>min_max)
> 		{
> 			min=min_max;
> 			end=temp;
> 		}
> 	}
> 	printf("%d %d\n",end,min);
> 	/*for(i=1;i<=num;i++)
> 	{
> 	for(j=1;j<=num;j++)
> 		printf("%d ",shortest[i][j]);
> 	printf("\n");
> 	}*/
> 	}
> 	
> 	else
> 	 break;
> 	 }	
> 	return 0;	
> }
刚才用GCC编译的,runtimeerror,后来式了一下C,结果就过了……大牛解释一下……

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