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

  1. #pragma comment(linker, "/STACK:10240000,10240000")
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <algorithm>
  6. #include <cstdlib>
  7. #include <cstring>
  8. #include <map>
  9. #include <queue>
  10. #include <deque>
  11. #include <cmath>
  12. #include <vector>
  13. #include <ctime>
  14. #include <cctype>
  15. #include <set>
  16.  
  17. using namespace std;
  18.  
  19. #define mem0(a) memset(a, 0, sizeof(a))
  20. #define lson l, m, rt << 1
  21. #define rson m + 1, r, rt << 1 | 1
  22. #define define_m int m = (l + r) >> 1
  23. #define Rep(a, b) for(int a = 0; a < b; a++)
  24. #define lowbit(x) ((x) & (-(x)))
  25. #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) {}
  26. #define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
  27. #define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {}
  28.  
  29. typedef double db;
  30. typedef long long LL;
  31. typedef pair<int, int> pii;
  32. typedef multiset<int> msi;
  33. typedef multiset<int>::iterator msii;
  34. typedef set<int> si;
  35. typedef set<int>::iterator sii;
  36. typedef vector<int> vi;
  37.  
  38. const int dx[] = {, , -, , , , -, -};
  39. const int dy[] = {, -, , , -, , , -};
  40. const int maxn = 1e5 + ;
  41. const int maxm = 1e5 + ;
  42. const int maxv = 1e7 + ;
  43. const int MD = 1e9 +;
  44. const int INF = 1e9 + ;
  45. const double PI = acos(-1.0);
  46. const double eps = 1e-;
  47.  
  48. struct Node {
  49. int x, y, cost;
  50. bool operator < (const Node &a) const {
  51. return cost > a.cost;
  52. }
  53. constructInt3(Node, x, y, cost);
  54. };
  55.  
  56. priority_queue<Node> Q;
  57.  
  58. int n, m;
  59. char s[][];
  60.  
  61. void BFS(int x1, int y1, int x2, int y2) {
  62. while (!Q.empty()) Q.pop();
  63. Q.push(Node(x1, y1, ));
  64. s[x1][y1] = '*';
  65. while (!Q.empty()) {
  66. Node top = Q.top(); Q.pop();
  67. if (top.x == x2 && top.y == y2) {
  68. cout << top.cost << endl;
  69. return ;
  70. }
  71. for (int i = ; i < ; i++) {
  72. int x = top.x + dx[i], y = top.y + dy[i];
  73. if (x >= && x < n && y >= && y < m && (s[x][y] == '.' || s[x][y] == 'x')) {
  74. Q.push(Node(x, y, top.cost + (s[x][y] == '.'? : )));
  75. s[x][y] = '*';
  76. }
  77. }
  78. }
  79. puts("Poor ANGEL has to stay in the prison all his life.");
  80. }
  81.  
  82. int main() {
  83. //freopen("in.txt", "r", stdin);
  84. while (cin >> n >> m) {
  85. int x1, x2, y1, y2;
  86. for (int i = ; i < n; i++) {
  87. scanf("%s", s + i);
  88. for (int j = ; j < m; j++) {
  89. if (s[i][j] == 'r') {
  90. x1 = i;
  91. y1 = j;
  92. s[i][j] = '.';
  93. }
  94. if (s[i][j] == 'a') {
  95. x2 = i;
  96. y2 = j;
  97. s[i][j] = '.';
  98. }
  99. }
  100. }
  101. BFS(x1, y1, x2, y2);
  102. }
  103. return ;
  104. }

[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. Java优秀教程

    1.java中局部变量是在栈上分配的: 2.数组是储存在堆上的对象,可以保存多个同类型变量: 3.在Java语言中,所有的变量在使用前必须声明. 4.局部变量没有默认值,所以局部变量被声明后,必须经过 ...

  2. Redis入门使用 -- 个人总结

    目录 什么是Redis? Redis 与其他 key - value 数据库的对比 Redis 能干什么 Redis的安装配置 Redis启动和连接 上面开启的是非守护线程下启动(独占模式),下面我们 ...

  3. [linux][nginx] 通过nginx扩展nginx-rtmp-module简单做了一个流媒体直播

    做的过程出现很多问题,环境其实就需要nginx就可以,然后就是在播放的问题,m3u8的格式,mac直接访问就支持,苹果系统原生H5支持m3u8,还有就是手机直接访问也支持!但是其他其他系统PC端不支持 ...

  4. python 基础篇 错误和异常处理

    语法错误 所谓语法错误,也就是你写的代码不符合编程规范,无法被识别与执行,比如下面这个例子: if name is not None print(name) If 语句漏掉了冒号,不符合 Python ...

  5. wget下载整个网站---比较实用--比如抓取Smarty的document

    wget下载整个网站可以使用下面的命令 wget -r -p -k -np http://hi.baidu.com/phps, -r 表示递归下载,会下载所有的链接,不过要注意的是,不要单独使用这个参 ...

  6. css3--:target选择器称为目标选择器

    :target选择器称为目标选择器,用来匹配文档(页面)的url的某个标志符的目标元素.我们先来上个例子,然后再做分析. 示例展示 点击链接显示隐藏的段落. HTML代码: <h2>< ...

  7. 【<meta name="" content=">】的作用

    一.语法: <meta name="name" content="string"/> 二.参数解析: 1.name项:常用的选项有keywords( ...

  8. ansible的基础概念与部署(一)

  9. Spring Boot filter

    在Spring Boot中自定义filter 本文我们将会讲解如何在Spring Boot中自定义filter并指定执行顺序. 定义Filter很简单,我们只需要实现Filter接口即可,同时我们可指 ...

  10. linux系统的简单配置

    配置网卡:vim /etc/sysconfig/network-scripts/网卡名称 ifcfg-xxxx  ##文件名称 DEVICE=xxx  ##设备名称 BOOTPROTO=dhcp|st ...