[Google Code Jam (Qualification Round 2014) ] A. Magic Trick
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, 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 |
Case #1: 7 |
本题直接模拟即可,只有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的更多相关文章
- [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 ...
- [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 ...
- [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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- LeetCode_Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters ...
- 走进C++程序世界-------类的定义和使用(数据成员和方法成员,析构函数,构造函数,内联实现)
类的成员简介 在C++中,可以通过声明一个类来穿件一种新的类型.类将一组变量(他们的类型通常不同)和一组相关的函数组合在一起.类可以有各种类型的变量组成,还可以包含其他类对象.成员变量称为数据成员它们 ...
- 前端模拟发送数据-Chrome下的REST Client
1)确定需要POST的数据 2)拼接数据,POST给服务器 3)查看服务器响应及结果
- AS3排序
package { import flash.display.Sprite; public class Sort extends Sprite { private var arr:Vector.< ...
- Hive 6、Hive DML(Data Manipulation Language)
DML主要是对Hive 表中的数据进行操作的(增 删 改),但是由于Hadoop的特性,所以单条的修改.删除,其性能会非常的低所以不支持进行级操作: 主要说明一下最常用的批量插入数据较为常用的方法: ...
- 基于PCA和SVM的人脸识别系统-error修改
------------------------------------------------- Undefined function or variable 'W'. Error in class ...
- dom4j解析接口使用SOAP传递的xml
xml 文件的格式类型: <?xml version="1.0" encoding="utf-8"?> <SOAP-ENV:Envelope ...
- [Angular 2] WebStorm - Managing Imports
Some tips for import libaray by using webstorm: // Alt + Enter --> Auto Import // Ctrl + Alt + o ...
- asp.net cookie和session的详细使用
cookie使用代码: //设置Cookie HttpCookie setCookie = new HttpCookie("test"); setCookie.Values.Add ...
- ORACLE查看数据文件-控制文件-日志文件-表空间信息
1.查看当前数据库中的所有用户:select username from dba_users; 2.查看当前会话登录的用户:show user或select username from user_us ...