rober ration
来源:互联网 发布:易云网络验证 编辑:程序博客网 时间:2024/06/05 09:12
Problem Description
A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The possible instructions are
N north (up the page)
S south (down the page)
E east (to the right on the page)
W west (to the left on the page)
For example, suppose the robot starts on the north (top) side of Grid 1 and starts south (down). The path the robot follows is shown. The robot goes through 10 instructions in the grid before leaving the grid.
Compare what happens in Grid 2: the robot goes through 3 instructions only once, and then starts a loop through 8 instructions, and never exits.
You are to write a program that determines how long it takes a robot to get out of the grid or how the robot loops around.
Input
There will be one or more grids for robots to navigate. The data for each is in the following form. On the first line are three integers separated by blanks: the number of rows in the grid, the number of columns in the grid, and the number of the column in which the robot enters from the north. The possible entry columns are numbered starting with one at the left. Then come the rows of the direction instructions. Each grid will have at least one and at most 10 rows and columns of instructions. The lines of instructions contain only the characters N, S, E, or W with no blanks. The end of input is indicated by a row containing 0 0 0.
Output
For each grid in the input there is one line of output. Either the robot follows a certain number of instructions and exits the grid on any one the four sides or else the robot follows the instructions on a certain number of locations once, and then the instructions on some number of locations repeatedly. The sample input below corresponds to the two grids above and illustrates the two forms of output. The word "step" is always immediately followed by "(s)" whether or not the number before it is 1.
Sample Input
3 6 5NEESWEWWWESSSNWWWW4 5 1SESWEEESNWNWEENEWSEN0 0
Sample Output
10 step(s) to exit3 step(s) before a loop of 8 step(s)
#include<iostream>#include<stdio.h>using namespace std;int mp[11][11];char mmpp[11][11];int s[11][11];int n,m,k,cnt;int dn[2]={0,-1};int ds[2]={0,1};int de[2]={0,1};int dw[2]={0,-1};void DFS(int x,int y){ int q,p; if(x<0||x>=n||y<0||y>=m||mp[x][y]==1) { if(mp[x][y]==1) printf("%d step(s) before a loop of %d step(s)\n",s[x][y]-1,cnt-s[x][y]); else printf("%d step(s) to exit\n",cnt-1); } else { s[x][y]=cnt; cnt++; if(mmpp[x][y]=='W') { q=x+dw[0]; p=y+dw[1]; } else if(mmpp[x][y]=='E') { q=x+de[0]; p=y+de[1]; } else if(mmpp[x][y]=='N') { q=x+dn[1]; p=y+dn[0]; } else { q=x+ds[1]; p=y+ds[0]; } mp[x][y]=1; DFS(q,p); }}int main(){ //freopen("a.in","r",stdin); int i,y1,x1; while(scanf("%d %d %d",&n,&m,&k)==3&&n+m) { memset(mp,0,sizeof(mp)); memset(s,0,sizeof(s)); for(i=0;i<n;i++) scanf("%s",mmpp[i]); cnt=1; x1=0;y1=k-1; DFS(x1,y1); } return 0;}
- rober ration
- House Rober
- Ration Rose
- 成功安装RATION ROSE
- Ration rose 破解
- Ration安装及破解
- UML Ration Rose
- ration rose2003 安装方法
- 日志log ration 转储
- Win10安装Ration Rose2007
- **[Lintcode] House Rober III 打劫房屋 III
- Ration Rose2003安装及破解
- Ration Rose 2007 直接下载
- 在win7下安装ration 2003
- IBM Ration Rhapsody 软件的环境配置
- 读-Rober C.Martin-代码整洁之道
- 关于IBM Ration Function Tester中DEBUG报异常问题的解决
- Ration和深蓝的下午茶:取石子游戏&异或和
- tar命令使用及tar实现全备份和增量备份
- Java中的向上转型和向下转型
- 【Cocos2d-X开发学习笔记】第23期:事件处理机制之按键事件
- 一个旋转的圆形的CSS菜单代码
- cocos2d-x2.1.2动画与精灵表单
- rober ration
- dump和restore命令实现全备、增量备份和差异备份
- 整理一些好用的css, javascript资源网站等
- CentOS 6.4 安装 Fcitx4.0(结合网上的教程自己实践做的总结)
- 那些数学老师忘了告诉你的事情
- What’s The Memristor And Where It Comes From
- MyEclipse的 at com.genuitec.eclipse.ast.deploy.core.Deployment.<init>错误解决办法。
- 浅谈:JavaScript中分号的省略规则
- Android apk多渠道验证工具 - 不提供工具,只提供源码