zoukankan      html  css  js  c++  java
  • UVa 10099 The Tourist Guide

    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, since he has to ride the bus with each group, 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.

     

    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: C1C2 and PC1 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: SD 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 60
    3 4 40
    3 6 20
    4 7 35
    5 7 20
    6 7 30
    1 7 99
    0 0

    Sample Output

    Scenario #1
    Minimum Number of Trips = 5


    Rezaul 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
    Minimum Number of Trips = %d
    
    ",kase,ans);
    40     }
    41 
    42     return 0;
    43 }
    [C++]

     

  • 相关阅读:
    50个C/C++经典面试题
    多继承的构造顺序
    sizeof(struct)
    c++ 实现strcpy(),strlen()
    十天冲刺-01
    学习进度条(第八周)
    梦断代码阅读笔记01
    学习进度条(第七周)
    团队作业记账本开发NABCD
    学习进度条(第六周)
  • 原文地址:https://www.cnblogs.com/lzj-0218/p/3572319.html
Copyright © 2011-2022 走看看