hdu 2822 Dogs(优先队列)
来源:互联网 发布:微谱数据库免费入口 编辑:程序博客网 时间:2024/06/05 04:05
题目链接:hdu2822
会优先队列话这题很容易AC。。。。
#include<stdio.h>#include<string.h>#include<queue>#include<algorithm>#define N 1005using namespace std;char map[N][N];int v[N][N],d[4][2] = { {-1,0},{1,0},{0,-1},{0,1} };int begin_x,begin_y,end_x,end_y,n,m;struct node{ int x,y,step; friend bool operator < (node a,node b) { return a.step > b.step; }};void bfs(){ memset(v,0,sizeof(v)); priority_queue <node> q; node s,temp; s.x = begin_x; s.y = begin_y; s.step = 0; v[s.x][s.y] = 1; q.push(s); while(!q.empty()) { temp = q.top(); q.pop(); if(s.x == end_x && s.y == end_y) { printf("%d\n",s.step); return ; } for(int i= 0 ; i < 4 ; i ++) { s = temp; s.x += d[i][0]; s.y += d[i][1]; if(s.x < 0 || s.x >= n || s.y < 0 || s.y >= m || v[s.x][s.y]) continue; v[s.x][s.y] = 1; if(map[s.x][s.y] == '.') s.step ++; q.push(s); } }}int main(){ int i; while(scanf("%d%d",&n,&m) && (n + m)) { for(i = 0 ; i < n ; i ++) scanf("%s",map[i]); scanf("%d%d%d%d",&begin_x,&begin_y,&end_x,&end_y); begin_x -- ; begin_y --; end_x -- ; end_y --;//题目给出的坐标都是从1开始计算的 bfs(); } return 0;}
- hdu 2822 Dogs(优先队列)
- hdu 2822 Dogs(bfs+优先队列)
- HDU 2822 Dogs(优先队列)
- hdu 2822 Dogs 优先队列
- hdu 2822 Dogs(BFS + 优先队列)
- hdu 2822 Dogs (优先队列 + BFS)
- hdu 2822 Dogs【优先队列+Bfs】
- hdu 2824 Dogs(BFS, 优先队列优化)
- hdoj 2822 Dogs(BFS+优先队列)
- hdu2822((Dogs))优先队列
- hdu2822 Dogs【优先队列】
- hdu 2822 Dogs(搜索)
- hdu 1008 Dogs 广度优先搜索
- hdu 2822 dogs
- hdu 2822 Dogs
- HDU 2822 Dogs
- hdu 2822 Dogs
- hdu 2822 Dogs
- 【rmzt】单车&&青春xp主题
- Oracle 基础 语句大全
- win7 远程桌面 连接ubuntu
- HDU-2095
- as3与javaweb结合开发属于个人的类YY的网站(一)
- hdu 2822 Dogs(优先队列)
- SEO者固步自封的势态越发严重是谁的错
- 人生若只如初见
- 无向图 双连通分量的模板
- 锁定表操作
- 企业类网站如何在百度首页生存?
- 从逆向分析角度看C++虚函数
- 非深入探寻Java反射机制 (Constructor)
- hdu-1004-Let the Balloon Rise