noj1010 基本的迷宫问题
来源:互联网 发布:语音识别算法视频教程 编辑:程序博客网 时间:2024/05/21 10:23
The Inescapable Maze
Time Limit:1000ms Memory Limit:65536K
Total Submissions:362 Accepted:138
Description
Jack and his friends were trapped in a maze of amusement park. Please help them to find the right way to escape.
This square maze is reperented as 0,1 text. 0 is a way, 1 is a wall.
The size of maze is N. The entrance at (1,1), the exit at (N,N). You can only escape from exit.
Input
The first line contain three integers, N, x, y. (N<=80)
N is the size of maze. x, y is the Jack and friends's current location.
Your task is to find the way from (x,y) to (N,N)
Output
If you find the way out, print 'Found' then following with the maze model with '#' to show the way.
If you could't find the way, print 'Not Found'.
Sample Input
6 5 20 0 1 1 1 11 0 0 0 0 11 1 1 0 1 11 0 0 0 1 11 0 1 0 1 11 0 1 0 0 0
Sample Output
Found0 0 1 1 1 11 0 0 # # 11 1 1 # 1 11 0 0 # 1 11 0 1 # 1 11 0 1 # # #
#include <iostream>#include<stdio.h>#include<queue>#include<stack>#include<string.h>using namespace std;int t;int m,n;struct point{ int x; int y;}buf;int vis[100][100];int mapp[1000][100];int keep[100][100];int dir[][2]={{1,0},{-1,0},{0,1},{0,-1}};queue<point> q;stack<point >s;int flag;void bfs(){ flag=0; vis[buf.x][buf.y]=1; while(!q.empty()) { for(int i=0;i<4;i++) { buf.x=q.front().x+dir[i][0]; buf.y=q.front().y+dir[i][1]; if(1<=buf.x&&buf.x<=t&&1<=buf.y&&buf.y<=t&& !vis[buf.x][buf.y] &&mapp[buf.x][buf.y]==0) { vis[buf.x][buf.y]=1; keep[buf.x][buf.y]=i; q.push(buf); if(buf.x==t&&buf.y==t) { flag=1; break; } } } q.pop(); if(buf.x==t&&buf.y==t) { flag=1; break; } }}int main(){ memset(vis,0,sizeof(vis)); scanf("%d%d%d",&t,&m,&n); for(int i=1;i<=t;i++) for(int j=1;j<=t;j++) scanf("%d",&mapp[i][j]); buf.x=n; buf.y=m; q.push(buf); bfs(); if(flag==0) printf("Not Found\n"); else { printf("Found\n"); point nbuf={t,t}; s.push(nbuf); while(buf.x!=n||buf.y!=m) { nbuf.x=buf.x-dir[keep[buf.x][buf.y]][0]; nbuf.y=buf.y-dir[keep[buf.x][buf.y]][1]; s.push(nbuf); buf.x=nbuf.x; buf.y=nbuf.y; } while(!s.empty()) { mapp[s.top().x][s.top().y]=2; s.pop(); } for(int i=1;i<=t;i++) for(int j=1;j<=t;j++) { if(mapp[i][j]==0||mapp[i][j]==1) printf("%d",mapp[i][j]); else printf("#"); if(j!=t) printf(" "); if(j==t&&i!=t) printf("\n"); } } return 0;}
0 0
- noj1010 基本的迷宫问题
- NOJ1010 数的计算
- 最基础的poj迷宫问题及基本态度
- 走迷宫的问题
- 迷宫问题的DFS
- 迷宫问题的求解
- 迷宫问题的反思
- 迷宫的路径问题
- 迷宫问题:hdoj1242--BFS基本应用
- 迷宫问题的递归求解
- .数据结构迷宫问题的文档
- 迷宫问题的双向BFS
- 和迷宫类似的问题
- 实验三的迷宫问题
- 迷宫问题(栈的应用)
- 简单的实现迷宫问题
- 简单迷宫问题的求解
- 一般迷宫问题的求解
- C语言_数组
- Oracle RAC 环境下的连接管理
- setDefaultAlphaPixelFormat bug addSpriteFrames 异步加载资源
- [剑指offer]字符串的排列
- 关于台式电脑突然断电后重启,所有软件恢复的秘密
- noj1010 基本的迷宫问题
- php下载
- for(i=1;i<=5;i++)sum=sum+i;详解
- Python 源码剖析(一)—— vs2013 编译 python 源码
- 【排序算法】基数排序(java实现)
- 关于控件三态中悬浮无效的原因!
- 浏览器的渲染原理简介
- java生成随机uuid并保存到文件
- 配置url路径