#P13243. [GCJ 2014 Qualification] Magic Trick

[GCJ 2014 Qualification] Magic Trick

题目背景

Note: To advance to the next rounds, you will need to score 25 points. Solving just this problem will not give you enough points.

题目描述

Recently you went to a magic show. You were very impressed by one of the tricks, so you decided to try to figure out the secret behind it!

The magician starts by arranging 1616 cards in a square grid: 44 rows of cards, with 44 cards in each row. Each card has a different number from 11 to 1616 written on the side that is showing. Next, the magician asks a volunteer to choose a card, and to tell him which row that card is in.

Finally, the magician arranges the 1616 cards in a square grid again, possibly in a different order. Once again, he asks the volunteer which row her card is in. With only the answers to these two questions, the magician then correctly determines which card the volunteer chose. Amazing, right?

You decide to write a program to help you understand the magician's technique. The program will be given the two arrangements of the cards, and the volunteer's answers to the two questions: the row number of the selected card in the first arrangement, and the row number of the selected card in the second arrangement. The rows are numbered 11 to 44 from top to bottom.

Your program should determine which card the volunteer chose; or if there is more than one card the volunteer might have chosen (the magician did a bad job); or if there's no card consistent with the volunteer's answers (the volunteer cheated).

输入格式

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} test cases follow. Each test case starts with a line containing an integer: the answer to the first question. The next 44 lines represent the first arrangement of the cards: each contains 44 integers, separated by a single space. The next line contains the answer to the second question, and the following four lines contain the second arrangement in the same format.

输出格式

For each test case, output one line containing "Case #xx: yy", where xx is the test case number (starting from 11).

If there is a single card the volunteer could have chosen, yy should be the number on the card. If there are multiple cards the volunteer could have chosen, yy should be "Bad magician!", without the quotes. If there are no cards consistent with the volunteer's answers, yy should be "Volunteer cheated!", without the quotes. The text needs to be exactly right, so consider copying/pasting it from here.

3
2
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
3
1 2 5 4
3 11 6 15
9 10 7 12
13 14 8 16
2
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
2
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
2
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
3
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Case #1: 7
Case #2: Bad magician!
Case #3: Volunteer cheated!

提示

Limits(6 Pts)

  • 1T1001 \leq T \leq 100.
  • 1both answers41 \leq \text{both answers} \leq 4.
  • Each number from 11 to 1616 will appear exactly once in each arrangement.