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:我用Floyd算法不知错哪了,大牛帮看下

Posted by phoenixzz at 2007-07-20 20:25:40 on Problem 1125
In Reply To:我用Floyd算法不知错哪了,大牛帮看下 Posted by:030501619 at 2007-06-02 13:53:17
> 如题,谢了
> #include<iostream>
> using namespace std;
> int main()
> {
> 	int n;
> 	while(cin>>n&&n!=0)
> 	{
> 		int i,j,a,u,v,k,t1,t2,t3,t=32767,q,t0;
> 		int *min=new int [n+1];
> 		for(i=0;i<n+1;i++)
> 			min[i]=0;
> 		int **c=new int *[n+1];
> 		for(i=0;i<n+1;i++)
> 			c[i]=new int [n+1];
> 		for(i=1;i<=n;i++)
> 			for(j=1;j<=n;j++)
> 				c[i][j]=32767;
> 		for(i=0;i<n;i++)
> 		{
> 			cin>>a;
> 			for(j=0;j<2*a;j=j+2)
> 			{
> 				cin>>u>>v;
> 				c[i+1][u]=v;
> 			}
> 		}
> 		for(i=1;i<=n;i++)
> 			c[i][i]=0;
> 		for(k=1;k<=n;k++)//Floyd算法
> 			for(i=1;i<=n;i++)
> 				for(j=1;j<=n;j++){
> 					t1=c[i][k];
> 					t2=c[k][j];
> 					t3=c[i][j];
> 					if(t1!=32767&&t2!=32767&&(t3==32767||t1+t2<t3)){
> 						c[i][j]=t1+t2;
> 					}
> 				}
> 		for(i=1;i<=n;i++)//寻找路径
> 		{
> 			for(j=1;j<=n;j++)
> 				min[i]=c[i][j]+min[i];
> 			if(min[i]<t)
> 			{
> 				t=min[i];
> 				q=i;
> 				t0=c[i][n-1];
> 			}
> 		}
>         if(t==32767)
> 		   cout<<"disjoint"<<endl;
> 		else cout<<q<<" "<<t0<<endl;
> 	}
> 	return 0;
> }




MUX 32767 会不会太小了啊,我向来都定义成10000000

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