24小时热门版块排行榜    

CyRhmU.jpeg
查看: 520  |  回复: 1

llhhbc

新虫 (初入文坛)

[交流] 2014 google code jam 资格赛 A Magic Trick已有1人参与

去年一次偶然的机会,了解到了google code jam,今年,收到google发来的邮件,于是,我就参加了今年的比赛。资格赛顺利通过,第一轮,就败下阵来。不过,我也喜欢上了这个活动。

      google公布了参加比赛的人的答案,我也觉得这是一个很好的学习材料。
      自己研究了一段时间,发现,有些东西理解有些吃力,百度后,发现这类信息少之又少。最后,查到了一个国外的论坛上别人的说明,才渐渐把程序读明白。

     我虽不才,不过,我喜欢编码,当我的想法,在电脑里实现后,那份喜悦不会忘记。 欢迎有兴趣的朋友一起来讨论、交流。

原题目信息如下:
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, T. T 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!

这个题目思路比较简单,
  先根据第一组输入,把给出的那一行的4个数字全部取出来,再与第二组输入那行的4个数字比较,统计相同数字的个数。如果是0,则是Volunteer cheated!如果是1,则输出该数字;如果大于1,则是Bad magician!

附件a.c是我实现的代码,供参考。

在此,附上google网址:
https://code.google.com/codejam/contest/2974486/dashboard
上面有提供测试数据,并能检测程序执行结果
回复此楼

» 本帖附件资源列表

  • 欢迎监督和反馈:小木虫仅提供交流平台,不对该内容负责。
    本内容由用户自主发布,如果其内容涉及到知识产权问题,其责任在于用户本人,如对版权有异议,请联系邮箱:xiaomuchong@tal.com
  • 附件 1 : a.c
  • 2014-06-07 12:26:02, 1.42 K

» 收录本帖的淘帖专辑推荐

收藏

» 猜你喜欢

» 本主题相关商家推荐: (我也要在这里推广)

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

我爱小虫子

新虫 (正式写手)

好东西,感谢分享。。。
2楼2014-06-10 22:41:04
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 llhhbc 的主题更新
普通表情 高级回复(可上传附件)
信息提示
请填处理意见