题意:一个求最小的最大值,一个求最大的最小值,思路一样
思路:floyd
代码:
uva10048:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int c, s, q;
const int inf = 0x3f3f3f3f;
int mmap[105][105];
void floyd() {
for(int i=1; i<=c; i++)
for(int j=1; j<=c; j++)
for(int z=1; z<=c; z++) {
mmap[j][z] = min(mmap[j][z], max(mmap[j][i], mmap[i][z]));
}
}
int main() {
int a,b,d;
int cas = 1;
while(scanf("%d%d%d", &c, &s, &q) && (c+q+s)) {
memset(mmap, inf, sizeof(mmap));
for(int i=0; i<s; i++) {
scanf("%d%d%d", &a, &b, &d);
mmap[a][b] = mmap[b][a] = d;
}
floyd();
if(cas != 1)
printf("\n");
printf("Case #%d\n", cas++);
for(int i=0; i<q; i++) {
scanf("%d%d", &a, &b);
if(mmap[a][b] != inf)
printf("%d\n", mmap[a][b]);
else printf("no path\n");
}
}
return 0;
uva10099:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 105;
int f,s;
int q,d,t;
int mmap[maxn][maxn];
void floyd() {
for(int k=1; k<=f; k++)
for(int i=1; i<=f; i++)
for(int j=1; j<=f; j++) {
mmap[i][j] = max(mmap[i][j], min(mmap[i][k], mmap[k][j]));
}
}
int main() {
int a, b, c;
int cas = 1;
while(scanf("%d%d", &f, &s) && (f+s)) {
memset(mmap, 0, sizeof(mmap));
for(int i=0; i<s; i++) {
scanf("%d%d%d", &a, &b, &c);
mmap[a][b] = mmap[b][a] = c;
}
scanf("%d%d%d", &q, &d, &t);
floyd();
a = 0;
if(t%mmap[q][d]) a = 1;
int ans = t/(mmap[q][d]-1)+a;
printf("Scenario #%d\n", cas++);
printf("Minimum Number of Trips = %d\n", ans);
printf("\n");
}
return 0;
}