POJ 1573:Robot Motion:简单模拟
来源:互联网 发布:网络专题的版式 编辑:程序博客网 时间:2024/05/21 18:35
Robot Motion
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 9969 Accepted: 4828
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 0
Sample Output
10 step(s) to exit3 step(s) before a loop of 8 step(s)
Source
Mid-Central USA 1999
无脑模拟。
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>int hang,lie,ru;int a[15][15],b[15][15],step;char tem[15];void init(){int i,j;step=0;memset(a,0,sizeof(a));memset(b,-1,sizeof(b));for(i=1;i<=hang;i++){scanf("%s",tem);for(j=0;j<lie;j++){switch(tem[j]){case'N':a[i][j+1]=1;break;case'S':a[i][j+1]=2;break;case'W':a[i][j+1]=3;break;case'E':a[i][j+1]=4;break;default:break;};}}}void comput(int x,int y){int i,j;if(x==0||x==hang+1||y==0||y==lie+1){printf("%d step(s) to exit\n",step);return;}if(b[x][y]>=0){printf("%d step(s) before a loop of %d step(s)\n",b[x][y],step-b[x][y]);return ;}b[x][y]=step; step++;switch(a[x][y]){case 1:comput(x-1,y);break;case 2:comput(x+1,y);break;case 3:comput(x,y-1);break;case 4:comput(x,y+1);break;default:break;};}int main(){int i,j;while(scanf("%d%d%d",&hang,&lie,&ru)!=EOF&&(hang||lie||ru)){init();comput(1,ru);}return 0;}
0 0
- POJ 1573:Robot Motion:简单模拟
- POJ 1573 Robot Motion模拟
- POJ 1573 Robot Motion 模拟
- POJ 1573 Robot Motion 模拟
- POJ 1573 Robot Motion 模拟
- POJ 1573-Robot Motion(模拟)
- poj-1573-Robot Motion--模拟
- POJ 1573 Robot Motion(模拟)
- poj 1573 Robot Motion(模拟)
- poj 1573 Robot Motion 模拟
- POJ 1573 && hdu 1035 Robot Motion【简单模拟】
- POJ 1573 Robot Motion 递归模拟
- poj 1573 Robot Motion(模拟题)
- POJ 1573 Robot Motion (经典模拟)
- POJ 1573 Robot Motion(模拟)
- HDU 1035 && poj 1573 Robot Motion【模拟】
- POJ 1573 Robot Motion(模拟水题)
- POJ 1573 Robot Motion 水模拟
- 【极客学院每日1课 】Java入门与常用技巧
- MySQL性能优化的21个最佳实践
- php模拟认证h3c校园网
- Web前端博客,企业架构博客
- 四川:春暖花开 乐山花卉市场鲜花迎来销售旺季
- POJ 1573:Robot Motion:简单模拟
- 下载量已超越千万的爆红游戏2048(同名小3传奇、1024)源代码解密和下载(第二篇)
- JAVA GC原理
- crontab命令用法
- JavaScript图表FusionCharts的属性介绍
- 第6周作业3-Fibonacci数列
- 橘红色的光芒在它
- 推荐一款好工具:16进制字节搜索工具 C#的效率
- Stl的erase