【CodeCraft比赛】Problem 3——INVESCAPE (迷宫BFS)
来源:互联网 发布:粤语歌国语版 知乎 编辑:程序博客网 时间:2024/06/06 20:49
CodeCraft是印度IIT大学举办的一个算法邀请赛(这个大学貌似在印度挺出名,有个笑话:印度某集团的老总谈自己的儿子说,我这个不争气的儿子,考IIT都没考上,我气得没办法,只好把他送到了哈佛。。。囧rz)目前只有这一届。
在人人上看到了ACM-ICPC主页君过年期间比赛的新闻,于是很有兴趣便参加了一下,据官网说还会再搞。第一名200美刀,第二名75美刀。我又折腾了一晚上,3AC拿了第30名,小红花一朵
比赛题目链接(注册后才能查看):http://felicity.iiit.ac.in/web2py/Portal/default/event_home?event_id=5&tab_id=102
题目:
Problem Statement
Sue Storm needs to escape from Victor Von Doom's Maze, which is in the form of a NxN grid. At some cells Sonic Detectors have been installed which will alert the enemy. Sue can stay invisible for an indefinite amount of time but she must not come in contact with these Sonic Detectors. Only possible moves are left, right, up or down. Help her find the way to the exit (N,N) where Ben and Reed are waiting for her.Assume she always starts at (1,1). It is ensured that there will be no detector at (1,1) and (N,N).
INPUT
First line of input contains number of Test Cases T. Each test case begins with N, depicting the size of maze. Then follow N lines. Each of these N lines contains N characters. Jth character in the Ith line is 'D' if there is a Sonic Detector installed or '.' otherwise.OUTPUT
Print exactly T lines each containing either "YES" if she can reach the exit, "NO" otherwise.Constraints:
1 <= T <= 1001 <= N <= 100
Sample Input:
22.D..2.DD.
Output:
YESNO
Limits
Memory Limit : 32MBTime Limit : 1seconds
Soure Code Limit : 5kb
热身题,挺水的一个BFS,从坐标(1,1)——> (n,n),最终能不能走到,手打1AC。
#include <iostream>#include <queue>#include <cstring>using namespace std;const int INF=105;int mapsize=0;int finder=0;char maze[105][105];int visited[105][105];int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};class point{public:int x;int y;};void Initmaze(int x){memset(visited,0,sizeof(visited));for(int i=1;i<=x;i++){for(int j=1;j<=x;j++){cin>>maze[i][j];}}}void bfs(){point start,end;queue<point> Q;start.x=1;start.y=1;visited[1][1]=1;Q.push(start);while(!Q.empty()){end=Q.front();Q.pop();for(int i=0;i<4;i++){start.x=end.x+dir[i][0];start.y=end.y+dir[i][1];while(start.x>=1 && start.x<=mapsize && start.y>=1 && start.y<=mapsize && maze[start.x][start.y]=='.'){if(visited[start.x][start.y]==0){if(start.x==mapsize && start.y==mapsize){finder=1;return;}visited[start.x][start.y]=1;Q.push(start);}start.x+=dir[i][0];start.y+=dir[i][1];}}}}int main(){int testcase;cin>>testcase;while(testcase--){cin>>mapsize;Initmaze(mapsize);finder=0;if(mapsize==1){cout<<"YES"<<endl;continue;}else{bfs();if(finder==1)cout<<"YES"<<endl;elsecout<<"NO"<<endl;}}return 0;}
- 【CodeCraft比赛】Problem 3——INVESCAPE (迷宫BFS)
- 【CodeCraft比赛】Problem 7——X-man(最长公共子串LCS变种)
- 经典迷宫问题—BFS
- 迷宫问题(maze problem)——深度优先(DFS)与广度优先搜索(BFS)求解
- POJ2251——BFS三维迷宫
- 【poj3984】迷宫问题——bfs/栈
- K - 迷宫问题——BFS
- poj3984——迷宫问题(BFS)
- POJ3984 迷宫问题 —— BFS
- BFS经典例题—迷宫问题
- hud 1010 走迷宫 搜索—bfs
- 搜索练习3 /poj.org/problem 3984 迷宫问题/bfs 回溯找路经
- 3维迷宫的bfs
- uva532--3d迷宫--bfs
- ACM-BFS之逃离迷宫——hdu1728
- BFS——POJ 3984 迷宫问题 解题题解
- POJ——3984迷宫问题(BFS+回溯)
- 广度搜索bfs——百炼10:迷宫问题
- java流程控制语句
- 程序优化的方法(C/C++)
- IIS中找不到web扩展服务ASP.NET v2.0.50727
- 2013年02月17日 工作总结
- Extjs4.1:模式窗口的设置
- 【CodeCraft比赛】Problem 3——INVESCAPE (迷宫BFS)
- 说说O2O(1):O2O四大业务模式
- 说说O2O(2):O2O和二维码
- 说说O2O(3):O2O的社会化营销
- Matlab和C混合编程
- 说说O2O(4):电商VS零售
- 说说O2O(5):消费体验和支付
- 说说O2O(6):O2O的本质
- 说说O2O(7):出版社的O2O破局