View the step-by-step solution to:

# Problem D - The Tourist Guide Problem D The Tourist Guide Input: standard input Output: standard output Mr. works as a tourist guide. Some two-way...

#include <stdio.h>
#include <math.h>

#define MAX 102
#define NEGINF -10000

#define max(a, b) ( (a > b) ? (a) : (b) )
#define min(a, b) ( (a < b) ? (a) : (b) )

long passengers[MAX][MAX];

void init( long roads ) {
long i, j;
for( i = 1; i <= roads; ++i )
for( j = 1; j <= roads; ++j )
passengers[i][j] = NEGINF;
}
int main()
{
long i, j, k, scinario = 0;
long source, des, totalPassengers;
{
for( i = 0; i < roads; ++i ){
}
scanf( "%ld%ld%ld", &source, &des, &totalPassengers );
for( k = 1; k <= cities; ++k )
for( i = 1; i <= cities; ++i )
for( j = 1; j <= cities; ++j )
passengers[i][j] = max( passengers[i][j], min( passengers[i][k], passengers[k][j]));

printf( "Scenario #%ldnMinimum Number of Trips = %.0lfnn", ++scinario,
ceil( double(totalPassengers) / ( passengers[source][des] - 1 )));

}
return 0;
}#include <stdio.h>
#include <math.h>

#define MAX 102
#define NEGINF -10000

#define max(a, b) ( (a > b) ? (a) : (b) )
#define min(a, b) ( (a < b) ? (a) : (b) )

long passengers[MAX][MAX];

void init( int roads ) {
int i, j;
for( i = 1; i < MAX; ++i )
for( j = 1; j < MAX; ++j )
passengers[i][j] = 0;
}

int main()
{
long i, j, k, scinario = 0;
long source, des, totalPassengers;
{
for( i = 0; i < roads; ++i ){
}
scanf( "%ld%ld%ld", &source, &des, &totalPassengers );
for( k = 1; k <= cities; ++k )
for( i = 1; i <= cities; ++i )
for( j = 1; j <= cities; ++j )
passengers[i][j] = max( passengers[i][j], min( passengers[i][k], passengers[k][j]));

printf( "Scenario #%ldnMinimum Number of Trips = %.0lfnn", ++scinario,
ceil( double(totalPassengers) / ( passengers[source][des] - 1 )));

}
return 0;
}

Problem D The Tourist Guide Input: standard input Output: standard output Mr. G. works as a tourist guide. His current assignment is to take some tourists from one city to another. Some two-way roads connect the cities. For each pair of neighboring cities there is a bus service that runs only between those two cities and uses the road that directly connects them. Each bus service has a limit on the maximum number of passengers it can carry. Mr. G. has a map showing the cities and the roads connecting them. He also has the information regarding each bus service. He understands that it may not always be possible for him to take all the tourists to the destination city in a single trip. For example, consider the following road map of 7 cities. The edges connecting the cities represent the roads and the number written on each edge indicates the passenger limit of the bus service that runs on that road. Now, if he wants to take 99 tourists from city 1 to city 7, he will require at least 5 trips and the route he should take is : 1 - 2 - 4 - 7. But, Mr. G. finds it difficult to find the best route all by himself so that he may be able to take all the tourists to the destination city in minimum number of trips. So, he seeks your help. Problem D - The Tourist Guide file:///D|/Documents and Settings/Administrator/Desktop/next contests/tcl contest/problemset/p3.html (1 of 2) [4/4/2001 10:15:31 AM]
Input The input will contain one or more test cases. The first line of each test case will contain two integers: N (N<= 100) and R representing respectively the number of cities and the number of road segments. Then R lines will follow each containing three integers: C 1 , C 2 and P . C 1 and C 2 are the city numbers and P (P> 1) is the limit on the maximum number of passengers to be carried by the bus service between the two cities. City numbers are positive integers ranging from 1 to N . The ( R + 1)-th line will contain three integers: S , D and T representing respectively the starting city, the destination city and the number of tourists to be guided. The input will end with two zeroes for N and R . Output For each test case in the input first output the scenario number. Then output the minimum number of trips required for this case on a separate line. Print a blank line after the output of each test case. Sample Input 7 10 1 2 30 1 3 15 1 4 10 2 4 25 2 5 20 3 4 40 3 6 50 4 7 35 5 7 60 6 7 30 1 7 99 0 0 Sample Output Scenario #1 Minimum Number of Trips = 5 Rezaul Alam Chowdhury Problem D - The Tourist Guide file:///D|/Documents and Settings/Administrator/Desktop/next contests/tcl contest/problemset/p3.html (2 of 2) [4/4/2001 10:15:31 AM]

### Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

### -

Educational Resources
• ### -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents