【HDOJ】2425 Hiking Trip
优先级队列+BFS。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std; #define MAXN 25 typedef struct node_st {
int x, y, t;
node_st() {}
node_st(int xx, int yy, int tt) {
x = xx; y = yy; t = tt;
}
friend bool operator < (node_st a, node_st b) {
return a.t > b.t;
}
} node_st; char map[MAXN][MAXN];
int visit[MAXN][MAXN];
int dir[][] = {-,,,,,-,,};
int n, m, vp, vs, vt;
int sx, sy, ex, ey; bool outRange(int x, int y) {
if (x< || x>=n || y< || y>=m)
return true;
return false;
} int bfs() {
int i, x, y, t;
priority_queue<node_st> que;
node_st node; if (map[ex][ey] == '@')
return -; memset(visit, , sizeof(visit));
map[sx][sy] = '@';
que.push(node_st(sx, sy, )); while (!que.empty()) {
node = que.top();
if (node.x==ex && node.y==ey)
return node.t;
que.pop();
for (i=; i<; ++i) {
x = node.x + dir[i][];
y = node.y + dir[i][];
if (outRange(x, y) || map[x][y]=='@')
continue;
if (map[x][y] == 'T')
t = node.t + vt;
if (map[x][y] == '.')
t = node.t + vs;
if (map[x][y] == '#')
t = node.t + vp;
if (visit[x][y]== || visit[x][y]>t) {
que.push(node_st(x, y, t));
visit[x][y] = t;
}
}
} return -;
} int main() {
int i, t=; while (scanf("%d %d", &n, &m) != EOF) {
scanf("%d%d%d", &vp, &vs, &vt);
for (i=; i<n; ++i)
scanf("%s", map[i]);
scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
i = bfs();
printf("Case %d: %d\n", ++t, i);
} return ;
}
【HDOJ】2425 Hiking Trip的更多相关文章
- hdu 2425 Hiking Trip
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2425 Hiking Trip Description Hiking in the mountains ...
- hdu 2425 Hiking Trip (bfs+优先队列)
Problem Description Hiking in the mountains is seldom an easy task for most people, as it is extreme ...
- 【HDOJ】3660 Alice and Bob's Trip
就是一个基本的dfs.可关键问题是c/c++/g++光输入就超时了.还是写java过的,毕竟时限4s.都放弃希望了,没想到还真过了. import java.lang.*; import java.i ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【poj1041】 John's trip
http://poj.org/problem?id=1041 (题目链接) 题意 给出一张无向图,求字典序最小欧拉回路. Solution 这鬼畜的输入是什么心态啊mdzz,这里用vector储存边, ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
- 【HDOJ】【3480】Division
DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...
- 【HDOJ】【2829】Lawrence
DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...
随机推荐
- Objective-C--Runtime机制
个人理解: 简单来说,Objective-C runtime是一个实现Objective-C语言的C库.对象可以用C语言中的结构体表示,而方法(methods)可以用C函数实现.事实上,他们 差不多也 ...
- [转] Understanding Twitter Bootstrap 3
Bootstrap is a popular, open source framework. Complete with pre-built components it allows web desi ...
- 如何判断Fragment是否对用户可见
背景 最近在开发中遇到了一个问题.我们的app需要统计用户的页面路径,也就是用户使用各个页面的情况.这就需要在不同的页面跳入和跳出时记录下来.但是我们的app主要是由Fragment构成的.而在不同的 ...
- htmlentities() 函数
Definition and Usage定义和用法 The htmlentities() function converts characters to HTML entities.htmlentit ...
- css兼容性问题
其实做网页最大的问题还是兼容性吧,要调试IE的各种浏览器. DIV+CSS设计IE6.IE7.FF 兼容性 DIV+CSS网页布局这是一种趋势,我也开始顺应这股趋势了,不过在使用DIV+CSS网站设 ...
- apache commons io包基本功能
1. http://jackyrong.iteye.com/blog/2153812 2. http://www.javacodegeeks.com/2014/10/apache-commons-io ...
- For and While loop choice.
/* Difference between 'for' and 'while'. We can transform everything between 'for' and 'while'. if t ...
- mysql locktables
SELECT r.trx_id waiting_trx_id, r.trx_mysql_thread_id waiting_thread, TIMESTAMPDIFF( ...
- memcached和mongodb 在windows下安装
要在新机器上安装memcached和mongodb服务,折腾了一天,终于把这两个服务在windows下跑起来了. memcached主要参考http://www.rootop.org/pages/27 ...
- Android界面布局学习总结
参考文章: http://blog.csdn.net/shakespeare001/article/details/7843460 http://www.cnblogs.com/w-y-f/p/412 ...