Connection Status:
Competition Arena > CrazyBot
SRM 425 · 2008-11-12 · by crazyb0y · Brute Force, Simple Search, Iteration
Class Name: CrazyBot
Return Type: double
Method Name: getProbability
Arg Types: (int, int, int, int, int)
Problem Statement

Problem Statement

An out-of-control robot is placed on a plane, and it takes n random steps. At each step, the robot chooses one of four directions randomly and moves one unit in that direction. The probabilities of the robot choosing north, south, east or west are north, south, east and west percent, respectively.

The robot's path is considered simple if it never visits the same point more than once. (The robot's starting point is always the first visited point.) Return a double containing the probability that the robot's path is simple. For example, "EENE" and "ENW" are simple, but "ENWS" and "WWWWSNE" are not ('E', 'W', 'N' and 'S' represent east, west, north and south, respectively).

Notes

  • Your return must have relative or absolute error less than 1E-9.

Constraints

  • n will be between 1 and 14, inclusive.
  • east will be between 0 and 100, inclusive.
  • west will be between 0 and 100, inclusive.
  • south will be between 0 and 100, inclusive.
  • north will be between 0 and 100, inclusive.
  • The sum of east, west, south and north will be 100.
Examples
0)
1
25
25
25
25
Returns: 1.0

The robot only takes one step, so it never visits a point more than once.

1)
2
25
25
25
25
Returns: 0.75

The robot will visit its starting point twice only if the two moves are in opposite directions.

2)
7
50
0
0
50
Returns: 1.0

Here, the only possible directions are north and east, so the robot will never visit the same point twice.

3)
14
50
50
0
0
Returns: 1.220703125E-4

Here, the only possible directions are east and west. The only two available paths are "EEEEEEEEEEEEEE" and "WWWWWWWWWWWWWW". The probability is equal to 2 / (2^14).

4)
14
25
25
25
25
Returns: 0.008845493197441101

The probability is quite small for n=14.

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

Coding Area

Language: C++17 · define a public class CrazyBot with a public method double getProbability(int n, int east, int west, int south, int north) · 87 test cases · 2 s / 256 MB per case

Submitting as anonymous