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. Axure 原型设计工具画业务流程图

    加入人人都是产品经理[起点学院]产品经理实战训练营,BAT产品总监手把手带你学产品点此查看详情! 软件行业从业6年,流程图看过太多,大部分流程图是在考验阅读者的理解能力,近期在设计公司新版APP,对流 ...

  2. [转]jQuery EasyUI 扩展-- 主题(Themes)

    主题(Themes)允许您改变站点的外观和感观.使用主题可以节省设计的时间,让您腾出更多的时间进行开发.您也可以创建一个已有主题的子主题. 主题生成器(Theme Builder) jQuery UI ...

  3. Wiggle Sort 解答

    Question Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= num ...

  4. ZOJ3829---模拟,贪心

    这是2014年ACM亚洲区预赛牡丹江现场赛的一道题,铜牌题,可惜当时一路WA到死... 只有乘法的后缀表达式的特点有两个:(1)数字的数量一定大于‘*’的数量(2)最后一位一定是‘*’: 数字比*多的 ...

  5. Payssion,海外本地支付_海外本地收款_小语种本地支付_外贸收款_外贸网店收款_欧洲本地支付_俄罗斯本地支付_巴西支付_跨境支付_PAYSSION,让跨境支付更轻松!

    Payssion,海外本地支付_海外本地收款_小语种本地支付_外贸收款_外贸网店收款_欧洲本地支付_俄罗斯本地支付_巴西支付_跨境支付_PAYSSION,让跨境支付更轻松!       首页 / 关于 ...

  6. java保留有效数字

    DecimalFormat df=DecimalFormat("######0.0") double d = df.format(xx): 保留一位就是"######0. ...

  7. 基于阿里云server搭建SVNserver

    基于阿里云server搭建SVNserver 本系列文章由ex_net(张建波)编写,转载请注明出处. http://blog.csdn.net/ex_net/article/details/8577 ...

  8. Android资源管理框架(Asset Manager)简要介绍和学习计划

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8738877 Android应用程序主要由两部分 ...

  9. Objective C—创建单例

    单例模式是在实际项目开发中用到比较多的一种设计模式,设计原理是整个系统只产生一个对象实例,通过一个统一的方法对外提供这个实例给外部使用. 在Java中,构造单例一般将类的构造函数声明为private类 ...

  10. css 实现进度条

    <select id="progress" onchange="changeProgress(this)"> <option value=&q ...