题意:给一个地图,'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. 关于vue切换用户,路由表不更新问题

    简介 我想很多同学在项目中可能会遇到类似的问题,然后一顿操作,发现结果不尽人意.于是查阅各种资料,走进很多坑(可能你阅读的这篇随笔也是个坑).接下来我所描述的是关于我使用不同权限的用户切换登陆后,需要 ...

  2. XSS语义分析的阶段性总结(一)

    本文作者:Kale 前言 由于X3Scan的研发已经有些进展了,所以对这一阶段的工作做一下总结!对于X3Scan的定位,我更加倾向于主动+被动的结合.主动的方面主要体现在可以主动抓取页面链接并发起请求 ...

  3. iview使用之怎样通过render函数在table组件表头添加图标及判断多个状态

    在实际项目开发中,我们经常会用到各种各样的表格,比如在表格中填加下拉菜单,按钮,图标及可以根据状态显示对应文字等等,因为这段时间一直在做后台管理系统,所以表格用的就比较多,当然UI组件库我用的是ivi ...

  4. tensorflow版线性回归

    import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' import tensorflow as tf def linearregression(): X ...

  5. 开发一款图片压缩工具(三):使用 click 实现命令行

    上一篇实现了图片的压缩函数.现在如果需要对图片进行压缩,可以调用实现的函数进行压缩: pngquant_compress('elephant.png', force=True, quality=20) ...

  6. 2019-2020-1 20199325《Linux内核原理与分析》第七周作业

    第七周作业 1.进程描述符task_struct数据结构(一) 为了管理进程,内核必须对每个进程进行清晰的描述,进程描述符提供了内核所需了解的进程信息. struct task_struct数据结构很 ...

  7. c语言 字符串大小写转换

    https://www.programmingsimplified.com/c/program/c-program-change-case https://docs.microsoft.com/en- ...

  8. [Windows]允许未签名的驱动

    bcdedit.exe -set loadoptions ENABLE_INTEGRITY_CHECKS bcdedit.exe -set TESTSIGNING OFF https://social ...

  9. mybatis 批量保存,并且唯一约束

    1.主键返回在insert配置中添加两个属性 useGeneratedKeys="true" keyProperty="id" 2.唯一约束冲突可以使用 ON ...

  10. 负载均衡服务之HAProxy访问控制ACL

    前文我们聊到了haproxy的错误页的配置,自定义日志的配置,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/12797913.html:今天我们主要来看看hap ...