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 ...
随机推荐
- [device tree] interrupt
Specifying interrupt information for devices ============================================ 1) Interru ...
- Oracle例外定义
例外名 ORA-XXXXX SQLCODE ACCESS_INTO_NULL ORA-06530 -6530 CASE_NOT_FOUND ORA-06592 -6592 COLLECTION_IS_ ...
- 看懂sh脚本
1 开头 程序必须以下面的行开始(必须方在文件的第一行): #!/bin/sh 符号#!用来告诉系统它后面的参数是用来执行该文件的程序.在这个例子中我们使用/bin/sh来执行程序. 当编写脚本完成时 ...
- 阿里云Centos等更新源设置成阿里源方法。
https://help.aliyun.com/knowledge_detail/5974184.html ---------------------------------------------- ...
- maven repository 配置
eclipse maven 配置修改: maven repository 配置 http://blog.csdn.net/joewolf/article/details/4876604 Maven缺省 ...
- 《java并发编程实战》读书笔记3--对象的组合
希望将一些现有的线程安全组件组合为更大规模的组件或程序 设计线程安全的类 如果对象中所有的域是基本类型变量,那么这些域将构成对象的全部状态.例如,LinkedList的状态就包括该链表中所有节点对象的 ...
- C# Merge into的使用详解
Merge是一个非常有用的功能,类似于Mysql里的insert into on duplicate key. Oracle在9i引入了merge命令, 通过这个merge你能够在一个SQL语句中对一 ...
- Centos7Yum安装配置指定版本nginx
1.安装 rpm -ivh http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.14.2-1.el7_4.ngx.x86_64.rpm 2.启 ...
- 595. Big Countries
There is a table World +-----------------+------------+------------+--------------+---------------+ ...
- 让你完全理解Base-64是怎么回事
HTTP将BASE64-编码用于基本认证和摘要认证,在几种HTTP扩展中也使用了该编码. Base-64编码保证了二进制数据的安全 Base-64编码可以将任意一组字节转换为较长的常见文本字符序列,从 ...