题目大意:导游要带人去旅游,需要乘坐公交车,公交车有人数限制,导游要把所有人都带到终点,问导游最少要带几趟才能将所有人带到终点
解题思路:和噪音的那题相似,要从起点带到终点的次数最少,起点到终点的最小值就要达到最大,小心一点的就是,每次带过去的人应该要减去1个导游
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define maxn 105
int N,R;
int len[maxn][maxn];
int main(){
int mark = 1;
while(scanf("%d%d",&N,&R) != EOF && N + R) {
int t1,t2,l;
for(int i = 1; i <= N; i++)
for(int j = 1; j <= N; j++)
if(i == j)
len[i][j] = 0;
else
len[i][j] = -1;
for(int i = 0; i < R; i++) {
scanf("%d%d%d",&t1,&t2,&l);
len[t1][t2] = l;
len[t2][t1] = l;
}
scanf("%d%d%d",&t1,&t2,&l);
for(int k = 1; k <= N; k++)
for(int i = 1; i <= N; i++)
for(int j = 1; j <= N; j++)
if(len[i][k] != -1 && len[k][j] != -1) {
int temp = min(len[i][k],len[k][j]);
if(len[i][j] == -1 || temp > len[i][j])
len[i][j] = temp;
}
int ans;
if(l % (len[t1][t2] - 1) == 0)
ans = l / (len[t1][t2] - 1);
else
ans = l / (len[t1][t2] - 1) + 1;
printf("Scenario #%d\n",mark++);
printf("Minimum Number of Trips = %d\n\n",ans);
}
return 0;
}