Problem Dios
The Tourist Guideide
Input: standard inputui
Output: standard outputthis
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.spa
Now, if he wants to take 99 tourists from city 1 to city 7, he will require at least 5 trips, since he has to ride the bus with each group, and the route he should take is : 1 - 2 - 4 - 7.code
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.orm
Inputblog
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: C1, C2 and P. C1 andC2 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.three
The input will end with two zeroes for N and R.ip
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 10Sample Output
Scenario #1Rezaul Alam Chowdhury
給一個無向圖,圖的每一個邊都有權值,當公交車從一條邊上走過期,它所載的人數不能超過這條邊的權值,如今一個導遊帶領遊客從一個點前往另外一個點,問最少要走多少趟才能夠把全部遊客都帶過去(每趟導遊都要跟着走)
用Floyd的思想,設G[i][j]爲從i到j的流量最大的路線的載客量,則有:
G[i][j]=max{ G[i][j] , min{G[i][k],G[k][j]} }
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 6 using namespace std; 7 8 int n,r; 9 int G[105][105]; 10 11 int main() 12 { 13 int kase=0; 14 15 while(scanf("%d %d",&n,&r)==2&&(n||r)) 16 { 17 kase++; 18 memset(G,0,sizeof(G)); 19 20 for(int i=1;i<=r;i++) 21 { 22 int a,b,c; 23 scanf("%d %d %d",&a,&b,&c); 24 G[a][b]=G[b][a]=c; 25 } 26 27 for(int k=1;k<=n;k++) 28 for(int i=1;i<=n;i++) 29 for(int j=1;j<=n;j++) 30 G[i][j]=max(G[i][j],min(G[i][k],G[k][j])); 31 32 int s,e,p,ans=0; 33 scanf("%d %d %d",&s,&e,&p); 34 35 ans=p/(G[s][e]-1); 36 if(p%(G[s][e]-1)) 37 ans++; 38 39 printf("Scenario #%d\nMinimum Number of Trips = %d\n\n",kase,ans); 40 } 41 42 return 0; 43 }