POJ 2263 Heavy Cargo(Floyd + map)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 3768 | Accepted: 2013 |
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
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
- 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
#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)的更多相关文章
- POJ 2263 Heavy Cargo(ZOJ 1952)
最短路变形或最大生成树变形. 问 目标两地之间能通过的小重量. 用最短路把初始赋为INF.其它为0.然后找 dis[v]=min(dis[u], d); 生成树就是把最大生成树找出来.直到出发和终点能 ...
- poj 1797 Heavy Transportation(最大生成树)
poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...
- 【POJ - 2253】Frogger (Floyd算法)
-->Frogger 中文翻译 Descriptions: 湖中有n块石头,编号从1到n,有两只青蛙,Bob在1号石头上,Alice在2号石头上,Bob想去看望Alice,但由于水很脏,他想避免 ...
- POJ 1797 Heavy Transportation (Dijkstra变形)
F - Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- poj 1797 Heavy Transportation(最短路径Dijkdtra)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 26968 Accepted: ...
- POJ 3660 Cow ContestCow(Floyd传递闭包)题解
题意:给出m个关系,问你能确定机头牛的排名 思路:要确定排名那必须要把他和其他n-1头牛比过才行,所以Floyd传递闭包,如果赢的+输的有n-1就能确定排名. 代码: #include<cstd ...
- POJ 2263 Heavy Cargo 多种解法
好题.这题可以有三种解法:1.Dijkstra 2.优先队列 3.并查集 我这里是优先队列的实现,以后有时间再用另两种方法做做..方法就是每次都选当前节点所连的权值最大的边,然后BFS搜索. ...
- poj 1797 Heavy Transportation(Dijkstar变形)
http://poj.org/problem?id=1797 给定n个点,及m条边的最大负载,求顶点1到顶点n的最大载重量. 用Dijkstra算法解之,只是需要把“最短路”的定义稍微改变一下, A到 ...
- POJ 1791 Heavy Transportation(最大生成树)
题面 Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand ...
随机推荐
- 开发人员应该知道的SEO
搜索引擎是如何工作的 > 如果你有时间,可以读一下谷歌的框架: http://infolab.stanford.edu/~backrub/google.html > 这是一个老的,有些过时 ...
- docker初步
[Note,]由于docker的局限性,docker只能运行在64位的系统中 docker软件应用程序可以重复地运行在任何地方,因为它的容器包含了所有的环境依赖关系! docker有三种方式运行 作为 ...
- javascript运算符整理
说起运算符,基本上各类编程语言中都会涉及,使用方法大同小异.今天在这里以javascript做简单的整理. 总得来说运算符还是比较的多,大致可以分为以下几种类型: 一元运算符 位运算符 布尔运算符 乘 ...
- JS帮你计算属相
背景:一个人出生在2014年的正月初一,他的生肖到底是属蛇还是属马呢?这就要确定那一天才是一年的开始.是春节还是立春?每年的春节是正月初一,但是生肖必须是从立春日开始计算.春节是1912年孙中 ...
- Android应用开发学习之启动另外一个Activity
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 一个Activity可以启动另外一个Activity,以实现比较复杂的功能,我们来看一个例子,其运行效果如下图所示: ...
- URLConnection的连接、超时、关闭用法总结
Java中可以使用HttpURLConnection来请求WEB资源. 1. URL请求的类别 分为二类,GET与POST请求.二者的区别在于: a:) get请求可以获取静态页面,也可以把 ...
- Dave(正方形能围成的最大点数)
Dave Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Submis ...
- Spring 3.x企业应用开发实战(11)----基于@AspectJ配置切面
1.@AspectJ的JDK必须是JDK 5.0+ 基于@AspectJ配置切面 @AspectJ采用注解描述切点.增强,两者只是表达式方式不同,效果相同. @AspectJ语法基础-----切点表达 ...
- JAVA wait(), notify(),sleep具体解释
在CSDN开了博客后,一直也没在上面公布过文章,直到前一段时间与一位前辈的对话,才发现技术博客的重要,立志要把CSDN的博客建好.但一直没有找到好的开篇的主题,今天再看JAVA线程相互排斥.同步的时候 ...
- C#控制条码打印机 纸张大小,间距,绘制内容(所有条码打印机通用)
其他条码知识 请访问:http://www.ybtiaoma.com ,本文仅供参考,请勿转载,谢谢 using System; using System.Drawing; using System. ...