题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=2425

Hiking Trip

Description

Hiking in the mountains is seldom an easy task for most people, as it is extremely easy to get lost during the trip. Recently Green has decided to go on a hiking trip. Unfortunately, half way through the trip, he gets extremely tired and so needs to find the path that will bring him to the destination with the least amount of time. Can you help him?
You've obtained the area Green's in as an R * C map. Each grid in the map can be one of the four types: tree, sand, path, and stone. All grids not containing stone are passable, and each time, when Green enters a grid of type X (where X can be tree, sand or path), he will spend time T(X). Furthermore, each time Green can only move up, down, left, or right, provided that the adjacent grid in that direction exists.
Given Green's current position and his destination, please determine the best path for him.

Input

There are multiple test cases in the input file. Each test case starts with two integers R, C (2 <= R <= 20, 2 <= C <= 20), the number of rows / columns describing the area. The next line contains three integers, VP, VS, VT (1 <= VP <= 100, 1 <= VS <= 100, 1 <= VT <= 100), denoting the amount of time it requires to walk through the three types of area (path, sand, or tree). The following R lines describe the area. Each of the R lines contains exactly C characters, each character being one of the following: ‘T’, ‘.’, ‘#’, ‘@’, corresponding to grids of type tree, sand, path and stone. The final line contains four integers, SR, SC, TR, TC, (0 <= SR < R, 0 <= SC < C, 0 <= TR < R, 0 <= TC < C), representing your current position and your destination. It is guaranteed that Green's current position is reachable – that is to say, it won't be a '@' square.
There is a blank line after each test case. Input ends with End-of-File.

Output

For each test case, output one integer on one separate line, representing the minimum amount of time needed to complete the trip. If there is no way for Green to reach the destination, output -1 instead.

Sample Input

4 6
1 2 10
T...TT
TTT###
TT.@#T
..###@
0 1 3 0

4 6
1 2 2
T...TT
TTT###
TT.@#T
..###@
0 1 3 0

2 2
5 1 3
T@
@.
0 0 1 1

Sample Output

Case 1: 14
Case 2: 8
Case 3: -1

bfs+优先队列。。

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
using std::cin;
using std::cout;
using std::endl;
using std::find;
using std::sort;
using std::map;
using std::pair;
using std::vector;
using std::multimap;
using std::priority_queue;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = ;
typedef unsigned long long ull;
bool vis[N][N];
char trip[N][N];
const int dx[] = { , , -, }, dy[] = { -, , , };
int R, C, Vs, Vp, Vt, Sx, Sy, Dx, Dy;
struct Node {
int x, y, s;
Node(int i = , int j = , int k = ) :x(i), y(j), s(k) {}
inline bool operator<(const Node &a) const {
return s > a.s;
}
};
int bfs() {
cls(vis, false);
priority_queue<Node> que;
que.push(Node(Sx, Sy, ));
vis[Sx][Sy] = true;
while (!que.empty()) {
Node tmp = que.top(); que.pop();
if (tmp.x == Dx && tmp.y == Dy) return tmp.s;
rep(i, ) {
int nx = dx[i] + tmp.x, ny = dy[i] + tmp.y;
char &ch = trip[nx][ny];
if (nx < || nx >= R || ny < || ny >= C) continue;
if (ch == '@' || vis[nx][ny]) continue;
if (ch == 'T') que.push(Node(nx, ny, tmp.s + Vt));
else if (ch == '.') que.push(Node(nx, ny, tmp.s + Vs));
else if (ch == '#') que.push(Node(nx, ny, tmp.s + Vp));
vis[nx][ny] = true;
}
}
return -;
}
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int k = ;
while (~scanf("%d %d", &R, &C)) {
scanf("%d %d %d", &Vp, &Vs, &Vt);
rep(i, R) scanf("%s", trip[i]);
scanf("%d %d %d %d", &Sx, &Sy, &Dx, &Dy);
printf("Case %d: %d\n", k++, bfs());
}
return ;
}

