Programming contests

ECN selejtező programozó csapatverseny, 2016. március 23.

March 23, 2016, 10:10 AM – March 23, 2016, 3:10 PM

Game: Mouse and Cheese

SOHA and TARA have recently invented a new game called “Mouse and Cheese”. As the name suggests, this game involves a mouse searching for a piece of cheese. The game is played on a 3 × 3 board as shown in the diagram below. Each cell is uniquely numbered with an integer between 1 and 9. The board contains 12 sticks (the blue lines in the diagram).

Initially, a mouse and a piece of cheese are placed on two different cells. In the example to the right, the mouse is placed on “cell 8”, and the cheese is placed on “cell 3”.

The rule of the game goes like this: It's a two-player game where the players make moves alternately. SOHA, being player 1, goes first. In each move, the player selects a stick and throws it away. After each move, if the mouse can reach the cell containing the cheese without touching any of the remaining sticks, then that player is declared as the winner. If both play perfectly, who wins?

Before the game starts, some of the sticks are removed. You will be given the coordinates of these sticks and the cell numbers of the mouse and the cheese. A stick is represented using the coordinates of its end points. The lower left of the grid is the origin (0, 0). In the example above, the two sticks surrounding the cheese has coordinates “2 0 2 1” and “2 1 3 1”. Note that the end points of a stick can be given in any order. That is “2 0 2 1” could be given as “2 1 2 0”.

Input Specification

The first line of the input is an integer T (T < 1000) that determines the number of test cases. Each case starts with 3 integers S, C, and R. S and C denote the location of the mouse and the cheese, respectively. Each of the next R lines contains 4 space-separated integers that give the coordinates of the sticks removed from the board before the start of the game.

Notes and constraints:

  • 1 ≤ S, C ≤ 9
  • SC
  • 0 ≤ R ≤ 12
  • For each case, all the removed sticks will be distinct.

Output Specification

For each case, output the case number first, starting with 1, followed by the name of the player who wins. If the mouse can already reach the cheese before the game starts, output “No Cheese!” instead. Look at the sample output for exact format.

Sample Input

  1. 3
  2. 1 2 1
  3. 1 1 1 0
  4. 1 4 0
  5. 7 2 2
  6. 1 2 1 3
  7. 2 2 2 3
download as text file

Output for Sample Input

  1. Case 1: No Cheese!
  2. Case 2: SOHA
  3. Case 3: TARA
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024