Animation
SRM 167 · 2003-10-14 · by dgoodman
Problem Statement
We will be given the initial conditions
by a
We would like an animation of the process. At each unit of time, we want a
string showing occupied locations with an 'X' and unoccupied locations with a
'.'. Create a class Animation that contains a method animate that is given an int
speed and a
The method will return
a
Constraints
- speed will be between 1 and 10 inclusive
- init will contain between 1 and 50 characters inclusive
- each character in init will be '.' or 'L' or 'R'
2
"..R...."
Returns: { "..X....", "....X..", "......X", "......." }
The single particle starts at the 3rd position, moves to the 5th, then 7th, and then out of the chamber.
3
"RR..LRL"
Returns: { "XX..XXX", ".X.XX..", "X.....X", "......." }
At time 1, there are actually 4 particles in the chamber, but two are passing through each other at the 4th position
2
"LRLR.LRLR"
Returns: { "XXXX.XXXX", "X..X.X..X", ".X.X.X.X.", ".X.....X.", "........." }
At time 0 there are 8 particles. At time 1, there are still 6 particles, but only 4 positions are occupied since particles are passing through each other.
10
"RLRLRLRLRL"
Returns: { "XXXXXXXXXX", ".........." }
These particles are moving so fast that they all exit the chamber by time 1.
1
"..."
Returns: { "..." }
Submissions are judged against all 26 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Animation with a public method vector<string> animate(int speed, string init) · 26 test cases · 2 s / 256 MB per case