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. POJ 2392 Space Elevator DP

    该题与POJ 1742的思路基本一致:http://www.cnblogs.com/sevenun/p/5442279.html(多重背包) 题意:给你n个电梯,第i个电梯高h[i],数量有c[i]个 ...

  2. Jndi and c3p0 in Tomcat

    Tomcat 中Jndi是使用Tomcat自带的连接池抛弃Tomcat自带的连接池.使用c3p0 . 环境:Tomcat 5.5.20下面配置只适合Tomcat 5.5.X 下面来看Jndi 与 c3 ...

  3. IOS 判断设备类型

    - (NSString*)deviceString { // 需要#import "sys/utsname.h" struct utsname systemInfo; uname( ...

  4. JConsole 连接配置

    远程监控配置 JDK配置 在%JAVA_HOME%/jre/lib/management目录下,jmxremote.password.template.jmxremote.password需要修改配置 ...

  5. 一段代码说明javascript闭包执行机制

    假设你能理解以下代码的执行结果,应该就算理解闭包的执行机制了. var name = "tom"; var myobj = { name: "jackson", ...

  6. [置顶] 【cocos2d-x入门实战】微信飞机大战之十二:分数的本地存储

    转载请表明地址:http://blog.csdn.net/jackystudio/article/details/12036237 作为一个单机游戏,连分数存储的的功能都没有,让它怎么在单机游戏圈里混 ...

  7. Git服务器 gitweb与gitLab的区别

    昨天我们已经把Git服务器搭建完成了,工程的上传与下载都可以了,不过有些人不喜欢使用git命令进行操作.所以我们就搭建一个可视化操作的环境!配置gitweb和gitlab两种访问方式! 一,配置git ...

  8. [汇编学习笔记][第十七章使用BIOS进行键盘输入和磁盘读写

    第十七章 使用BIOS进行键盘输入和磁盘读写 17.1 int 9 中断例程对键盘输入的处理 17.2 int 16 读取键盘缓存区 mov ah,0 int 16h 结果:(ah)=扫描码,(al) ...

  9. C#使用seleium实现一个自动登录器

    1.http://docs.seleniumhq.org/ 下载seleium包 2.新建一个C#项目,比如控制台,引用seleium包中的dll using System; using System ...

  10. codeforces 519E A and B and Lecture Rooms(LCA,倍增)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud E. A and B and Lecture Rooms A and B are ...