POJ1573 Robot Motion(dfs)
来源:互联网 发布:snmpv3 java 编辑:程序博客网 时间:2024/05/20 05:11
Robot Motion
题目链接:
http://poj.org/problem?id=1573
解题思路:
简单模拟即可。
AC代码:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int dx[] = {0,-1,0,1},dy[] = {-1,0,1,0};char maze[11][11];int vis[11][11];int m,n,ans;void dfs(int x,int y){ //cout<<x<<y<<endl; if(x<0 || x>=m || y<0 || y>=n){ printf("%d step(s) to exit\n",ans); return ; } if(vis[x][y]){ printf("%d step(s) before a loop of %d step(s)\n",vis[x][y]-1,ans-vis[x][y]+1); return ; } ans++; if(maze[x][y] == 'W'){ vis[x][y] = ans; dfs(x+dx[0],y+dy[0]); } else if(maze[x][y] == 'N'){ vis[x][y] = ans; dfs(x+dx[1],y+dy[1]); } else if(maze[x][y] == 'E'){ vis[x][y] = ans; dfs(x+dx[2],y+dy[2]); } else{ vis[x][y] = ans; dfs(x+dx[3],y+dy[3]); }}int main(){ int x; while(scanf("%d%d%d",&m,&n,&x),m+n+x){ for(int i = 0; i < m; i++) scanf("%s",maze[i]); ans = 0; memset(vis,0,sizeof(vis)); dfs(0,x-1); } return 0;}
1 0
- POJ1573 Robot Motion(dfs)
- POJ1573--Robot Motion(模拟)
- poj1573&&hdu1035 Robot Motion(模拟)
- poj1573——Robot Motion(模拟)
- POJ1573 Robot Motion (模拟 | 递归)
- POJ1573--模拟--Robot Motion
- poj1573 Robot Motion (模拟)
- poj1573 Robot Motion
- poj1573--Robot Motion
- poj1573 Robot Motion
- poj1573 Robot Motion
- POJ1573 - Robot Motion
- POJ1573 Robot Motion(模拟)
- poj1573 Robot Motion
- poj1573 Robot Motion 模拟
- poj1573--Robot Motion
- poj1573 Robot Motion
- POJ1573 Robot Motion
- 十三周项目二 成绩处理
- Android-sharedUserId数据权限
- 批量获取及验证HTTP代理Python脚本
- 第十三周项目四(3):选择排序
- 微软chart数据绑定
- POJ1573 Robot Motion(dfs)
- RMI远程方法调用
- 代码轻视频系列#001
- 深入理解Linux修改hostname
- Android一滴滴筆記(不間斷更新)
- UVA 129 Kypton Factor dfs构造解
- Notification中PendingIntent的陷阱
- 用java实现图片渐变叠加(3种方法)
- 校园网又抽风了,没有电影看?