XDU 1196
来源:互联网 发布:环信 java 服务端 编辑:程序博客网 时间:2024/06/01 15:32
简单迷宫题,貌似哪里写过,So,一遍AC
考点貌似在判断上,或者说,没有。。
#include <iostream>#include <queue>#include <cstring>using namespace std;int vis[31][31];int walls[60][31];int w, h;int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};int main(){cin >> w >> h;while(w){memset(vis, 0, sizeof(vis));memset(walls, 0, sizeof(walls));for(int i = 1; i <= 2*h-1; i++)if(i%2){for(int j = 1; j <= w - 1; j++)cin >> walls[i][j];}elsefor(int j = 1; j <= w; j++)cin >> walls[i][j];vis[1][1] = 1;queue<short> qw;queue<short> qh;qw.push(1); qh.push(1);while(!qw.empty()){short x = qh.front(), y = qw.front(), step = vis[x][y];qw.pop(); qh.pop();if(x == h && y == w)break;for(int i = 0; i < 4; i++){short newx = x + dir[i][0], newy = y + dir[i][1]; if(newx >= 1 && newx <= h && newy >= 1 && newy <= w){ short tempx = x < newx ? x : newx;short wallx = x == newx ? 2*(tempx-1)+1 : 2*tempx;short wally = y < newy ? y : newy;int newstep = step+1;if(!walls[wallx][wally]){if(!vis[newx][newy]){vis[newx][newy] = newstep;qw.push(newy);qh.push(newx);}else if(newstep < vis[newx][newx]){vis[newx][newy] = newstep;}}}}}if(vis[h][w])cout << vis[h][w] << endl;elsecout << "0" << endl;cin >> w >> h;}}
- XDU 1196
- XDU 1010
- XDU 1022
- XDU 1278
- XDU Problem 1016 - Code
- XDU 1010 素数环
- XDU 1008 - 数星星
- XDU 1284 寻找礼物
- XDU Problem 1105 - 打麻将
- XDU 1003 最喜欢的数字
- XDU 1036-神奇的盒子
- XDU Problem 1255 - 数列游戏
- XDU Problem 1063 - Enjoy It
- XDU 挖掘机 线段树求解
- XDU 1024: 最优规则式
- xdu 1068 Clinton’s beliefs
- XDU 1028 G.锘爷考驾照
- 2017XDU初赛网络赛
- 【leetcode】Surrounded Regions
- 由C/C++中的结构体包含数组引申到C/C++堆栈
- Intel-最快线程间数据交换算法,有效避免锁竞争 -- TwoQueues
- Vim高级进阶之ex命令集
- Android中的ListView实现图片文字和按钮
- XDU 1196
- img 灰度阈值变化
- Android开发之DOS命令行的使用
- sed的一些用法
- AndroidManifest.xml文件versionCode和versionName详解
- 构造方法和对象的创建简单例题
- linux之上C内嵌汇编并转换虚拟/物理地址
- 盛大陈天桥:最好的商业模式要深谙“人性”
- Web压力测试工具Siege介绍