Problem A. Magic Trick

Small input
6 points
You have solved this input set.

 

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!

本题直接模拟即可,只有Small input。6 points

第一次参加Google Code Jam。GCJ的评测为下载数据,在规定时间内提交答案,数据都为边界数据。搜狗浏览器下载GCJ数据会有缺失。第一题一直WA,发现数据缺失后,换了浏览器才AC。

代码:

 #include<stdio.h>
#include<string.h>
#include<stdbool.h> int i,j,n,m,t,sum,p,
a[][],b[][];
bool c[]; int
pre()
{
memset(a,,sizeof(a));
memset(b,,sizeof(b));
memset(c,,sizeof(c));
sum=;
return ;
} int
init()
{
scanf("%d",&n); for(i=;i<=;i++)
for(j=;j<=;j++)
scanf("%d",&a[i][j]); scanf("%d",&m); for(i=;i<=;i++)
for(j=;j<=;j++)
scanf("%d",&b[i][j]); return ;
} int
main()
{
int casi;
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
scanf("%d",&t);
for(casi=;casi<=t;casi++)
{
pre();
init(); for(i=;i<=;i++)
c[a[n][i]]=true; for(i=;i<=;i++)
if(c[b[m][i]])
{
sum++;
p=b[m][i];
} if(sum==) printf("Case #%d: %d\n",casi,p);
else if(sum==) printf("Case #%d: Volunteer cheated!\n",casi);
else printf("Case #%d: Bad magician!\n",casi); } return ;
}

---恢复内容结束---

[Google Code Jam (Qualification Round 2014) ] A. Magic Trick的更多相关文章

  1. [Google Code Jam (Qualification Round 2014) ] B. Cookie Clicker Alpha

    Problem B. Cookie Clicker Alpha   Introduction Cookie Clicker is a Javascript game by Orteil, where ...

  2. [C++]Store Credit——Google Code Jam Qualification Round Africa 2010

    Google Code Jam Qualification Round Africa 2010 的第一题,很简单. Problem You receive a credit C at a local ...

  3. [C++]Saving the Universe——Google Code Jam Qualification Round 2008

    Google Code Jam 2008 资格赛的第一题:Saving the Universe. 问题描述如下: Problem The urban legend goes that if you ...

  4. dp - Google Code jam Qualification Round 2015 --- Problem B. Infinite House of Pancakes

    Problem B. Infinite House of Pancakes Problem's Link:   https://code.google.com/codejam/contest/6224 ...

  5. Google Code jam Qualification Round 2015 --- Problem A. Standing Ovation

    Problem A. Standing Ovation Problem's Link:   https://code.google.com/codejam/contest/6224486/dashbo ...

  6. Google Code Jam 2010 Round 1C Problem A. Rope Intranet

    Google Code Jam 2010 Round 1C Problem A. Rope Intranet https://code.google.com/codejam/contest/61910 ...

  7. Google Code Jam 2010 Round 1C Problem B. Load Testing

    https://code.google.com/codejam/contest/619102/dashboard#s=p1&a=1 Problem Now that you have won ...

  8. Google Code Jam 2010 Round 1A Problem A. Rotate

    https://code.google.com/codejam/contest/544101/dashboard#s=p0     Problem In the exciting game of Jo ...

  9. Google Code Jam 2010 Round 1B Problem B. Picking Up Chicks

    https://code.google.com/codejam/contest/635101/dashboard#s=p1   Problem A flock of chickens are runn ...

随机推荐

  1. 这样就算会了PHP么?-3

    关于循环,IF,WHILE.... <?php $month = date("n"); $today = date("j"); if ($today &g ...

  2. 资本助力转型 TCL攻守转换(转型、并购、过冬前一定要保留强大的战略预备队)

    吴侨发 9月份,TCL集团(3.92, 0.00, 0.00%)160多位高管启动四天戈壁行.在戈壁行第三天,30多公里的戈壁,差不多等于平路50公里,最后两只队伍走了13个小时.路途的艰辛几乎超过这 ...

  3. 实现ECMAScript的引擎

    list of ECMAScript engines From Wikipedia, the free encyclopedia     An ECMAScript engine is a progr ...

  4. 【转】Win7与Ubuntu 14.04双系统修改启动项顺序

    原文网址:http://blog.sina.com.cn/s/blog_b381a98e0102v1gy.html 一.Ubuntu14.04采用默认安装方式的情况 采用默认安装方式,在win7下安装 ...

  5. 黑马程序员_Java面向对象_异常

    6.异常 1.异常: 就是程序在运行时出现不正常的情况.问题也是现实生活中一个具体的事物,也可以通过Java的类进行描述,并封装成对象.Exception和Error的子类名都是以父类名作为后缀名. ...

  6. PyInstaller打包Python脚本为exe

    1.PyInstaller-3.1.1  百度云链接  http://pan.baidu.com/s/1jHYWin8 密码  oapl 2.安装最新版本的 pywin32-217.win32-py2 ...

  7. iOS学习之 plist文件的读写

    在做iOS开发时,经经常使用到到plist文件,  那plist文件是什么呢? 它全名是:Property List,属性列表文件,它是一种用来存储串行化后的对象的文件.属性列表文件的扩展名为.pli ...

  8. javascript正則表達式 &quot;\b&quot;问题

    preface 昨晚在看<javascript权威指南>后.看见作者自己封装一个兼容全部浏览器的山寨HTML5新API classLIst类.自己想了想认为自己也要去玩一下.可是能力还是有 ...

  9. Hacker(19)----检测Windows系统漏洞

    想完全掌握Windows中存在的漏洞需要使用专业的漏洞扫描软件.目前常用的有MBSA(MircosoftBaselineSecurityAnalyzer).360安全卫士等. 一.使用MBSA检测系统 ...

  10. 关闭归档提示:ORA-38774: cannot disable media recovery - flashback database is enabled

    SQL> select * from v$version; Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit P ...