Andy and Ralph are playing a two-player game on a triangular board that looks like the following:
At each turn, a player must choose two adjacent vertices and draw a line segment that connects them. If the newly drawn edge results in a triangle on the board (only the smallest ones count), then the player claims the triangle and draws another edge. Otherwise, the turn ends and the other player plays. The objective of the game is to claim as many triangles as possible.
For example, assume that it is Andy’s turn, where the board has fives edges as shown in the picture below. If Andy draws edge 6, then he will claim the triangle formed by edge 4, 5, and 6, and continue playing.
Given a board that already has some edges drawn on it, decide the winner of the game assuming that both Andy and Ralph play optimally. Andy always goes first. Note that if a triangle exists on the board before the first move, neither player claims it.
If both players get the same number of triangles, then print out “Draw”. Quotation marks are used for clarity and should not be printed.
입력 6 1 2 3 4 5 6 출력 Andy wins 입력 5 4 5 6 7 8 출력 Ralph wins
출처:standford/2011/