Two teams alternately return a reflecting ball in fixed order, and the team whose player misses loses, so decide the winner and the loser return count.
Hard8MathGame theorySimulationNo attempts yetTime limit5sMemory limit512 MBTwo teams play pong. Each player controls one paddle, which we treat as a single point, and one ball travels back and forth between the two teams. Inside a team the players must return the ball in a fixed cyclic order. In a three-player team the first touch belongs to P1, the next to P2, the next to P3, and only then is it P1's turn again. Play continues until some player fails to reach the ball. The ball then leaves the field and that player's team loses.
The field is a rectangle of height A and width B. Its lower left corner is (0,0), the horizontal coordinate x runs from 0 to B, and the vertical coordinate y runs from 0 to A. The team called LEFT guards the wall x=0 with N paddles, and the team called RIGHT guards the wall x=B with M paddles, one paddle per player. Every paddle of LEFT moves vertically at speed V and every paddle of RIGHT moves vertically at speed W, both in units per second. Paddles of the same team pass through each other freely.
The ball starts at height Y and horizontal position X, and it moves VY units up and VX units to the right every second. Each player sees the starting position of the ball and then places their own paddle anywhere on their own wall before play begins. When the ball reaches a horizontal wall (y=0 or y=A) it reflects, so the angle of incidence equals the angle of reflection. When the ball reaches a vertical wall, the player whose turn it is must have their paddle exactly at the arrival point. If the paddle is there, the ball bounces back. If it is not, that player's team loses. A player who is not on turn cannot touch the ball even when their paddle sits at the arrival point.
A velocity component can be 0. If VX is 0, the ball never reaches a vertical wall, so play never ends.
Determine the final result, assuming every player plays optimally.
The first line contains T, the number of test cases. Each test case consists of four lines.
The first line contains A and B, the height and the width of the field.
The second line contains N and M, the number of players on the team guarding x=0 and the number of players on the team guarding x=B.
The third line contains V and W, the paddle speed of the first team and the paddle speed of the second team.
The fourth line contains Y, X, VY and VX: the vertical position, the horizontal position, the vertical speed and the horizontal speed of the ball.
All values are integers.
For each test case, print one line of the form Case #x: y, where x is the test case number starting from 1 and y is one of the following.
DRAW if the game can go on forever.LEFT z if the team guarding x=0 wins, where z is the largest number of times the opposing team can bounce the ball.RIGHT z if the team guarding x=B wins, where z is the largest number of times the opposing team can bounce the ball.
The picture shows the play of the first test case of the first example. The ball reaches the right wall at time 0.375, and the first RIGHT player intercepts it, for instance by starting with her paddle there and never moving it. It reaches the left wall at 0.875, where the single LEFT player returns it. At 1.375 it is back on the right wall and the second RIGHT player can put his paddle at the bounce point. At 1.875 it is on the left wall again and the LEFT player arrives just in time, covering three units of distance in exactly the one second she has. The next arrival on the right wall is too far away for the first RIGHT player. The second RIGHT player could reach it, but the cyclic order forbids him from touching the ball. If RIGHT had one more player, she would return the ball, and then LEFT would lose, because the ball would come back too high for the single LEFT player.