hdu 2425 Hiking Trip的更多相关文章

  1. hdu 2425 Hiking Trip (bfs+优先队列)

    Problem Description Hiking in the mountains is seldom an easy task for most people, as it is extreme ...

  2. hdu - 1242 Rescue && hdu - 2425 Hiking Trip (优先队列+bfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=1242 感觉题目没有表述清楚,angel的朋友应该不一定只有一个,那么正解就是a去搜索r,再用普通的bfs就能过了 ...

  3. 【HDOJ】2425 Hiking Trip

    优先级队列+BFS. #include <iostream> #include <cstdio> #include <cstring> #include <q ...

  4. [欧拉回路] hdu 3018 Ant Trip

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3018 Ant Trip Time Limit: 2000/1000 MS (Java/Others) ...

  5. hdu 5360 Hiking(优先队列+贪心)

    题目:http://acm.hdu.edu.cn/showproblem.php? pid=5360 题意:beta有n个朋友,beta要邀请他的朋友go hiking,已知每一个朋友的理想人数[L, ...

  6. hdu 3018 Ant Trip 欧拉回路+并查集

    Ant Trip Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem ...

  7. HDU 5360 Hiking 登山 (优先队列,排序)

    题意: 有n个人可供邀请去hiking,但是他们很有个性,每个人都有个预期的人数上下限[Li,Ri],只有当前确定会去的人数在这个区间内他才肯去.一旦他答应了,无论人数怎样变更,他都不会反悔.问最多能 ...

  8. HDU 2425 DNA repair (AC自动机+DP)

    DNA repair Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  9. HDU 3018 Ant Trip (欧拉回路)

    Ant Trip Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

随机推荐

  1. 关于Rational Functional Tester (RFT)的简单介绍

    前段时间给客户做了个RFT的简单培训,以下.因为涉及到公司的框架,所以中间省去了很多框架里的细节,只留了一个框架的总体结构的概览. RFT IBM Rational Functional Tester ...

  2. linux下DNS设置以及解析顺序

    1.编辑/etc/resolv.conf文件,添加如下语句: nameserver dns_ip(例如nameserver 8.8.8.8) 2.如/etc/nsswitch.conf中未包含启用DN ...

  3. 洛谷P2738 [USACO4.1]篱笆回路Fence Loops

    P2738 [USACO4.1]篱笆回路Fence Loops 11通过 21提交 题目提供者该用户不存在 标签USACO 难度提高+/省选- 提交  讨论  题解 最新讨论 暂时没有讨论 题目描述 ...

  4. 洛谷P1466 集合 Subset Sums

    P1466 集合 Subset Sums 162通过 308提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交  讨论  题解 最新讨论 暂时没有讨论 题目描述 对于从1到N (1 ...

  5. android 上传文件用php程序在服务端接受(一)

    php服务端接受程序..file_up.php. <?php /* require_once('lib/session_config.php'); require_once('lib/flydc ...

  6. idea 文件名乱码问题的解决

    参考:http://www.cnblogs.com/xingma0910/p/4651889.html idea:文件名乱码:

  7. 二模09day1解题报告

    T1.词编码(word) 给出一些原长为n的01串经过变化后的串求原串.原串的特点是:各个1的位置号和%(n+1)==0 变法(只取其一): 改一个0为1 删一个 加一个 不变. 其中2优先考虑位置靠 ...

  8. SVN与TortoiseSVN实战:标签与分支

    最近在写<IOS性能调优系列>,今天偷个懒,写写SVN与TortoiseSVN实战的第二篇,标签与分支. 第一篇详见<SVN与TortoiseSVN实战:从入门到精通> SVN ...

  9. sqlite3里类似top的用法

    sqlite3里类似top的用法 在sqlserver中使用top是很正常的,类似这样的语句: SELECT TOP 10 * FROM [index] ORDER BY id DESC; 但是很不幸 ...

  10. 举例详解CSS中的继承

    CSS的继承是由所使用的样式属性定义的.换句话说,当你查看CSS属性backgruound-color,你会看到一栏「继承性」,也许你几乎没有在意过它,但是它还是十分有用的.什么是CSS继承 每一个元 ...