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

Floyd循环顺序写反了,k是最外层循环

Posted by 00403022 at 2005-07-26 22:28:47 on Problem 2496
In Reply To:谁能告诉我这个程序为什么错了 Posted by:chengmingvictor at 2005-07-26 22:17:46
> #include <iostream>
> #include <cmath>
> #include <algorithm>
> using namespace std;
> 
> int n, p;
> int const MAX = 100;
> int adj[MAX][MAX];
> int list[MAX*MAX];
> 
> int main(){
> 	int cases;
> 	cin>>cases;
> 	for(int c = 0; c < cases; c++)
> 	{
> 		cout<<"Scenario #"<<c+1<<':'<<endl;
> 		cin>>p>>n;
> 		for(int i = 0; i < n; i++)
> 			for(int j = 0; j < n; j++)
> 			{
> 				cin>>adj[i][j];
> 				adj[i][j] &= 0xfffffff;
> 			}
> 
> 		//Floyd algorithm
> 		for(i = 0; i < n; i++)
> 			for(int j = 0; j < n; j++)
> 				for(int k = 0; k < n; k++)
> 					if(adj[i][k] + adj[k][j] < adj[i][j])
> 						adj[i][j] = adj[i][k] + adj[k][j];
> 		int t = 0;
> 		for(i = 0; i < n; i++)
> 			for(int j = 0; j < n; j++)
> 				if(i != j)
> 					list[t++] = adj[i][j];
> 		sort(list, list + t);
> 		int index = ceil(t * p / 100.0) -1; 
> 		cout<<list[index]<<endl<<endl;
> 	}
> 	return 0;
> }
> 
> 

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