题意:
有一个导游要带着一群旅客从一个城市到达另一个城市,每个城市之间有最大的旅客流量限制。
问最少几趟能将这些旅客从一个城市搞到另一个城市。
解析:
用floyd找出最小流量中的最大边,然后次数就是 ceil(总人数 / 最大承载量 - 1),-1的意思是导游每次也要在车上。
ps.老司机哭晕在厕所
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <climits>
#include <cassert>
#define LL long long
using namespace std;
const int maxn = 100 + 10;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = 4 * atan(1.0);
const double ee = exp(1.0);
int n, m;
int g[maxn][maxn];
void floyd()
{
for (int k = 1; k <= n; k++)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
g[i][j] = max(g[i][j], min(g[i][k], g[k][j]));
}
}
}
}
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif // LOCAL
int ca = 1;
while (~scanf("%d%d", &n, &m))
{
if (!n && !m)
break;
memset(g, 0, sizeof(g));
for (int i = 0; i < m; i++)
{
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
g[u][v] = g[v][u] = w;
}
int fr, to, w;
scanf("%d%d%d", &fr, &to, &w);
floyd();
printf("Scenario #%d\n", ca++);
printf("Minimum Number of Trips = %.lf\n", ceil((double)w / (g[fr][to] - 1)));
printf("\n");
}
return 0;
}