Heavy Cargo
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3768   Accepted: 2013

Description

Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their latest model, the Godzilla V12, is so big that the amount of cargo you can transport with it is never limited by the truck itself. It is only limited by the weight restrictions that apply for the roads along the path you want to drive.

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

The
input will contain one or more test cases. The first line of each test
case will contain two integers: the number of cities n (2<=n<=200)
and the number of road segments r (1<=r<=19900) making up the
street network.

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

For each test case, print three lines:

  • 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

Source

题意:求各城市每条给定起点和终点间通路的最小负载,并据此求出所有最小负载中的最大值.
思路:题目给的是城市名用map.
收获:map用法 + Floyd
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
using namespace std; const int INF=0x3f3f3f3f;
const double eps=1e-;
const double PI=acos(-1.0);
#define maxn 500 map<string, int> a;
char s1[];
char s2[];
int c[maxn][maxn];
int v[maxn][maxn];
int pre[maxn][maxn];
int main()
{
int n, m, w;
int cas = ;
while(~scanf("%d%d",&n,&m)&&(n+m))
{
int cnt = ;
memset(c, , sizeof c);
for(int i = ; i < m; i++)
{
scanf("%s%s%d", s1, s2, &w);
if(!a.count(s1))
a[s1] = cnt++;
if(!a.count(s2))
a[s2] = cnt++;
c[a[s1]][a[s2]] = c[a[s2]][a[s1]] = w;
}
// map<string, int>::iterator it;
// for(it=a.begin();it!=a.end();++it)
// cout<<"key: "<<it->first <<" value: "<<it->second<<endl;
for(int i = ; i < n; i++)
for(int j = ; j < n; j++)
{
v[i][j] = c[i][j];
//pre[i][j] = i;
} for(int k = ; k < n; k++)
for(int i = ; i<n; i++)
for(int j = ; j < n; j++)
{
v[i][j] = max(v[i][j], min(v[i][k],v[k][j]));
//pre[i][j] = pre[k][j];
} scanf("%s%s",s1,s2); printf("Scenario #%d\n", ++cas);
printf("%d tons\n",v[a[s1]][a[s2]]);
puts("");
}
return ;
}

POJ 2263 Heavy Cargo(Floyd + map)的更多相关文章

  1. POJ 2263 Heavy Cargo(ZOJ 1952)

    最短路变形或最大生成树变形. 问 目标两地之间能通过的小重量. 用最短路把初始赋为INF.其它为0.然后找 dis[v]=min(dis[u], d); 生成树就是把最大生成树找出来.直到出发和终点能 ...

  2. poj 1797 Heavy Transportation(最大生成树)

    poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...

  3. 【POJ - 2253】Frogger (Floyd算法)

    -->Frogger 中文翻译 Descriptions: 湖中有n块石头,编号从1到n,有两只青蛙,Bob在1号石头上,Alice在2号石头上,Bob想去看望Alice,但由于水很脏,他想避免 ...

  4. POJ 1797 Heavy Transportation (Dijkstra变形)

    F - Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  5. poj 1797 Heavy Transportation(最短路径Dijkdtra)

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 26968   Accepted: ...

  6. POJ 3660 Cow ContestCow(Floyd传递闭包)题解

    题意:给出m个关系,问你能确定机头牛的排名 思路:要确定排名那必须要把他和其他n-1头牛比过才行,所以Floyd传递闭包,如果赢的+输的有n-1就能确定排名. 代码: #include<cstd ...

  7. POJ 2263 Heavy Cargo 多种解法

    好题.这题可以有三种解法:1.Dijkstra   2.优先队列   3.并查集 我这里是优先队列的实现,以后有时间再用另两种方法做做..方法就是每次都选当前节点所连的权值最大的边,然后BFS搜索. ...

  8. poj 1797 Heavy Transportation(Dijkstar变形)

    http://poj.org/problem?id=1797 给定n个点,及m条边的最大负载,求顶点1到顶点n的最大载重量. 用Dijkstra算法解之,只是需要把“最短路”的定义稍微改变一下, A到 ...

  9. POJ 1791 Heavy Transportation(最大生成树)

    题面 Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand ...

随机推荐

  1. Hdu4005-The war(双连通缩点)

    In the war, the intelligence about the enemy is very important. Now, our troop has mastered the situ ...

  2. input表单 radio对象的判断选择

    /*选择约见对象*/ var lenth=$('input[name="single"]').length; var len=0; $('input[name="sing ...

  3. UITableView 滚动时隐藏键盘

    #pragma mark - UItableView滚动时收键盘 - (void)scrollViewWillBeginDragging:(UITableView *)scrollView { [se ...

  4. Spark常用函数讲解之Action操作

    摘要: RDD:弹性分布式数据集,是一种特殊集合 ‚ 支持多种来源 ‚ 有容错机制 ‚ 可以被缓存 ‚ 支持并行操作,一个RDD代表一个分区里的数据集RDD有两种操作算子:         Trans ...

  5. Android FragmentActivity onActivityResult冲突问题

    场景:假设fragment的填充数据是ListView,ListView中的每一项都有button,点击每一项的button跳转到B界面.在B界面处理完业务需返回fragment中更新数据. 解决方式 ...

  6. [Ext JS 4] 实战之Grid, Tree Gird编辑Cell

    前言 本篇这里以稍微复杂一点的Tree Grid 来介绍. 在写编辑grid 之, 先来看一下 grid 的 selType 的配置. 先给一个简单的Tree grid 的例子: Ext.onRead ...

  7. Swift 全功能的绘图板开发

    要做一个全功能的绘图板,至少要支持以下这些功能: 支持铅笔绘图(画点) 支持画直线 支持一些简单的图形(矩形.圆形等) 做一个真正的橡皮擦 能设置画笔的粗细 能设置画笔的颜色 能设置背景色或者背景图 ...

  8. CGContext

    CGContext又叫图形上下文,相当于一块画布,以堆栈形式存放,只有在当前 context上绘图才有效.iOS有分多种图形上下文,其中UIView自带提供的在drawRect:方法中通过 UIGra ...

  9. OAuth协议与第三方登录:(QQ,百度,微信,微博)

    OAuth 相当于授权的U盾,提供第三方认证的协议,是个安全相关的协议,作用在于,使用户授权第三方的应用程序访问用户的web资源,并且不需要向第三方应用程序透露自己的密码. 传统互联网:应用于PC端, ...

  10. OpenCV——常用函数查询

    1.cvLoadImage:将图像文件加载至内存: 2.cvNamedWindow:在屏幕上创建一个窗口: 3.cvShowImage:在一个已创建好的窗口中显示图像: 4.cvWaitKey:使程序 ...