题意:给一个地图,'x'走一步代价为2,'.'走一步代价为1,求从s到t的最小代价。裸优先队列。

 #pragma comment(linker, "/STACK:10240000,10240000")

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <ctime>
#include <cctype>
#include <set> using namespace std; #define mem0(a) memset(a, 0, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define define_m int m = (l + r) >> 1
#define Rep(a, b) for(int a = 0; a < b; a++)
#define lowbit(x) ((x) & (-(x)))
#define constructInt4(name, a, b, c, d) name(int a = 0, int b = 0, int c = 0, int d = 0): a(a), b(b), c(c), d(d) {}
#define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
#define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {} typedef double db;
typedef long long LL;
typedef pair<int, int> pii;
typedef multiset<int> msi;
typedef multiset<int>::iterator msii;
typedef set<int> si;
typedef set<int>::iterator sii;
typedef vector<int> vi; const int dx[] = {, , -, , , , -, -};
const int dy[] = {, -, , , -, , , -};
const int maxn = 1e5 + ;
const int maxm = 1e5 + ;
const int maxv = 1e7 + ;
const int MD = 1e9 +;
const int INF = 1e9 + ;
const double PI = acos(-1.0);
const double eps = 1e-; struct Node {
int x, y, cost;
bool operator < (const Node &a) const {
return cost > a.cost;
}
constructInt3(Node, x, y, cost);
}; priority_queue<Node> Q; int n, m;
char s[][]; void BFS(int x1, int y1, int x2, int y2) {
while (!Q.empty()) Q.pop();
Q.push(Node(x1, y1, ));
s[x1][y1] = '*';
while (!Q.empty()) {
Node top = Q.top(); Q.pop();
if (top.x == x2 && top.y == y2) {
cout << top.cost << endl;
return ;
}
for (int i = ; i < ; i++) {
int x = top.x + dx[i], y = top.y + dy[i];
if (x >= && x < n && y >= && y < m && (s[x][y] == '.' || s[x][y] == 'x')) {
Q.push(Node(x, y, top.cost + (s[x][y] == '.'? : )));
s[x][y] = '*';
}
}
}
puts("Poor ANGEL has to stay in the prison all his life.");
} int main() {
//freopen("in.txt", "r", stdin);
while (cin >> n >> m) {
int x1, x2, y1, y2;
for (int i = ; i < n; i++) {
scanf("%s", s + i);
for (int j = ; j < m; j++) {
if (s[i][j] == 'r') {
x1 = i;
y1 = j;
s[i][j] = '.';
}
if (s[i][j] == 'a') {
x2 = i;
y2 = j;
s[i][j] = '.';
}
}
}
BFS(x1, y1, x2, y2);
}
return ;
}

[hdu1242]优先队列的更多相关文章

  1. hdu1242 优先队列+bfs

    Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  2. HDU1242 BFS+优先队列

    Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  3. HDU1242 Rescue(BFS+优先队列)

    Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  4. hdu1242 Rescue bfs+优先队列

    直接把Angle的位置作为起点,广度优先搜索即可,这题不是步数最少,而是time最少,就把以time作为衡量标准,加入优先队列,队首就是当前time最少的.遇到Angle的朋友就退出.只需15ms A ...

  5. Rescue HDU1242 (BFS+优先队列) 标签: 搜索 2016-05-04 22:21 69人阅读 评论(0)

    Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is describe ...

  6. hdu1242 Rescue(BFS +优先队列 or BFS )

    http://acm.hdu.edu.cn/showproblem.php?pid=1242 题意:     Angel被传说中神秘的邪恶的Moligpy人抓住了!他被关在一个迷宫中.迷宫的长.宽不超 ...

  7. 堆排序与优先队列——算法导论(7)

    1. 预备知识 (1) 基本概念     如图,(二叉)堆是一个数组,它可以被看成一个近似的完全二叉树.树中的每一个结点对应数组中的一个元素.除了最底层外,该树是完全充满的,而且从左向右填充.堆的数组 ...

  8. 数据结构:优先队列 基于list实现(python版)

    #!/usr/bin/env python # -*- coding:utf-8 -*- #Author: Minion-Xu #list实现优先队列 class ListPriQueueValueE ...

  9. python优先队列,队列和栈

    打印列表的疑问 class Node: def __str__(self): return "haha" print([Node(),Node()]) print(Node()) ...

随机推荐

  1. lua 逻辑运算 and, or, not

    这边并非说lua低级,为了方便区分才这么写的. 高级语言中的逻辑运算符是&&,||,! a&&b : 当a和b都为真, 结果返回为真,当a或者b有一个为假,结果返回为假 ...

  2. SQL Server 之T-SQL基本语句 (2)

    接下来继续用上述例子来总结知识点. 用通配符进行过滤 LIKE操作符 //用来选择与条件一样或部分相似的数据 select name from person where name like 'chen ...

  3. TensorFlow keras中一些著名的神经网络

  4. [Inno Setup] 安装完成后调用函数

    如果使用了通配符,每拷贝一个文件,函数都会被调用一次. Source: "path\test.exe"; DestDir: {app}; AfterInstall: LoadPer ...

  5. c语言解一元二次方程

    C语言解一元二次方程,输入系数a,b,c; #include <stdio.h> #include <math.h> int main(int argc, char *argv ...

  6. 用libevent写的海康摄像头rtsp客户端

    之前一直使用live555作为RTSP的客户端,但其框架臃肿,虽然支持各种格式,但实际中并没有这些需求,关键是其注重于格式的解析,却不注重网络IO,单线程下性能也不高,重新用libevent编写rts ...

  7. axios的使用小技巧:如何绕过字符串拼接,直接传递对象

     Vue.js官方推荐使用axios作为发送http请求的工具,在使用axios中,有些小技巧是不容易发现的.当我们不知道这些技巧时,我们可能会使用其他"奇技淫巧",比如,我们很容 ...

  8. webpack打包多入口配置

    在它的entry入口设置多文件入口即可,例: entry: { core: './src/core.js', design: './src/design.js' }, 单一出口输出: output: ...

  9. 工具 在 Nuget 发布自己的包

    MSDN : https://docs.microsoft.com/zh-cn/nuget/quickstart/create-and-publish-a-package-using-visual-s ...

  10. 使用mvp+rxjava+retrofit加载数据

    将mvp和rxjava和retrofit简单整合的列子,让activity的代码不再那么臃肿,只负责显示数据. 关于mvp的介绍可以看这里, 关于Rxjava的介绍可以看这里; 关于retrofit的 ...