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 ...
随机推荐
- [Linux]Linux printf 输出重定向【转】
转自:http://www.cnblogs.com/aaronLinux/p/6765145.html?utm_source=itdadao&utm_medium=referral 方法一 # ...
- python基础===抽象
懒惰即美德 斐波那契数列: >>> fibs = [0,1] >>> for i in range(8): fibs.append(fibs[-2]+fibs[-1 ...
- 构造函数、原型对象prototype、实例、隐式原型__proto__的理解
(欢迎一起探讨,如果有什么地方写的不准确或是不正确也欢迎大家指出来~) PS: 内容中的__proto__可能会被markdown语法导致显示为proto. 建议将构造函数中的方法都定义到构造函数的原 ...
- MongoDB的win安装教程
写在前面的 Mongo DB 是目前在IT行业非常流行的一种非关系型数据库(NoSql),其灵活的数据存储方式备受当前IT从业人员的青睐.Mongo DB很好的实现了面向对象的思想(OO思想),在Mo ...
- 坐标转换——GCJ-02
WGS84(World Geodetic System 1984),是为GPS 全球定位系统 使用而建立的坐标系统GCJ-02,我国在WGS84的基础上加密得到BD-09,百度坐标在GCJ-02基础上 ...
- P1968
题目背景 此处省略maxint+1个数 题目描述 在以后的若干天里戴维将学习美元与德国马克的汇率.编写程序帮助戴维何时应买或卖马克或美元,使他从100美元开始,最后能获得最高可能的价值. 输入输出格式 ...
- LeetCode解题报告—— Number of Islands & Bitwise AND of Numbers Range
1. Number of Islands Given a 2d grid map of '1's (land) and '0's (water), count the number of island ...
- redis之(十九)redis的管理
[一]redis的安全 --->redis的简洁美,使得redis的安全设计是在“redis运行在可信环境”这个前提下做出来,. --->在生产环境运行时不能允许外界直接链接到redis, ...
- python 几种循环性能测试: while, for, 列表生成式, map等
直接上代码: #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/07/24 16:23 import itertools imp ...
- FFmpeg软件只是个解码编码软件,如果支持多种格式必须先安装好对应的库,下面就说下我装的库
FFmpeg软件只是个解码编码软件,如果支持多种格式必须先安装好对应的库,下面就说下我装的库:1. 安装faad2 # wget http://downloads.sourceforge.net/fa ...