K - Heavy Cargo dijkstar
来源poj2263
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
找到n的最大的载重,似乎之前做过,只要用dijkstar变形一下,每次找最大的来搜,收到end就是最大的了
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define scf(x) scanf("%d",&x)
#define scff(x,y) scanf("%d%d",&x,&y)
#define prf(x) printf("%d\n",x)
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
//#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
using namespace std;
const double pi=acos(-1.0);
const int N=1e5+10;
char name[205][35];
int map[205][205];
int visit[205];
int value[205];
int find(int n,char b[35])
{
rep(i,0,n)
{
if(strcmp(b,name[i])==0)
return i;
}
return -1;
}
int dijkstra(int n,int star,int end)
{
int pos,MAX=0;
value[star]=inf;
rep(i,0,n)
{
if(map[star][i]!=-1)
value[i]=map[star][i];
if(MAX<value[i]&&i!=star)
{
MAX=value[i];
pos=i;
}
}
visit[star]=1;
visit[pos]=1;
if(pos==end) return MAX;
rep(i,1,n)
{
MAX=0;
rep(j,0,n)
{
if(map[pos][j]!=-1&&visit[j]==0)
{
if(value[j]==-1) value[j]=min(map[pos][j],value[pos]);
else value[j]=max(value[j],min(map[pos][j],value[pos]));
}
}
rep(j,0,n)
{
if(MAX<value[j]&&j!=star&&visit[j]==0)
{
pos=j;
MAX=value[j];
}
}
visit[pos]=1;
if(pos==end) return value[end];
}
return value[end];
}
int main()
{
int n,m,k;
int bits=1;
char a[35],b[35];
while(~scff(n,m)&&n)
{
mm(visit,0);
mm(value,-1);
mm(map,-1);
int cas=0;
while(m--)
{
sf("%s%s%d",a,b,&k);
int x,y;
x=find(cas,a);
if(x==-1)
{
x=cas;
strcpy(name[cas++],a);
}
y=find(cas,b);
if(y==-1)
{
y=cas;
strcpy(name[cas++],b);
}
map[x][y]=map[y][x]=k;
}
sf("%s%s",a,b);
int star,end;
star=find(cas,a);end=find(cas,b);
int ans=dijkstra(n,star,end);
pf("Scenario #%d\n%d tons\n\n",bits++,ans);
}
return 0;
}
K - Heavy Cargo dijkstar的更多相关文章
- POJ2263 Heavy Cargo
Heavy Cargo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4004 Accepted: 2124 Descr ...
- POJ 2263 Heavy Cargo(Floyd + map)
Heavy Cargo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3768 Accepted: 2013 Descr ...
- Heavy Cargo POJ 2263 (Floyd传递闭包)
Description Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their lat ...
- poj2263 zoj1952 Heavy Cargo(floyd||spfa)
这道题数据范围小,方法比较多.我用floyd和spfa分别写了一下,spfa明显有时间优势. 一个小技巧在于:把城市名称对应到数字序号,处理是用数字. 方法一:spfa #include<ios ...
- POJ 2263 Heavy Cargo 多种解法
好题.这题可以有三种解法:1.Dijkstra 2.优先队列 3.并查集 我这里是优先队列的实现,以后有时间再用另两种方法做做..方法就是每次都选当前节点所连的权值最大的边,然后BFS搜索. ...
- POJ 2263 Heavy Cargo(ZOJ 1952)
最短路变形或最大生成树变形. 问 目标两地之间能通过的小重量. 用最短路把初始赋为INF.其它为0.然后找 dis[v]=min(dis[u], d); 生成树就是把最大生成树找出来.直到出发和终点能 ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- poj1013
题目大意:假造的银币 Sally Jones有一些游客给的银币,但是只有11枚是真正的银币(有一枚是假的),从颜色和大小是无法区分真比还是假币的,但是它的重量和真币是不同的,Sally Jones它是 ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
随机推荐
- Sqoop找不到主类 Error: Could not find or load main class org.apache.sqoop.Sqoop
最近由于要使用Sqoop来到出数据到hdfs,可是发现Sqoop1.4.5跟hadoop2.X不兼容,需要对Sqoop1.4.5进行编译,编译的具体方法见:http://my.codeweblog.c ...
- AXURE插件在 Chrome 浏览器中用不了怎么办?
使用Chrome浏览器打开axure设计的原型的时候可能无法正常显示,这时Chrome会提示你安装axure rp for Chrome插件.此前,我们只需要简单的点击install.2013年12月 ...
- Jsoup的简易使用示例
http://www.open-open.com/jsoup/parsing-a-document.htm 测试用网页 <!doctype html> <!-- http://jwc ...
- let's encrypt申请
let's encrypt申请 https://keelii.com/2016/06/12/free-https-cert-lets-encrypt-apply-install/ https://ww ...
- How to copy the contents of std::vector to c-style static array,safely?
[问题] I am getting warning when using the std copy function. I have a byte array that I declare. byte ...
- dubbo常见错误
1.dubbo zookeeper注册中心provider的ip地址为内网ip,导致consumer连不上 我用的阿里云的服务器,host默认配置了内网ip,注销或删除即可 vim /etc/host ...
- centos exfat格式U盘不支持问题
centos exfat格式U盘不支持问题 1. 下载fuse-exfat-1.3.0-1.el7.x86_64.rpm 2. 终端安装 rpm -ivh fuse-exfat-1.3.0-1.el ...
- nrm管理npm源
npm源:npm install命令下载需要依赖包的服务器地址,默认是 npm ---- https://registry.npmjs.org/ 而国外的源速度太慢,所以我们一般都用国内的淘宝源tao ...
- Xcode真机调试失败:The identity used to sign the executable is no longer valid
在Xcode中突然好久没有使用真机调试了.今天使用真机的时候.出现例如以下的警告.并真机执行失败: The identity used to sign the executable is no lon ...
- Vue在线客服系统【开源项目】
1. 项目介绍 一个基于Vue2.0的在线客服系统. 技术栈包含:Vue.VueX.Vue Router.Element UI. 2. 功能介绍 项目包含了2个模块:客服端和访客端. 2.1 客服端功 ...