[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!app

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.ide

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?this

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.spa

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).code

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.orm

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.blog

Output

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

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.ci

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。

代碼:

 

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<stdbool.h>
 4 
 5 int i,j,n,m,t,sum,p,
 6     a[10][10],b[10][10];
 7 bool c[20];
 8 
 9 int 
10 pre()
11 {
12     memset(a,0,sizeof(a));
13     memset(b,0,sizeof(b));
14     memset(c,0,sizeof(c));
15     sum=0;
16     return 0;
17 }
18 
19 int
20 init()
21 {
22     scanf("%d",&n);
23     
24     for(i=1;i<=4;i++)
25         for(j=1;j<=4;j++)
26         scanf("%d",&a[i][j]);
27    
28     scanf("%d",&m);
29     
30     for(i=1;i<=4;i++)
31         for(j=1;j<=4;j++)
32         scanf("%d",&b[i][j]);
33 
34     return 0;
35 }
36 
37 int 
38 main()
39 {
40     int casi;
41     freopen("1.in","r",stdin);
42     freopen("1.out","w",stdout);
43     scanf("%d",&t);
44 for(casi=1;casi<=t;casi++)
45 {
46     pre();
47     init();
48     
49     for(i=1;i<=4;i++)
50     c[a[n][i]]=true;
51     
52     for(i=1;i<=4;i++)
53     if(c[b[m][i]])
54     {
55         sum++;
56         p=b[m][i];
57     }
58     
59     if(sum==1) printf("Case #%d: %d\n",casi,p);
60     else if(sum==0) printf("Case #%d: Volunteer cheated!\n",casi);
61     else printf("Case #%d: Bad magician!\n",casi);
62 
63 }
64     
65     return 0;
66 }

 

 

 

---恢復內容結束---

相關文章
相關標籤/搜索