Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
贴代码#include<iostream> using namespace std; const int MAX_INT = 9999999; int min( int num1, int num2 ) { if ( num1 < num2 ) return num1; else return num2; } int main() { int number; while( true ) { cin>>number; if ( number == 0 ) break; int person[101][101]; for ( int i = 1 ; i <= number ; i ++ ) { for ( int j = 1 ; j <= number ; j++ ) { if ( i == j ) person[i][j] = 0; else person[i][j] = MAX_INT; } } int num, input1, input2; for ( int i = 0 ; i < number ; i ++ ) { cin>>num; for ( int j = 0 ; j < num ; j ++ ) { cin>>input1>>input2; person[i+1][input1] = input2; } } for ( int i = 1 ; i <= number ; i ++ ) { for ( int j = 1 ; j <= number ; j ++ ) { for ( int t = 1 ; t <= number ; t ++ ) { person[j][t] = min(person[j][i]+person[i][t], person[j][t]); } } } int maxDistance[101] = {MAX_INT}; for ( int i = 1 ; i <= number ; i ++ ) { int tempMax = -1; for ( int j = 1 ; j <= number ; j ++ ) { if ( person[i][j] > tempMax ) tempMax = person[i][j]; } maxDistance[i] = tempMax; } int minDistance = MAX_INT, minNum = 0; for ( int i = 1 ; i <= number ; i ++ ) { if ( maxDistance[i] < minDistance ) { minDistance = maxDistance[i]; minNum = i; } } cout<<minNum<<" "<<minDistance<<endl; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator