hdu 2822 Dogs
来源:互联网 发布:漂流教室 知乎 编辑:程序博客网 时间:2024/06/05 02:15
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2822
bfs+优先队列。。。
走
#include<algorithm>#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio>#include<vector>#include<queue>#include<map>using std::cin;using std::cout;using std::endl;using std::find;using std::sort;using std::map;using std::pair;using std::vector;using std::multimap;using std::priority_queue;#define pb(e) push_back(e)#define sz(c) (int)(c).size()#define mp(a, b) make_pair(a, b)#define all(c) (c).begin(), (c).end()#define iter(c) decltype((c).begin())#define cls(arr,val) memset(arr,val,sizeof(arr))#define cpresent(c, e) (find(all(c), (e)) != (c).end())#define rep(i, n) for (int i = 0; i < (int)(n); i++)#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)const int N = 1010;typedef unsigned long long ull;const int dx[] = { 0, 0, -1, 1 }, dy[] = { -1, 1, 0, 0 };bool vis[N][N];char rec[N][N];int m, n, Sx, Sy, Dx, Dy;struct Node { int x, y, s; Node(int i = 0, int j = 0, int k = 0) :x(i), y(j), s(k) {} bool operator<(const Node &a) const { return s > a.s; }};void bfs() { cls(vis, false); priority_queue<Node> que; que.push(Node(Sx, Sy, 0)); vis[Sx][Sy] = true; while (!que.empty()) { Node tmp = que.top(); que.pop(); if (tmp.x == Dx && tmp.y == Dy) { printf("%d\n", tmp.s); return; } rep(i, 4) { int nx = tmp.x + dx[i], ny = tmp.y + dy[i]; if (nx < 0 || nx >= m || ny < 0 || ny >= n || vis[nx][ny]) continue; if (rec[nx][ny] == 'X') que.push(Node(nx, ny, tmp.s)); else que.push(Node(nx, ny, tmp.s + 1)); vis[nx][ny] = true; } }}int main() {#ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w+", stdout);#endif while (~scanf("%d %d", &m, &n) && m + n) { rep(i, m) scanf("%s", rec[i]); scanf("%d %d %d %d", &Sx, &Sy, &Dx, &Dy); Sx--, Sy--, Dx--, Dy--; bfs(); } return 0;}
0 0
- hdu 2822 dogs
- hdu 2822 Dogs
- HDU 2822 Dogs
- hdu 2822 Dogs
- hdu 2822 Dogs
- HDU 2822 Dogs
- HDU 2822 Dogs
- hdu 2822 Dogs
- HDU 2822 Dogs
- hdu 2822 Dogs 优先队列
- hdu 2822 Dogs(搜索)
- HDU 2822 Dogs【两次bfs】
- HDU 2822 Dogs【两次bfs】
- hdu 2822 Dogs(优先队列)
- hdu 2822 Dogs(bfs+优先队列)
- hdu 2822 Dogs(BFS + 优先队列)
- hdu 2822 Dogs (优先队列 + BFS)
- hdu 2822 Dogs【优先队列+Bfs】
- MVC发送邮件
- 展讯8810平台:mstar2133_jt_397_2key调试(input子系统)
- 2015062810 - 张巡
- Java添加事件监听的四种方法代码实例
- [Leetcode]-Reverse Integer
- hdu 2822 Dogs
- C语言宏定义中的字符串替换
- 六月英语总结
- 别跟我这交活儿
- linux程序设计——make命令和makefile文件(第九章)
- iOS七大手势之(平移、捏合、轻扫、屏幕边缘轻扫)手势识别器方法
- TCP拥塞控制和流量控制相关知识点
- 转载中国地理信息产业现状、问题与出路分析
- Mybatis学习心得