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 ...
随机推荐
- java多线程以及Android多线程
Java 多线程 线程和进程的区别 线程和进程的本质:由CPU进行调度的并发式执行任务,多个任务被快速轮换执行,使得宏观上具有多个线程或者进程同时执行的效果. 进程:在操作系统来说,一个运行的程序或者 ...
- 改变ASPxpivotgridview弹出的prefilter的标题
说是要给变标题,再网上找了很久的资料,基本上属于一无所获,后来在官网上看到一个技术支持用vb写的,说是要本地化什么的,个人技术有限不是太懂 后来干脆就直接注册个账号,发问了,好歹等到了晚上十点左右,有 ...
- Iptables基础整理
Iptables基础框架
- Redis -- 过期时间 和 缓存 例子
1.设置 key的生存时间,过期自动删除 exprire key seconds 设置过期时间 秒数 ttl key 查询剩余时间 如果 设置了过期时间.对key进行 set 操作,会清除 ...
- 【linux】crontab定时命令
参考来源: http://blog.csdn.net/ariessurfer/article/details/7459183 http://www.jb51.net/LINUXjishu/19905. ...
- HDU-1934
Car Plates Competition Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu 2389(二分图hk算法模板)
Rain on your Parade Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 655350/165535 K (Java/Ot ...
- 云联云通讯报错:应用与模板id不匹配,解决方法
<statusMsg>应用与模板id不匹配</statusMsg> 这种一般是后端服务器上配置的APP ID和模板ID所属的APP不一致造成的 找到发送模板短信的方法,修改ap ...
- 176. Second Highest Salary
Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...
- bzoj 1485 卡特兰数 + 分解因子
思路:打表可以看出是卡特兰数,但是模数不一定是素数,所以需要分解一下因数. #include<bits/stdc++.h> #define LL long long #define fi ...