PROBLEM STATEMENT
An interesting graphic can be drawn using the following procedure:
P1: Select three arbitrary points on the xy coordinate plane. Call these
vertices A, B, and C.
P2: Select an arbitrary starting point on the same plane. Call this the current
position.
P3: Select at random one of the three vertices defined in P1.
P4: Compute the point that lies halfway between the current position and the
vertex selected in P3. Draw this halfway point and make this halfway point the
new current position.
P5: Repeat steps P3 and P4 indefinitely.
Write a method that, given a String representing the series of selected random
points described in P1 above, and a list of the coordinates for the starting
point and three vertices A, B, and C, returns the final current position that
would be computed following the above procedure.
The int[] of coordinates contains the x, y coordinates of the starting point,
followed by the x, y coordinates of the three vertices A, B, and C, in the
following arrangement: {x, y, Ax, Ay, Bx, By, Cx, Cy}.
For example, {0,0,0,50,50,0,-50,0} defines a starting position of {x=0,y=0},
vertex A at {x=0,y=50}, vertex B at {x=50,y=0} and vertex C at {x=-50,y=0}.
The String of moves consists of the uppercase characters 'A', 'B', and, 'C'.
The characters define respectively, the first, second, and third vertices
defined in the list of coordinates. Using the above example, the character 'A'
represents the vertex defined as {x=0,y=50}, 'B' as {x=50,y=0}, and 'C' as
{x=-50,y=0}.
Return the result as an int[] containing the two numbers representing the x and
y coordinates in that order of the final current position.
DEFINITION
Class: TriGraph
Method Name: plot
Parameters: String, int[]
Returns: int[]
Method signature: int[] plot(String moves, int[] points);
(be sure your method is public)
TopCoder will ensure the validity of the inputs. Inputs are valid if all of
the following criteria are met:
* moves is from 0 to 50 characters in length inclusive
* moves consists only of the uppercase characters 'A', 'B', and 'C'
* points contains exactly 8 numbers
* each element in points is in the range -99 to 99 inclusive
NOTES
N1: The starting point and vertices do not have to be unique.
N2: If the calculation of the new current position produces a coordinate with a
fractional result, truncate the fractional part so that the coordinates of the
current position are whole numbers. For example, 22.5 truncates to 22, -17.5
truncates to -17.
EXAMPLE
E1: "CACBB",{5,10,0,50,50,0,-50,0} ==> {30,3}
The starting position is {5,10}, A is {0,50}, B is {50,0}, C is {-50,0}. Make
the starting position {5,10} the current position. Now process each move in
order and compute the new current position.
Halfway from {5,10} to C {-50,0} is {-22,5}.
Halfway from {-22,5} to A {0,50} is {-11,27}.
Halfway from {-11,27} to C {-50,0} is {-30,13}.
Halfway from {-30,13} to B {50,0} is {10,6}.
Halfway from {10,6} to B {50,0} is {30,3}.
All of the moves have been processed and so the final current position of
{30,3} is returned.
MORE EXAMPLES
E2: "", {5,10,0,50,50,0,-50,0} ==> {5,10}
E3: "A", {5,10,0,50,50,0,-50,0} ==> {2,30}
E4: "B", {5,10,0,50,50,0,-50,0} ==> {27,5}
E5: "CCC",{10,10,0,0,50,0,50,50} ==> {45,45}
E6: "ABBCCAABBCCAABB",{0,0,-99,-99,0,99,99,-99} ==> {-14,52}
E7:
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",{20,20,21,21,42,42,21,84}
==> {20,20}