Heavy Cargo POJ 2263 (Floyd传递闭包)
Description
Given start and destination city, your job is to determine the maximum load of the Godzilla V12 so that there still exists a path between the two specified cities.
Input
Then r lines will follow, each one describing one road segment by naming the two cities connected by the segment and giving the weight limit for trucks that use this segment. Names are not longer than 30 characters and do not contain white-space characters. Weight limits are integers in the range 0 - 10000. Roads can always be travelled in both directions.
The last line of the test case contains two city names: start and destination.
Input will be terminated by two values of 0 for n and r.
Output
- a line saying "Scenario #x" where x is the number of the test case
- a line saying "y tons" where y is the maximum possible load
- a blank line
Sample Input
4 3
Karlsruhe Stuttgart 100
Stuttgart Ulm 80
Ulm Muenchen 120
Karlsruhe Muenchen
5 5
Karlsruhe Stuttgart 100
Stuttgart Ulm 80
Ulm Muenchen 120
Karlsruhe Hamburg 220
Hamburg Muenchen 170
Muenchen Karlsruhe
0 0
Sample Output
Scenario #1
80 tons Scenario #2
170 tons 题目意思:有n个城市,m条连接两个城市的道路,每条道路有自己的最大复载量。现在问从城市a到城市b,车上的最大载重能为多少。 解题思路:这里并不是求解最短路径,而是要求通行能力(可称为容量)最大的路,这种路可以成为最大容量路,可以用Floyd算法求最短路径的思想求解。
w[i][j]=max(w[i][j],min(w[i][k],w[k][j]))
这里需要好好的思考一下,对于点i和点j,中间点的加入更改的递推式应该取最大值,因为求的就是最大的容量值,而对于新加进来的i-k和k-j必须取小的值,因为小的值才是这条路的容量值,
三重循环遍历之后就求出了每两点之间的最大容量值。注意初始化的时候w应该都为0,因为求的是最大值。
#include<cstring>
#include<cstdio>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int w[][];
char start[];
char dest[];
int n,m;
int num;
char city[][];///城市名
void Floyd()
{
int i,j,k;
for(k=; k<n; k++)
{
for(i=; i<n; i++)
{
for(j=; j<n; j++)
{
w[i][j]=max(w[i][j],min(w[i][k],w[k][j]));
}
}
}
}
int index(char *s)///给城市分配编号
{
int i;
for(i=; i<num; i++)
{
if(!strcmp(city[i],s))
{
return i;
}
}
strcpy(city[i],s);
num++;
return i;
}
int main()
{
int i,j,limit;
int counts;
int a,b;
counts=;
while(scanf("%d%d",&n,&m)!=EOF)
{
getchar();
if(n==)
{
break;
}
for(i=; i<n; i++)///初始化邻接表
{
for(j=; j<n; j++)
{
w[i][j]=;
}
}
for(i=; i<n; i++)
{
w[i][i]=INF;
}
num=;
for(i=; i<m; i++)
{
scanf("%s%s%d",start,dest,&limit);
getchar();
a=index(start);
b=index(dest);
w[a][b]=w[b][a]=limit;///双向
}
Floyd();
scanf("%s%s",start,dest);///读入起点城市和终点城市
a=index(start);
b=index(dest);
printf("Scenario #%d\n",counts++);
printf("%d tons\n",w[a][b]);
printf("\n");
}
return ;
}
Heavy Cargo POJ 2263 (Floyd传递闭包)的更多相关文章
- POJ 3275 Floyd传递闭包
题意:Farmer John想按照奶牛产奶的能力给她们排序.现在已知有N头奶牛(1 ≤ N ≤ 1,000).FJ通过比较,已经知道了M(1 ≤ M ≤ 10,000)对相对关系.每一对关系表示为&q ...
- POJ 3660 Floyd传递闭包
题意:牛有强弱,给出一些牛的强弱的胜负关系,问可以确定几头牛的排名. 思路: Floyd传递闭包 // by SiriusRen #include <bitset> #include &l ...
- Cow Contest POJ - 3660 floyd传递闭包
#include<iostream> #include<cstring> using namespace std; ,INF=0x3f3f3f3f; int f[N][N]; ...
- POJ 2263 Heavy Cargo(Floyd + map)
Heavy Cargo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3768 Accepted: 2013 Descr ...
- POJ 2594 —— Treasure Exploration——————【最小路径覆盖、可重点、floyd传递闭包】
Treasure Exploration Time Limit:6000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64 ...
- POJ 3660—— Cow Contest——————【Floyd传递闭包】
Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3660 Cow ContestCow(Floyd传递闭包)题解
题意:给出m个关系,问你能确定机头牛的排名 思路:要确定排名那必须要把他和其他n-1头牛比过才行,所以Floyd传递闭包,如果赢的+输的有n-1就能确定排名. 代码: #include<cstd ...
- POJ2263 Heavy Cargo
Heavy Cargo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4004 Accepted: 2124 Descr ...
- POJ3660:Cow Contest(Floyd传递闭包)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16941 Accepted: 9447 题目链接 ...
随机推荐
- c#一些处理解决方案(组件,库)
1.关系数据库 postgresql,mysql,oracle,sqlserver 2.本地数据库 sqlite,berkeleydb,litedb 3.缓存数据库 redis,mongdb 4.数据 ...
- promise 格式
promise执行过程(test) var arr =new Array() var obj =new Object() let p =new Promise(function(resolve,rej ...
- jquery ajax 滚动加载数据
jquery php 滚动加载数据(文件包 rollingpage) 效果如下: 页面加载时候($function(){ 自动加载第一页数据 }) 设置: var winH = $(window).h ...
- mysql5.6升级为mysql5.7部署jboss/wildfly应用项目
一.部署mysql5.7二进制版 解压tar -xvf mv mysql-5.7 /usr/local/mysql5.7 或者其他文件夹 cd /usr/local/mysql.57 usera ...
- 【转载++】fopen返回0(空指针NULL)且GetLastError是0
结论来看,是一个简单又朴素的道理——打开文件句柄用完了得给关上.表现在现象上却是着实让人费解,以至于有人还怀疑起了微软的Winodws系统来了,可笑至极.还是那句话,先把自己的屁股先给擦干净喽再怀疑别 ...
- 大二作业——操作系统实验——C语言用双向链表,模拟实现动态分区式存储管理
实验:动态分区式存储管理 实验内容: 编写程序模拟完成动态分区存储管理方式的内存分配和回收.实验具体包括:首先确定内存空闲分配表:然后采用最佳适应算法完成内存空间的分配和回收:最后编写主函数对所做工作 ...
- Linux入门第五天——shell脚本入门(中)基础语法之判断与条件
一.判断式 利用 test 命令进行执行结果的判断(例如判断是否存在该文件):关于test test:test 示例:结合回传值 $? 进行判断:关于$?:$? [root@localhost tm ...
- ARKit-1
1.1-AR技术简介 增强现实技术(Augmented Reality,简称 AR),是一种实时地计算摄影机影像的位置及角度并加上相应图像.视频.3D模型的技术,这种技术的目标是在屏幕上把虚拟世界套在 ...
- 使GDAL库支持中文路径或中文文件名的处理方法
之前生成的gdal 2.1.1动态库,在通过命令行执行时,遇到有中文路径或中文图像名时,GDALOpen函数不能正确的被调用,如下图: 解决方法: 1. 在所有使用GDALAllRegist ...
- 3060 抓住那头奶牛 USACO
3060 抓住那头奶牛 USACO 时间限制: 1 s 空间限制: 16000 KB 题目等级 : 黄金 Gold 题目描述 Description 农夫约翰被告知一头逃跑奶牛的位置,想要立即抓住它, ...