hdu - 2822 Dogs (优先队列+bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=2822
给定起点和终点,问从起点到终点需要挖几次只有从# 到 .或者从. 到 . 才需要挖一次。
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
const int maxn = ;
int n,m;
int sx,sy,ex,ey;
char maze[maxn][maxn];
int vis[maxn][maxn];
int dir[][]={-,,,,,,,-};
struct point
{
int x,y,step;
char z;
bool operator < (const point a) const
{
return step>a.step;
}
}; int bfs()
{
// printf("%d %d\n",a,b);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
vis[i][j]=<<;
priority_queue<point>que;
point s;
s.x=sx;s.y=sy;s.step=;s.z='X';
que.push(s);
vis[s.x][s.y]=;
while(!que.empty())
{
point e=que.top();que.pop();
//printf("%d %d %d\n",e.x,e.y,e.step);
if(e.x==ex&&e.y==ey) return e.step;
for(int i=;i<;i++)
{
s=e;
s.x=e.x+dir[i][];
s.y=e.y+dir[i][];
if(s.x>=&&s.x<n&&s.y>=&&s.y<m)
{
if(maze[s.x][s.y]=='X') s.step=e.step;
else if(maze[s.x][s.y]=='.') s.step=e.step+;
if(s.step<vis[s.x][s.y])
{
vis[s.x][s.y]=s.step;
que.push(s);
}
}
}
}
} int main()
{
//freopen("a.txt","r",stdin);
while(~scanf("%d%d",&n,&m))
{
if(n==&&m==) break;
for(int i=;i<n;i++)
{
scanf("%s",maze[i]);
// printf("%s\n",maze[i]);
}
scanf("%d %d",&sx,&sy);
scanf("%d %d",&ex,&ey);
//printf("%d%d%d%d\n",sx,sy,ex,ey);
sx--,sy--,ex--,ey--;
printf("%d\n",bfs());
}
return ;
}
hdu - 2822 Dogs (优先队列+bfs)的更多相关文章
- hdu 2822 Dogs
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2822 Dogs Description Prairie dog comes again! Someda ...
- hdu 2822 Dogs(优先队列)
题目链接:hdu2822 会优先队列话这题很容易AC.... #include<stdio.h> #include<string.h> #include<queue> ...
- hdu 1026 Ignatius and the Princess I【优先队列+BFS】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1026 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- HDU 1428 漫步校园 (BFS+优先队列+记忆化搜索)
题目地址:HDU 1428 先用BFS+优先队列求出全部点到机房的最短距离.然后用记忆化搜索去搜. 代码例如以下: #include <iostream> #include <str ...
- ZOJ 649 Rescue(优先队列+bfs)
Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- 【POJ3635】Full Tank 优先队列BFS
普通BFS:每个状态只访问一次,第一次入队时即为该状态对应的最优解. 优先队列BFS:每个状态可能被更新多次,入队多次,但是只会扩展一次,每次出队时即为改状态对应的最优解. 且对于优先队列BFS来说, ...
- Codeforces 677D - Vanya and Treasure - [DP+优先队列BFS]
题目链接:http://codeforces.com/problemset/problem/677/D 题意: 有 $n \times m$ 的网格,每个网格上有一个棋子,棋子种类为 $t[i][j] ...
- POJ 2449 - Remmarguts' Date - [第k短路模板题][优先队列BFS]
题目链接:http://poj.org/problem?id=2449 Time Limit: 4000MS Memory Limit: 65536K Description "Good m ...
- HDU 2822 (BFS+优先队列)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2822 题目大意:X消耗0,.消耗1, 求起点到终点最短消耗 解题思路: 每层BFS的结点,优先级不同 ...
随机推荐
- scala.的Enumeration枚举示例(转)
简介 在scala中没有枚举类型,但在标准类库中提供了Enumeration类来产出枚举.扩展Enumeration类后,调用value方法类初始化枚举中的可能值. 内部类value实际上是一个抽象类 ...
- Farseer.net轻量级ORM开源框架 V1.8版本升级消息
SHA-1: 775a93cf64df3f49c83cc4f4df346afd2075a68f * 发布V1.8.0修复:Oracle的SQL生成 在没有条件时,缺少Where关键字,导致无法分页修复 ...
- 由于未清除缓存引发的bug
在写页面的时候,首先引入了本地react.js和react-dom.js 16版本(cjs)的文件,出现如下错误 发现bug后,将本地的react.js和react-dom.js文件改成16.2(um ...
- JavaSE-15 Log4j参数详解
一:日志记录器输出级别,共有5级(从前往后的顺序排列) ①fatel:指出严重的错误事件将会导致应用程序的退出 ②error:指出虽然发生错误事件,但仍然不影响系统的继续运行 ③warn:表明会出现潜 ...
- window10换系统为windows7
第一步 第二步 第三步 下载系统:http://www.dnxtc.net 1.GHO镜像安装器和WIN7,GHO文件必须一起放在除C盘外的其他盘的根目录 2.“GHO镜像安装器“工具上右键管理员方式 ...
- OpenGL C#绘图环境配置
OpenGL C#绘图环境配置 OpenGL简介 OpenGL作为一种图形学编程接口已经非常流行, 虽然在大型游戏方面DirectX有一定的市场占有率, 但由于OpenGL的开放性,可移植性等优点 ...
- Jupyter IPython dead kernel and do not restart
本人遇到的情况:dead kernel & try to restart failed 查看CMD发现这个库安装有问题 解决办法 1.pip uninstall backports.shuti ...
- 【2018 1月集训 Day1】二分的代价
题意: 现在有一个长度为 n的升序数组 arr 和一个数 x,你需要在 arr 中插入 x. 你可以询问 x 跟 arri 的大小关系,保证所有 arri 和 x 互不相同.这次询问的代价为 cost ...
- Shiro框架 (原理分析与简单实现)
Shiro框架(原理分析与简单实现) 有兴趣的同学也可以阅读我之前分享的:Java权限管理(授权与认证)CRM权限管理 (PS : 这篇博客里面的实现方式没有使用框架,完全是手写的授权与认证,可以 ...
- http2提升效率的几个点
1.二进制传输,消息的解析效率更高 2.头部数据压缩,传输效率更高 3.多路复用,可以让请求并发执行 4.服务器推送,可以主动推送数据到浏览器 http2加载图片demo:https://http2. ...