hdu 2822 ~!!!!!!坑死我
首先 在此哀悼。。。 为我逝去的时间哀悼。。。 每一步都确定再去写下一步吧。。。日狗
不过还是有点收获的。。 对优先队列的使用 有了进一步的理解
先上代码
#include<iostream>
#include<cstdio>
#include<queue>
#include<string.h>
using namespace std;
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
char mapp[1001][1001];
int vis[1001][1001],n,m,sx,sy,ex,ey;
struct node
{
int x,y;
int time;
friend bool operator < (node a,node b)
{
return a.time>b.time;
}
};
int bfs()
{
int i,j;
priority_queue<node> q;
memset(vis,0,sizeof(vis));
vis[sx][sy]=1;
node t,stu;
stu.x=sx;
stu.y=sy;
stu.time=0;
q.push(stu);
while(!q.empty())
{
t=q.top();
q.pop();
if(t.x == ex&&t.y == ey) return t.time;
for(i=0;i<4;i++)
{
stu.x=t.x+dir[i][0];
stu.y=t.y+dir[i][1];
if(vis[stu.x][stu.y]==1||stu.x<=0||stu.x>n||stu.y<=0||stu.y>m) continue;
vis[stu.x][stu.y]=1;
if(mapp[stu.x][stu.y]=='.')
{
stu.time=t.time+1;
// cout<<stu.x<<' '<<stu.y<<endl;
}
else stu.time=t.time;
// if(mapp[stu.x][stu.y]=='X') stu.tmp=1;
q.push(stu);
}
}
return 0;
}
int main()
{
while(~scanf("%d %d",&n,&m))
{
if(n==0||m==0) break;
int i,j;
for(i=1;i<=n;i++)
{
scanf("%s",mapp[i]+1);////这里比较重要 注意题目给的题目于自己写的地图的位置关系(这里相当于指针的应用。。)
}
scanf("%d %d",&sx,&sy);
scanf("%d %d",&ex,&ey);
printf("%d\n",bfs());
}
return 0;
}
总的来说 对于优先队列的有了更深的理解 (按权优先的策略 后来的点的位置可能更前)
hdu 2822 ~!!!!!!坑死我的更多相关文章
- 【Python3爬虫】百度一下,坑死你?
一.写在前面 这个标题是借用的路人甲大佬的一篇文章的标题(百度一下,坑死你),而且这次的爬虫也是看了这篇文章后才写出来的,感兴趣的可以先看下这篇文章. 前段时间有篇文章<搜索引擎百度已死> ...
- HDU 2822 (BFS+优先队列)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2822 题目大意:X消耗0,.消耗1, 求起点到终点最短消耗 解题思路: 每层BFS的结点,优先级不同 ...
- hdu 2822 Dogs
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2822 Dogs Description Prairie dog comes again! Someda ...
- hdu - 2822 Dogs (优先队列+bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=2822 给定起点和终点,问从起点到终点需要挖几次只有从# 到 .或者从. 到 . 才需要挖一次. #includ ...
- 一些Layout的坑。坑死我自己了
iOS这个东西,初学感觉,还好还好,然后一年之后再来修复一下初学的时候的代码,我只是感觉头很晕- - 别扶我. AutoLayout的坑,明明以前都没有的!!!升了iOS10就突然发现了这个坑,其实也 ...
- JQuery中动态生成元素的绑定事件(坑死宝宝了)
今天在做项目的时候,遇到了一个前端的问题,坑了我好长时间没有解决,今天就记录于此,也分享给大家. 问题是这样的,首先看看我的界面,有一个初始印象: 下面是操作列所对应的JS代码: { "da ...
- ZOJ问题(坑死了)
ZOJ问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- 那些年,坑死自己的事之fread/fwrite
今天继续看牛人做过的东西,这个小程序并不大,加上相当多的注释行,才5000多行.这个小程序是在linux下实现的,之前自己也一直用vi来看并加以更加详细的注释,但是效率实在太低.于是将其转移到wind ...
- 坑死我啊,一个WPF Adorner使用注意事项
1.见鬼了? 项目中遇到这样的要求,一个Button用一个Adorner装饰,这个Adorner上又有一个Button,如下面这样 此时,我们在点击小Button的时候只希望处理小Button的事件, ...
随机推荐
- Nfs固定端口 nfs 端口公网映射
- 【转载】迄今为止把同步/异步/阻塞/非阻塞/BIO/NIO/AIO讲的这么清楚的好文章(快快珍藏)
原文链接:https://www.cnblogs.com/lixinjie/p/10811219.html 常规的误区 假设有一个展示用户详情的需求,分两步,先调用一个HTTP接口拿到详情数据,然后使 ...
- NET 4.5 中新增的特性调用者信息特性CallerMemberNameAttribute/CallerFilePathAttribute/CallerLineNumberAttribute
标题中所说的三个特性 CallerMemberNameAttribute / CallerFilePathAttribute / CallerLineNumberAttribute 我们统称为调用者信 ...
- Java基础 hello world基础实例
JDK :OpenJDK-11 OS :CentOS 7.6.1810 IDE :Eclipse 2019‑03 typesetting :Markdown code ...
- QCamera检测摄像头
The QCamera class provides interface for system camera devices. More... Header: #include <QCamera ...
- TeslaManage 2.0编译日志
1>------ 已启动全部重新生成: 项目: TeslaManage, 配置: Debug x64 ------1> Moc'ing teslamanage.h...1> Uic' ...
- 一秒解决--------No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
在打war包时候遇到错误: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.0:compile (d ...
- python flask框架学习——开启debug模式
学习自:知了课堂Python Flask框架——全栈开发 1.flask的几种debug模式的方法 # 1.app.run 传参debug=true app.run(debug=True) #2 设置 ...
- window下安装docker
下载docker toolbox https://mirrors.aliyun.com/docker-toolbox/windows/docker-toolbox/ 1,.双击安装DockerTool ...
- 使用SampleRateConverter对音频采样率进行转换
java sound resource SampleRateconverter.java(接近于官方源码) 输入目标采样率,输入文件,输出文件.食用方便;p 比如 SampleRateConverte ...