UVa10099_The Tourist Guide(最短路/floyd)(小白书图论专题)

解题报告

题意:

有一个旅游团现在去出游玩,现在有n个城市,m条路。由于每一条路上面规定了最多能够通过的人数,现在想问这个旅游团人数已知的情况下最少需要运送几趟

思路:

求出发点到终点所有路当中最小值最大的那一条路。

求发可能有多种,最短路的松弛方式改掉是一种,最小生成树的解法也是一种(ps,prime和dijs就是这样子类似的)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define inf 0x3f3f3f3f
using namespace std;
int n,m,q,mmap[110][110];
void floyd() {
    for(int k=0; k<n; k++)
        for(int i=0; i<n; i++)
            for(int j=0; j<n; j++)
                mmap[i][j]=max(mmap[i][j],min(mmap[i][k],mmap[k][j]));
}
int main() {
    int i,j,u,v,w,k=1;
    while(~scanf("%d%d",&n,&m)) {
        if(!n&&!m)break;
        for(i=0; i<n; i++) {
            for(j=0; j<n; j++)
                mmap[i][j]=0;
        }
        for(i=0; i<m; i++) {
            scanf("%d%d%d",&u,&v,&w);
            mmap[u-1][v-1]=mmap[v-1][u-1]=w;
        }
        floyd();
        scanf("%d%d%d",&u,&v,&w);
        int ans=0,num=mmap[u-1][v-1]-1;
        ans=ceil((double)w/num);
        printf("Scenario #%d\n",k++);
        printf("Minimum Number of Trips = %d\n\n",ans);
    }
    return 0;
}

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 andPC1 and C2 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 andT 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

UVa10099_The Tourist Guide(最短路/floyd)(小白书图论专题),布布扣,bubuko.com

时间: 2024-08-25 15:14:31

UVa10099_The Tourist Guide(最短路/floyd)(小白书图论专题)的相关文章

UVa10048_Audiophobia(最短路/floyd)(小白书图论专题)

解题报告 题意: 求所有路中最大分贝最小的路. 思路: 类似floyd算法的思想,u->v可以有另外一点k,通过u->k->v来走,拿u->k和k->v的最大值和u->v比较,存下最小的值. #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #define inf 0x3f3f3f3f using namespace std;

UVa10397_Connect the Campus(最小生成树)(小白书图论专题)

解题报告 题目传送门 题意: 使得学校网络互通的最小花费,一些楼的线路已经有了. 思路: 存在的线路当然全都利用那样花费肯定最小,把存在的线路当成花费0,求最小生成树 #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #define inf 0x3f3f3f3f using namespace std; int n,m,_hash[1110][1110],vis

UVa10034/POJ2560_Freckles(最小生成树)(小白书图论专题)

解题报告 题意: 把所有点连起来,求使用的墨水最少. 思路: 裸最小生成树. #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #define inf 0x3f3f3f3f using namespace std; struct N { double x,y; } node[110]; int vis[110],n; double mmap[110][110],

UVa567_Risk(最短路)(小白书图论专题)

解题报告 option=com_onlinejudge&Itemid=8&category=7&page=show_problem&problem=508">题目传送门 题意: 有20个城市,仅仅能征服相邻的城市,问要征服目的城市,最少须要征服多少城市(包含目的城市) 思路: 多源最短路,直接floyd,点才20个. #include <iostream> #include <cstring> #include <cstdio&

UVa10803_Thunder Mountain(最短路)(小白书图论专题)

解题报告 裸floyd. #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #define inf 0x3f3f3f3f using namespace std; int n; double mmap[210][210]; struct node { double x,y; } p[210]; double disc(node p1,node p2) { ret

UVa10986_Sending email(最短路)(小白书图论专题)

解题报告 思路: 裸裸的最短路. #include <iostream> #include <cstring> #include <cstdio> #include <queue> #define inf 0x3f3f3f3f #define N 40000 #define M 100000 using namespace std; struct node { int v,w,next; }edge[M]; int head[N],dis[N],vis[N]

UVa558_Wormholes(最短路)(小白书图论专题)

解题报告 思路: spfa判负环. #include <iostream> #include <cstring> #include <cstdio> #include <queue> #define inf 0x3f3f3f3f #define N 40000 #define M 100000 using namespace std; struct node { int v,w,next; } edge[M]; int head[N],dis[N],vis[

UVa10801_Lift Hopping(最短路)(小白书图论专题)

解题报告 思路 神奇的电梯,我的思路是直接整出一个超级源点和超级汇点(貌似这是网络流的叫法,,,sad) 源点与所有有在0层的电梯连线,汇点与k层连线,然后每个电梯如果有在同一层的连60s的线,对于每个电梯可以到达的每一层连一条线,处理层和电梯就直接用类似于离散化的方式处理,比如说第一个电梯可以有n个层可以到,第二个电梯有m个层可以到,那么就有1-n+m的点,源点0,汇点n+m+1: 做完看来别人的解题报告,发现我的想法很辍,因为只有在换电梯的时候才要松弛加上60,用邻接矩阵处理就很好. 智商捉

UVa10806_Dijkstra, Dijkstra.(网络流/费用流)(小白书图论专题)

解题报告 思路: 从s->t 再从t->s等同与s->t两次,要求每条路只能走一次,要求最小花费,让每一条边容量为1,跑跑费用流 只要跑出流量为2就结束. #include <iostream> #include <cstring> #include <cstdio> #include <queue> #define inf 0x3f3f3f3f #define N 5000 #define M 50000 using namespace