HDOJ1035 Robot Motion(模拟题,字符串)
2017-08-11 22:28
465 查看
HDOJ 1035
给出地图规模n * m, 给出入口坐标(0,y),遵循以下规则,求解机器人能否走出地图。若能,输出走出地图所需要的步数,若不能,输出进入循环前走的步数和循环的步数。
规则:
若当前格子为N,则只能向上走,若为S向下走,E向右走,W向左走。
模拟题:
给出地图规模n * m, 给出入口坐标(0,y),遵循以下规则,求解机器人能否走出地图。若能,输出走出地图所需要的步数,若不能,输出进入循环前走的步数和循环的步数。
规则:
若当前格子为N,则只能向上走,若为S向下走,E向右走,W向左走。
模拟题:
#include<iostream> #include<string.h> #include<algorithm> using namespace std; char mp[20][20]; int mat[20][20]; int main(){ int n,m,t,i,step; while(cin>>n>>m>>t &&(n||m)){ int flag=0; memset(mat,0,sizeof(mat)); memset(mp,0,sizeof(mp)); for(i=0;i<n;i++) scanf("%s",mp[i]); step=1; int x,y,loop=0; x=0,y=t-1; //起点坐标 while(1){ if(mp[x][y]=='N' && !mat[x][y]){ mat[x][y]=step; x--; } else if(mp[x][y]=='S'&&!mat[x][y]){ mat[x][y]=step; x++; } else if(mp[x][y]=='E' c130 &&!mat[x][y]){ mat[x][y]=step; y++; } else if(mp[x][y]=='W'&&!mat[x][y]){ mat[x][y]=step; y--; } else if(mat[x][y]){ //到达了重复点 step--; loop=step-mat[x][y]+1; flag=1; break; } else if(x<0 ||y<0 ||x>=n ||y>=m){ step--; break; } step++; } if(flag) printf("%d step(s) before a loop of %d step(s)\n",step-loop,loop); else printf("%d step(s) to exit\n",step); } return 0; }
相关文章推荐
- hdoj-1035 Robot Motion
- HDOJ---1035 Robot Motion
- HDOJ1035 ( Robot Motion ) 【递归】
- Hdoj 1035 Robot Motion
- HDOJ1035 Robot Motion 【模拟】
- hdoj 1035 Robot Motion
- HDOJ 题目1035 Robot Motion(模拟)
- HDOJ 1035 Robot Motion
- hdoj 1035 Robot Motion(简单题)
- hdoj 1035 Robot Motion 【DFS 暴力】
- HDOJ(1013) ——Digital Roots(字符串模拟题)
- hdoj 1035 Robot Motion
- hdoj 1035 Robot Motion 【DFS】
- hdoj 1035 Robot Motion (DFS+模拟)
- HDOJ HDU 1035 Robot Motion
- hdoj.1274 展开字符串【递归】 2015/05/15
- 十六进制字符串转换成十进制整数 天梯赛模拟题重现一
- hdoj 1238 SubStrings (子字符串问题)
- POJ 1035 Spell checker (字符串模拟)
- hdu1035 Robot Motion (DFS)