hdu2263Heavy Cargo
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>//POJ2263
#include <map>
#include <vector>
#include <cstring>
using namespace std;
const int maxn = 210;
const int maxm = 20000;
int n; int r;
int start, dest; //记录节点编号。
bool vis[maxn];//mark each point;//出队列后标记已经被更新过,如果在此访问不可更新其值则不再入队。
int value[maxn];//保存每个节点当前最大值,初始化为-1; //及时在更新 struct edge {
int from;
int to;
int weight;
}; struct point {
int num; // 队列里面到节点编号。
int w; // 队列里面到,到达此节点到距离。
bool operator < (const point& b) const {
return w < b.w;
}
}; vector<edge> G[maxn];
map<string, int> mymap;
priority_queue<point> Q; int work()
{
edge tmp;
point tmp_point;
int Size = G[start].size();
for(int i = 0; i < Size; i++) { //初始化队列。
tmp = G[start][i];
tmp_point.num = tmp.to;
tmp_point.w = tmp.weight;
Q.push(tmp_point);
value[tmp.to] = tmp.weight;//init value;
// printf("value[%d] = %d\n", tmp.to, tmp.weight);
}
while(!Q.empty())
{
tmp_point = Q.top();
// printf("tmp_point.num = %d, tmp_point.w = %d\n", tmp_point.num, tmp_point.w);
Q.pop();
int len = G[tmp_point.num].size();
for(int i = 0; i < len; i++) {
edge edge_tmp = G[tmp_point.num][i];
if(vis[edge_tmp.to]) { //已经被访问过,只是关心有可能得到解到,并入队。
if(value[edge_tmp.to] < min(edge_tmp.weight, tmp_point.w)) {
value[edge_tmp.to] = min(edge_tmp.weight, tmp_point.w);
point p;
p.num = edge_tmp.to;
p.w = value[edge_tmp.to];
Q.push(p);
}
}
else {//未被访问过。
value[edge_tmp.to] = min(edge_tmp.weight, value[edge_tmp.from]);
point p;
p.num = edge_tmp.to;
p.w = value[edge_tmp.to];
Q.push(p);
}
}
vis[tmp_point.num] = true;
if(tmp_point.num == dest) return tmp_point.w;//get result;
}
return value[n];
} void init() {
while(!Q.empty()) Q.pop();
mymap.clear();
memset(vis, false, sizeof(vis));
for(int i = 0; i <= n; i++) {
value[i] = -1;
}
} int main()
{
int counter = 1;
while(scanf("%d%d", &n, &r)!=EOF) {
init();
int cnt = 1; // 给节点编号。
if(n==0 && r==0) break;
string tmp[2];
int weight;
edge t; //临时变量
map<string, int>::iterator it;
for(int i = 1; i <= r; i++) {
cin >> tmp[0];
cin >> tmp[1];
for(int i = 0; i < 2; i++) {
if(mymap.find(tmp[i])==mymap.end())
mymap[tmp[i]] = cnt++;
}
cin >> weight;
t.from = mymap[tmp[0]];
t.to = mymap[tmp[1]];
t.weight = weight;
G[t.from].push_back(t);
t.from = mymap[tmp[1]];
t.to = mymap[tmp[0]];
G[t.from].push_back(t);
}
cin >> tmp[0] >> tmp[1];
start = mymap[tmp[0]], dest = mymap[tmp[1]];
int res = work();
printf("Scenario #%d\n", counter++);
printf("%d tons\n\n", res);
}
return 0;
}
hdu2263Heavy Cargo的更多相关文章
- 使用Cargo实现自动化部署
Cargo是一组帮助用户操作Web容器的工具,它能帮助用户实现自动化部署,而且它几乎支持所有的Web容器,如Tomcat.JBoss.Jetty和Glassfish.Cargo通过cargo-mave ...
- Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.2.3:run (default-cli) on project Maven_WebTest: Execution default-cli of goal org.codehaus.cargo:cargo-maven2-plugin:1.2.3:run failed: C
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- cargo failed to finish deploying within the timeout period [120000]
cargo插件,报错:failed to finish deploying within the timeout period [120000] 解决方法:配置timeout为0 <plugin ...
- POJ2263 Heavy Cargo
Heavy Cargo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4004 Accepted: 2124 Descr ...
- Loading Cargo
Loading Cargo "Look Stephen, here's a list of the items that need to be loaded onto the ship. W ...
- POJ 2263 Heavy Cargo(Floyd + map)
Heavy Cargo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3768 Accepted: 2013 Descr ...
- Jenkins [Error] at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:192)
Deploying /root/.jenkins/workspace/zgg-crm-pre/target/crm.war to container Tomcat 7.x Remote with co ...
- K - Heavy Cargo dijkstar
来源poj2263 Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their lates ...
- Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem C. Cargo Transportation 暴力
Problem C. Cargo Transportation 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed ...
随机推荐
- epoll内核源码分析
转载:https://www.nowcoder.com/discuss/26226?type=0&order=0&pos=27&page=1 /* * fs/eventpo ...
- Linux typeof【转】
转自:http://blog.csdn.net/xiaofeng_yan/article/details/5248633 今天偶然又看到了typeof这个东西,只知道它大概是返回变量的类型,后来上网查 ...
- python基础===python os.path模块
os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...
- 自动化测试===requests+unittest+postman的接口测试
postman是一个跨平台的接口测试工具,下载链接在这里:https://www.getpostman.com/ unittest是一个单元测试框架,python中安装:pip install uni ...
- python基础===修改属性的值
可以以三种不同的方式修改属性的值:直接通过实例进行修改:通过方法进行设置:通过方法进行递增(增加特定的值).下面依次介绍这些方法. class Car(): def __init__(self, ma ...
- centos_7.1.1503_src_4
http://vault.centos.org/7.1.1503/os/Source/SPackages/ libkcompactdisc-4.10.5-3.el7.src.rpm 05-Jul-20 ...
- JSP(3) - 9个JSP内置对象 - 小易Java笔记
1.9个JSP内置对象 内置对象引用名称 对应的类型 request HttpServletRequest response HttpServletResponse config Servle ...
- goreplay HTTP-HTTPS流量复制工具
goreplay相比tcpcopy只能复制HTTP和HTTPS的流量 goreplay编译很麻烦,就直接使用编译好的版本 gor_0.10.1_x64.tar.gz 支持centos5,测试的是cen ...
- (转) Spring源码阅读 之 Spring整体架构
标签(空格分隔): Spring 声明:本文系转载,原地地址:spring framework 4 源码阅读 Spring骨架 Spring的骨架,也是Spring的核心包.主要包含三个内容 cont ...
- K8s的内部Pod之间都不通,搞了快两天
试了不亚于二十种方法,绝望的时候,回到了家. 想手工安装,又遇到flannel在手工下,会更改docker启动项的不完善. cni,或许就是k8s的大方向吧. 最后,抱着试一试的态度,将flannel ...