Connection Status:
Competition Arena > Robot
TCCC '03 Finals · 2003-04-05 · by lars2520 · Dynamic Programming, Simulation
Class Name: Robot
Return Type: int
Method Name: getProb
Arg Types: (vector<string>, int, int, int)
Problem Statement

Problem Statement

A very simple robot moves in a random cardinal or diagonal direction (cardinal directions are north, south, east and west, and diagonal directions are north-east, north-west, south-east, and south-west) each timestep. Thus, the robot has a 12.5% chance of trying to move in each of 8 directions. If the robot moves in a diagonal direction, it moves one unit left or right, and then one unit up or down (both in the same timestep), depending on the direction. If the robot moves in a cardinal direction, it moves 1 unit in that direction. Given a String[], floor representing a bird's eye view of the floor, you are to determine the probability that the robot will end up at location (x,y) after time timesteps. You should return the probability as truncated parts per 1000. In other words, if act is the actual probability, return (int)(act*1000). Each character in floor represents one square unit of the floor and is an 'X', an 'R' or a '.', representing an obstacle, a robot, or an open floor, respectively. There is only one robot, and if it attempts to move into a square occupied by an obstacle, or it attempts to move diagonally when there is an obstacle in either of the locations that it is moving between it instead does not move. More specifically, the robot may move diagonally, if and only if the locations that it moves between and to are clear. Also, the robot can not move outside of the floor. In other words, consider floor to be surrounded by obstacles. Location (x,y) is represented by character x of element y of floor.

Constraints

  • floor has between 1 and 50 elements, inclusive.
  • Each element of floor has between 1 and 50 characters, inclusive.
  • Each element of floor has the same number of characters.
  • Each character of each element of floor is either a '.', an 'R', or an 'X'.
  • There is exactly one 'R' in floor.
  • The input will not cause rounding errors. In other words, the actual double probability will not be within .000001 of .xxx000, where the x's represent digits, unless it is exactly 0.
  • time will be between 0 and 1000, inclusive.
  • x will be between 0 and the length of the first element of floor - 1.
  • y will be between 0 and the length floor - 1.
Examples
0)
{"R.XX",
 "..XX",
 "..XX",
 "...."}
3
3
7
Returns: 1
1)
{".....", ".X...", ".R..."}
1
2
619
Returns: 71
2)
{"...", "..X", "X..", ".X.", "...", "...", "...", "X..", "X..", "X..", "...", "X.X", "...", ".X.", "...", ".R.", ".XX", "...", "...", "...", ".X.", ".X.", "...", "...", "...", "X..", ".XX", "...", ".X.", "...", "..X", "X..", "...", "...", ".XX", "X..", "...", "..X", "..X", "X.X", "...", "..."}
1
15
937
Returns: 16
3)
{"..X..X....X.", "..X....XX.R."}
10
1
633
Returns: 72
4)
{"...X...R..."}
7
0
602
Returns: 142

Submissions are judged against all 41 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Robot with a public method int getProb(vector<string> floor, int x, int y, int time) · 41 test cases · 2 s / 256 MB per case

Submitting as anonymous