Mutant Flatworld Explorers
来源:互联网 发布:文本编辑 mac 编辑:程序博客网 时间:2024/05/01 10:53
直接模拟
Background
Robotics, robot motion planning, and machine learning are areas that cross the boundaries of many of the subdisciplines that comprise Computer Science: artificial intelligence, algorithms and complexity, electrical and mechanical engineering to name a few. In addition, robots as ``turtles'' (inspired by work by Papert, Abelson, and diSessa) and as ``beeper-pickers'' (inspired by work by Pattis) have been studied and used by students as an introduction to programming for many years.
This problem involves determining the position of a robot exploring a pre-Columbian flat world.
The Problem
Given the dimensions of a rectangular grid and a sequence of robot positions and instructions, you are to write a program that determines for each sequence of robot positions and instructions the final position of the robot.
A robot position consists of a grid coordinate (a pair of integers: x-coordinate followed by y-coordinate) and an orientation (N,S,E,W for north, south, east, and west). A robot instruction is a string of the letters 'L', 'R', and 'F' which represent, respectively, the instructions:
- Left: the robot turns left 90 degrees and remains on the current grid point.
- Right: the robot turns right 90 degrees and remains on the current grid point.
- Forward: the robot moves forward one grid point in the direction of the current orientation and mantains the same orientation.
The direction North corresponds to the direction from grid point (x,y) to grid point (x,y+1).
Since the grid is rectangular and bounded, a robot that moves ``off'' an edge of the grid is lost forever. However, lost robots leave a robot ``scent'' that prohibits future robots from dropping off the world at the same grid point. The scent is left at the last grid position the robot occupied before disappearing over the edge. An instruction to move ``off'' the world from a grid point from which a robot has been previously lost is simply ignored by the current robot.
The Input
The first line of input is the upper-right coordinates of the rectangular world, the lower-left coordinates are assumed to be 0,0.
The remaining input consists of a sequence of robot positions and instructions (two lines per robot). A position consists of two integers specifying the initial coordinates of the robot and an orientation (N,S,E,W), all separated by white space on one line. A robot instruction is a string of the letters 'L', 'R', and 'F' on one line.
Each robot is processed sequentially, i.e., finishes executing the robot instructions before the next robot begins execution.
Input is terminated by end-of-file.
You may assume that all initial robot positions are within the bounds of the specified grid. The maximum value for any coordinate is 50. All instruction strings will be less than 100 characters in length.
The Output
For each robot position/instruction in the input, the output should indicate the final grid position and orientation of the robot. If a robot falls off the edge of the grid the word ``LOST'' should be printed after the position and orientation.
Sample Input
5 31 1 ERFRFRFRF3 2 NFRRFLLFFRRFLL0 3 WLLFFFLFLFL
Sample Output
1 1 E3 3 N LOST2 3 S
#include<bits/stdc++.h>using namespace std;char net[1000][1000];int main(){memset(net,'.',sizeof(net));int x,y;cin >> x >> y;char pos;int x_,y_;string str;while(cin >> x_ >> y_ >> pos >> str){int len=str.length();bool check=true;for(int i=0; i < len; i++){if(str[i]=='L'){if(pos=='N') pos='W';else if(pos=='S') pos='E';else if(pos=='W') pos='S';else if(pos=='E') pos='N';}else if(str[i]=='R'){if(pos=='N') pos='E';else if(pos=='S') pos='W';else if(pos=='W') pos='N';else if(pos=='E') pos='S';}else if(str[i]=='F'){int x_a=x_,y_a=y_;if(pos=='N') y_++;else if(pos=='S') y_--;else if(pos=='W') x_--;else if(pos=='E') x_++;if(net[x_a][y_a]=='#'&&(x_<0||x_>x||y_<0||y_>y)){x_=x_a;y_=y_a;continue;}if(x_<0||x_>x||y_<0||y_>y){x_=x_a;y_=y_a;check=false;net[x_a][y_a]='#';break;}}}cout << x_ << " " << y_ << " " << pos;if(check==false) cout << " LOST";cout << endl;}}
- Mutant Flatworld Explorers
- Uva-118-Mutant Flatworld Explorers
- UVA 118 Mutant Flatworld Explorers
- UVa 118 - Mutant Flatworld Explorers
- UVa 118|Mutant Flatworld Explorers|
- UVa Problem 118 - Mutant Flatworld Explorers
- UVa 118 Mutant Flatworld Explorers (模拟机器人移动)
- Check if a File is in Internet Explorers Cache
- 'Visual Studio Explorers and Designers Package' has failed to load properly
- Web应用漏洞fuzz工具 – teenage mutant ninja turtles V 1.5
- 枚举进程句柄File,Section,Mutant,Timer关闭Mutex句柄实现游戏多开
- 枚举进程句柄File,Section,Mutant,Timer关闭Mutex句柄实现游戏多开
- UVa 1368 - DNA Consensus String
- C#之伪静态实现
- 装饰模式(DecoratorPattern)与继承(Extends)的区别
- Python zipfile报错问题
- declare-styleable自定义控件属性
- Mutant Flatworld Explorers
- 一个程序员的多年珍藏
- python 坑:list的扩展
- Android Fragment完全解析
- Silverlight读取XML
- 超链接a标签另一个常被使用的功能:锚点(name和#)
- POJ 3261 Milk Patterns 后缀数组
- iOS 7最佳实践:一个天气App案例
- Dollars