Submit | All submissions | Best solutions | Back to list |
MMMAGIC3 - Mickey Mouse Magic Trick v3 |
MMMAGIC3
Mickey Mouse and Donald Duck love magic. They spacialize with card tricks. Mickey invented a new trick and they are going to surprise the world. They've contracted series of shows on whole the globe, worth many milion of dolars $$. The first show is coming up but unfortunately Mickey lost secret of the trick. He remembers only trick description, but it's not enough to satisfy the contract conditions. Help them!
Trick description
Mickey has n cards with values 1, 2, ..., n. He invites a spectator from the audience, Donald is outside the stage and see nothing on the stage. The spectator chooses randomly k cards from the pack and discard the remaining n-k cards. Mickey chooses one card from this k cards, shows it to everyone (except Donald) and hides it to the spectator's pocket. Next Mickey leaves the remaining k-1 cards in some order on the table. Donald is coming back. He is the only person, who don't know, what is the number in the hiden card. He can see only k-1 cards on the table. Donald thinks for a while, the drum rumbles, at the begining very silent, then lauter and lauter, everyone is waiting, the drum stops, a few seconds of deep silence and... Donald says the number on the hidden card. It's correct, applause! How did he discover the number? It's magic!
Help request
Mickey and Donald know, that's not magic only smart math manipulations. They asked You to help them. You have to write computer program, that can help them with the trick. The program should be able to do two things: help Mickey to select one card from given k cards and describe order of remaining k-1 cards on the table, then help Donald to guess the hidden card value basing only on k-1 cards left by Mickey on the table. You can use any strategy that You want, but remember - Donald needs to guess the number during the show, because the huge profit $$ depends on it.
Input
All integers in the same line are single-space separated (the same concerns problem output).
Values n, k are constant. In this problem n=8 and k=3. There are also problems with different values: MMMAGIC4, MMMAGIC5, MMMAGIC6
The first line of input contains two integers M, D, where M is the number of test cases in which Mickey needs help, D is the number of test cases in which Donald needs help (M+D < 200) .
Every of next M lines contains k distinct integers from range [1, n] - the values on cards given to Mickey. The order of values is casual.
Every of next D lines contains k-1 distinct integers from range [1, n] - the cards left to Donald on the table. The order is the same, as on the table, from left to right.
Output
For each Mickey's query write a line with k-1 integers - the values on the cards, that Mickey have to leave on the table, from left to right.
For each Donald's query write a line with one integer - the value of hidden card or (if in Your strategy such situation is impossible) any of remaining values.
Example
Input 1 | Output 1 |
3 0 1 2 3 4 6 2 8 7 4 |
2 1 4 6 4 7 |
Input 2 | Output 2 |
0 3 2 1 4 6 4 7 |
3 2 8 |
Explanation
The example above don't show any concrete strategy. It just shows, that strategy must be coherent (when Mickey for given set of cards 1 2 3 leave on the table 2 1, then Donald for given cards 2 1 should answer with the number 3).
Generally You can implement Your own strategy satisfying the conditions below:
- for Mickey's query "a1 a2 ... ak" You should reply "b1 b2 ... bk-1", such that {b1, b2, ..., bk-1} is subset of {a1, a2, ..., ak}
- for Donald's query "b1 b2 ... bk-1" reply the number c, such that {b1, b2, ..., bk-1, c} = {a1, a2, ..., ak}
Note
The similar problem appeared in MWPZ 2007 contest in Poland, with different story (in original problem there was Polish characters Bolek and Lolek). The main page of contest is http://mwpz.poznan.pl
Added by: | miodziu |
Date: | 2014-01-09 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | MWPZ 2007 http://mwpz.poznan.pl/ |
hide comments
2016-01-31 05:27:20
@miodziu I hardcoded to match every permutation of two cards to a combination of three cards, in such a way that the two cards in the permutation are always a subset of the three cards in the combination. Yet I'm still getting WA :( EDIT (miodziu): Your solution has a little mistake. Try to find it. EDIT(hodobox): Haha cheers ^.^, came here after a long time and found it, made one incorrect pairing. Coded a sensible solution this time instead :) Last edit: 2016-08-04 12:36:15 |
|
2015-01-10 15:01:35 eightnoteight
i'm getting wrong answer if i tried to use different stratergy for different testcases EDIT (miodziu): That's right. There is an explanation in problem statement, that the solution should be coherent in different testcases :) Last edit: 2015-01-12 15:17:03 |
|
2014-01-21 22:01:08 Mostafa 36a2
There is 8C3=56 tripple , and 8P2=56 possible pair ,there is no impossible situation if the stratigy is 100% correct (correct me if am wrong)! EDIT (miodziu): You used double negation "no impossible", so I can't understand Your question. Please clarify. EDIT (miodziu): Och... I've read your post once again, and (if I understood correctly) You're right. Last edit: 2014-01-22 09:08:07 |
|
2014-01-16 13:25:24 Mitch Schwartz
@Roman Hajduk: This problem uses custom judge -- any correct answer passes. You can answer your own question by reading the problem carefully. Edit: So there are sort of two interpretations of your question: (1) What if a Donald query doesn't correspond to a Mickey query in the input, and (2) What if a Donald query doesn't correspond to a Mickey pair in the strategy. For here (2) actually can't happen for any correct strategy (you can prove this without much work). And the wording of the question suggests (1) much more than (2), so that's the only one that occurred to me, and it's the one I answered. But question (2) could be important for v4 and the other variations on the problem. Last edit: 2014-01-10 17:42:40 |
|
2014-01-16 13:25:24 Roman Hajduk
hello i have a few qustions so M can be <> D. What should i print when there is in Donalds query pair that i didnt have as output in Mickeys query. Should i write random number? like if in example was in input in Donalds query pair 5 8. EDIT (miodziu): This is very good question, I should mention about it in output section (and I'll do it). In this case You can reply with any of remaining values (in Your example, for Donald's query "5 8" every value from set {1,2,3,4,6,7} is good). Last edit: 2014-01-10 15:57:50 |
|
2014-01-16 13:25:24 Mitch Schwartz
@Bhavik: Be sure to read the "Explanation" part. (You are wrong.) |
|
2014-01-16 13:25:24 Bhavik
M==D??this is necessary i think??plz tell me if i am wrong EDIT (miodziu): No, it's not necessary! Last edit: 2014-01-09 14:25:02 |