[hdu1242]优先队列
题意:给一个地图,'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]优先队列的更多相关文章
- hdu1242 优先队列+bfs
Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- HDU1242 BFS+优先队列
Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- HDU1242 Rescue(BFS+优先队列)
Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- hdu1242 Rescue bfs+优先队列
直接把Angle的位置作为起点,广度优先搜索即可,这题不是步数最少,而是time最少,就把以time作为衡量标准,加入优先队列,队首就是当前time最少的.遇到Angle的朋友就退出.只需15ms A ...
- 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 ...
- hdu1242 Rescue(BFS +优先队列 or BFS )
http://acm.hdu.edu.cn/showproblem.php?pid=1242 题意: Angel被传说中神秘的邪恶的Moligpy人抓住了!他被关在一个迷宫中.迷宫的长.宽不超 ...
- 堆排序与优先队列——算法导论(7)
1. 预备知识 (1) 基本概念 如图,(二叉)堆是一个数组,它可以被看成一个近似的完全二叉树.树中的每一个结点对应数组中的一个元素.除了最底层外,该树是完全充满的,而且从左向右填充.堆的数组 ...
- 数据结构:优先队列 基于list实现(python版)
#!/usr/bin/env python # -*- coding:utf-8 -*- #Author: Minion-Xu #list实现优先队列 class ListPriQueueValueE ...
- python优先队列,队列和栈
打印列表的疑问 class Node: def __str__(self): return "haha" print([Node(),Node()]) print(Node()) ...
随机推荐
- Java优秀教程
1.java中局部变量是在栈上分配的: 2.数组是储存在堆上的对象,可以保存多个同类型变量: 3.在Java语言中,所有的变量在使用前必须声明. 4.局部变量没有默认值,所以局部变量被声明后,必须经过 ...
- Redis入门使用 -- 个人总结
目录 什么是Redis? Redis 与其他 key - value 数据库的对比 Redis 能干什么 Redis的安装配置 Redis启动和连接 上面开启的是非守护线程下启动(独占模式),下面我们 ...
- [linux][nginx] 通过nginx扩展nginx-rtmp-module简单做了一个流媒体直播
做的过程出现很多问题,环境其实就需要nginx就可以,然后就是在播放的问题,m3u8的格式,mac直接访问就支持,苹果系统原生H5支持m3u8,还有就是手机直接访问也支持!但是其他其他系统PC端不支持 ...
- python 基础篇 错误和异常处理
语法错误 所谓语法错误,也就是你写的代码不符合编程规范,无法被识别与执行,比如下面这个例子: if name is not None print(name) If 语句漏掉了冒号,不符合 Python ...
- wget下载整个网站---比较实用--比如抓取Smarty的document
wget下载整个网站可以使用下面的命令 wget -r -p -k -np http://hi.baidu.com/phps, -r 表示递归下载,会下载所有的链接,不过要注意的是,不要单独使用这个参 ...
- css3--:target选择器称为目标选择器
:target选择器称为目标选择器,用来匹配文档(页面)的url的某个标志符的目标元素.我们先来上个例子,然后再做分析. 示例展示 点击链接显示隐藏的段落. HTML代码: <h2>< ...
- 【<meta name="" content=">】的作用
一.语法: <meta name="name" content="string"/> 二.参数解析: 1.name项:常用的选项有keywords( ...
- ansible的基础概念与部署(一)
- Spring Boot filter
在Spring Boot中自定义filter 本文我们将会讲解如何在Spring Boot中自定义filter并指定执行顺序. 定义Filter很简单,我们只需要实现Filter接口即可,同时我们可指 ...
- linux系统的简单配置
配置网卡:vim /etc/sysconfig/network-scripts/网卡名称 ifcfg-xxxx ##文件名称 DEVICE=xxx ##设备名称 BOOTPROTO=dhcp|st ...