Google Code Jam 2014 预赛 Problem A. Magic Trick

17 篇文章 0 订阅

Problem A. Magic Trick

This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start Guide to get started.
Small input
6 points

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

Problem

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 16 cards in a square grid: 4 rows of cards, with 4 cards in each row. Each card has a different number from 1 to 16 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 16 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 1 to 4 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).

Solving this problem

Usually, Google Code Jam problems have 1 Small input and 1 Large input. This problem has only 1 Small input. Once you have solved the Small input, you have finished solving this problem.

Input

The first line of the input gives the number of test cases, TT test cases follow. Each test case starts with a line containing an integer: the answer to the first question. The next 4 lines represent the first arrangement of the cards: each contains 4 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.

Output

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1).

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

Limits

1 ≤ T ≤ 100.
1 ≤ both answers ≤ 4.
Each number from 1 to 16 will appear exactly once in each arrangement.

Sample


Input 
 

Output 
 
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!


题意是翻牌,给出16张牌,志愿者先取一张牌并告诉魔术师牌在哪一行,之后魔术师重新洗牌,志愿者再告诉魔术师牌在哪一行,魔术师通过这些信息确定志愿者选的是哪张牌。
如果能确定,则输出该牌对应的值;
如果出现多张则输出 Bad magician!
如果没有对应牌相同则输出 Volunteer cheated!

数据小,直接暴力,代码如下:
#include <iostream>
#include <algorithm>
#define MAXN 1000
#include <cstdio>
using namespace std; 
int a[MAXN][MAXN];
int b[MAXN][MAXN];
int main(void){
	FILE *fp;
	fp = fopen("out.txt", "w");
	int T;
	cin >> T;
	for(int t=1; t<=T; ++t){
		int x, y;
		cin >> x;
		for(int i=1; i<=4; ++i){
			for(int j=1; j<=4; ++j){
				cin >> a[i][j];
			}
		}
		cin >> y;
		for(int i=1; i<=4; ++i){
			for(int j=1; j<=4; ++j){
				cin >> b[i][j];
			}
		}
		int flag = 0;
		int card;
		for(int i=1; i<=4; ++i){
			for(int j=1; j<=4; ++j){
				if(a[x][i] == b[y][j]){
					flag++;
					card = a[x][i];
				}
			}
		}
		if(flag == 1){
			fprintf(fp, "Case #%d: %d\n", t, card);
		}
		else if(flag > 1){
			fprintf(fp, "Case #%d: Bad magician!\n", t);
		} else {
			fprintf(fp, "Case #%d: Volunteer cheated!\n", t);
		}
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值