poj 2632 Crashing Robots&&POJ 1573 Robot Motion 【建坐标系的问题】
2015-12-16 19:31
423 查看
Crashing Robots
Description
In a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensure that the robots reach their destinations without crashing into each other. Of course, all warehouses are rectangular, and all robots occupy a circular floor
space with a diameter of 1 meter. Assume there are N robots, numbered from 1 through N. You will get to know the position and orientation of each robot, and all the instructions, which are carefully (and mindlessly) followed by the robots. Instructions are
processed in the order they come. No two robots move simultaneously; a robot always completes its move before the next one starts moving.
A robot crashes with a wall if it attempts to move outside the area of the warehouse, and two robots crash with each other if they ever try to occupy the same spot.
Input
The first line of input is K, the number of test cases. Each test case starts with one line consisting of two integers, 1 <= A, B <= 100, giving the size of the warehouse in meters. A is the length in the EW-direction, and B in the NS-direction.
The second line contains two integers, 1 <= N, M <= 100, denoting the numbers of robots and instructions respectively.
Then follow N lines with two integers, 1 <= Xi <= A, 1 <= Yi <= B and one letter (N, S, E or W), giving the starting position and direction of each robot, in order from 1 through N. No two robots start at the same position.
Figure 1: The starting positions of the robots in the sample warehouse
Finally there are M lines, giving the instructions in sequential order.
An instruction has the following format:
< robot #> < action> < repeat>
Where is one of
L: turn left 90 degrees,
R: turn right 90 degrees, or
F: move forward one meter,
and 1 <= < repeat> <= 100 is the number of times the robot should perform this single move.
Output
Output one line for each test case:
Robot i crashes into the wall, if robot i crashes into a wall. (A robot crashes into a wall if Xi = 0, Xi = A + 1, Yi = 0 or Yi = B + 1.)
Robot i crashes into robot j, if robots i and j crash, and i is the moving robot.
OK, if no crashing occurs.
Only the first crash is to be reported.
Sample Input
Sample Output
Source
Nordic 2005
(1)学习了坐标系和方向对应的 建系方法(这种是按坐标系建,下一题是按二维数组建) 方向仍是 E(1,0),w(0,1),N(0,1),S(0,-1)只是图转了90度;
(2)题意理解错误,输出结果是在对应输入处的,并非最后
(3)两种类型的变量输入按照格式,定义字符类型写错了;
例如:
3 F 1
int ro,re;
char ac;
scanf("%d %c %d",ro,ac,re);
注意 空格
(4) 赋值与等于号写错,手误
另外一道需要建系的题目是
Robot Motion
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
Sample Output
Source
Mid-Central USA 1999
这个系我们按照数组建,起点就是(1,s) 例如: 样例一起点(1,5) 样例二起点(1,1)
这个系不用转,对应着数组很好写,但是W根据数组应该是y变小,而不是x变小,
而N则是x变小,而不是y变大
代码如下
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 9158 | Accepted: 3903 |
In a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensure that the robots reach their destinations without crashing into each other. Of course, all warehouses are rectangular, and all robots occupy a circular floor
space with a diameter of 1 meter. Assume there are N robots, numbered from 1 through N. You will get to know the position and orientation of each robot, and all the instructions, which are carefully (and mindlessly) followed by the robots. Instructions are
processed in the order they come. No two robots move simultaneously; a robot always completes its move before the next one starts moving.
A robot crashes with a wall if it attempts to move outside the area of the warehouse, and two robots crash with each other if they ever try to occupy the same spot.
Input
The first line of input is K, the number of test cases. Each test case starts with one line consisting of two integers, 1 <= A, B <= 100, giving the size of the warehouse in meters. A is the length in the EW-direction, and B in the NS-direction.
The second line contains two integers, 1 <= N, M <= 100, denoting the numbers of robots and instructions respectively.
Then follow N lines with two integers, 1 <= Xi <= A, 1 <= Yi <= B and one letter (N, S, E or W), giving the starting position and direction of each robot, in order from 1 through N. No two robots start at the same position.
Figure 1: The starting positions of the robots in the sample warehouse
Finally there are M lines, giving the instructions in sequential order.
An instruction has the following format:
< robot #> < action> < repeat>
Where is one of
L: turn left 90 degrees,
R: turn right 90 degrees, or
F: move forward one meter,
and 1 <= < repeat> <= 100 is the number of times the robot should perform this single move.
Output
Output one line for each test case:
Robot i crashes into the wall, if robot i crashes into a wall. (A robot crashes into a wall if Xi = 0, Xi = A + 1, Yi = 0 or Yi = B + 1.)
Robot i crashes into robot j, if robots i and j crash, and i is the moving robot.
OK, if no crashing occurs.
Only the first crash is to be reported.
Sample Input
4 5 4 2 2 1 1 E 5 4 W 1 F 7 2 F 7 5 4 2 4 1 1 E 5 4 W 1 F 3 2 F 1 1 L 1 1 F 3 5 4 2 2 1 1 E 5 4 W 1 L 96 1 F 2 5 4 2 3 1 1 E 5 4 W 1 F 4 1 L 1 1 F 20
Sample Output
Robot 1 crashes into the wall Robot 1 crashes into robot 2 OK Robot 1 crashes into robot 2
Source
Nordic 2005
(1)学习了坐标系和方向对应的 建系方法(这种是按坐标系建,下一题是按二维数组建) 方向仍是 E(1,0),w(0,1),N(0,1),S(0,-1)只是图转了90度;
(2)题意理解错误,输出结果是在对应输入处的,并非最后
(3)两种类型的变量输入按照格式,定义字符类型写错了;
例如:
3 F 1
int ro,re;
char ac;
scanf("%d %c %d",ro,ac,re);
注意 空格
(4) 赋值与等于号写错,手误
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct node { int x,y,w; } map[110]; int mapp[110][110]; int dir[4][2]= {0,1,1,0,0,-1,-1,0}; int main()//建坐标系不会,和方向,做不好; { int t; scanf("%d",&t); while(t--) { memset(mapp,0,sizeof(mapp)); memset(map,0,sizeof(map)); int A,B,n,m,a,b,i,j; char e; scanf("%d%d%d%d",&A,&B,&n,&m); for(i=1; i<=n; i++) { scanf("%d %d %c",&map[i].x,&map[i].y,&e); if(e=='N') map[i].w=0; else if(e=='E') map[i].w=1; else if(e=='S') map[i].w=2; else if(e=='W') map[i].w=3; mapp[map[i].x][map[i].y]=i; } int ro,re,bj1=0,bj2,bj3; char ac;//这个变量明明是char型的,写错了; for(i=1; i<=m; i++) { scanf("%d %c %d",&ro,&ac,&re);//两种类型变量混合输入,,也没注意 if(bj1!=0) continue; if(ac=='L') { for(j=0;j<re;j++) {if(map[ro].w==0) map[ro].w=4; map[ro].w--; } } else if(ac=='R') { for(j=0;j<re;j++) { if(map[ro].w==3) map[ro].w=-1;//这里的赋值与等号写错了 map[ro].w++; } } else if(ac=='F') { for( j=1; j<=re; j++) { if(bj1!=0) break; mapp[map[ro].x][map[ro].y]=0; map[ro].x=map[ro].x+dir[map[ro].w][0]; map[ro].y=map[ro].y+dir[map[ro].w][1]; if(map[ro].x>A||map[ro].x<1||map[ro].y<1||map[ro].y>B) { bj1=1;//我以为输出结果放最后,,,呜呜 printf("Robot %d crashes into the wall\n",ro); break; } else if(mapp[map[ro].x][map[ro].y]!=0) { bj1=1; printf("Robot %d crashes into robot %d\n",ro,mapp[map[ro].x][map[ro].y]); break; } else mapp[map[ro].x][map[ro].y]=ro; } } } if(bj1==0) printf("OK\n"); } }
另外一道需要建系的题目是
Robot Motion
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 11740 | Accepted: 5700 |
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 5 NEESWE WWWESS SNWWWW 4 5 1 SESWE EESNW NWEEN EWSEN 0 0 0
Sample Output
10 step(s) to exit 3 step(s) before a loop of 8 step(s)
Source
Mid-Central USA 1999
这个系我们按照数组建,起点就是(1,s) 例如: 样例一起点(1,5) 样例二起点(1,1)
这个系不用转,对应着数组很好写,但是W根据数组应该是y变小,而不是x变小,
而N则是x变小,而不是y变大
代码如下
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int a,b; struct node { char zb; int step; } map[20][20]; void nono(int w,int m) { int s=w; int t=m; switch(map[s][t].zb) { case'W':t--;break; case 'E':t++;break; case 'S':s++;break; case 'N':s--;break; } if(s<1||s>a||t<1||t>b) { printf("%d step(s) to exit\n",map[w][m].step); return; } else if(map[s][t].step==0) { map[s][t].step=map[w][m].step+1; return nono(s,t); } else if(map[s][t].step!=0) { int q=map[w][m].step+1-map[s][t].step; printf("%d step(s) before a loop of %d step(s)\n",map[s][t].step-1,q); return; } } int main() { int s,i,j; while(scanf("%d %d %d",&a,&b,&s)) { if(a==0&&b==0&&s==0) break; memset(map,0,sizeof(map)); for(i=1; i<=a; i++) { getchar(); for(j=1; j<=b; j++) { scanf("%c",&map[i][j].zb); map[i][j].step=0; } } map[1][s].step=1; nono(1,s); } return 0; }
相关文章推荐
- 关于FragmentActivity获取getActivity()为nulld饿以及fragment的变量为null的问题
- RTB交接
- 地图和定位 、 iCloud
- Java 应用发布后,需要关注的7个性能指标
- WPARAM和LPARAM
- 【设计模式】——原型模式
- 数据结构之归并排序
- 显式intent和隐式intent的注册
- 删除本地过期图pain
- android appcompat-v7包引发的错误
- 如何在form:input中添加spring message code
- 通讯录 、 传感器
- 1225 数数字
- stand up meeting for beta release plan 12/16/2015
- Linux mysql
- 深入浅出:Linux设备驱动之字符设备驱
- 欢迎使用CSDN-markdown编辑器
- 让程序分别在DEBUG模式和RELEASE模式选择不同代码路径的方法 _DEBUG
- 点击按钮实现图片的切换
- 照片和音频 、 系统邮件、短信