Chico and dico--guess 5th card According to any 4 cards

Source: Internet
Author: User

Forget where to find this fun place:

Using your head is permitted

http://www.brand.site.co.il/

There are some interesting maths problems in it.

Pick some of them to translate, say your understanding ~


May Riddle


"Chico and Dico are a pair of very famous magicians. The following tricks often appear in their programs:

Chico first took out a standard poker, a total of 52 cards (the size of the king was eaten by both of them). Then he would pick an audience, certainly not (it's a math problem).

The audience will randomly select 5 copies of the deck and hand it over to Chico,chico to reorder them. This whole process is dico to see.

Now the audience will Chico in the order of the first 4 cards to Dico, next, Dico will accurately say what is the fifth card. ”

To expand this problem, false with n cards, the audience randomly choose K Card, and Dico need to guess the last J card, then N, K, J what conditions to meet to ensure that this magic is feasible.

Further, how to get such a strategy, and simple enough to let two magicians learn it.


Outside: I think of a classmate told me the magic. He and a partner asked an audience to tell him about his partner a piece of stuff. Of course he did not know. Then the partner will say a bunch of things, each one says he answers "yes" or "no", if the answer is "yes" then that item is what the audience said. He says the magic can even be played on the phone, but I don't know how to play it now.


Here to find a strategy to be able to follow the first four cards to determine the fifth card, it seems to be more chaotic. But the topic itself gives some tips for modeling:

N, K, J need to meet some conditions.

Since the letters are all marked out, think of the connection between them: A total of n cards, randomly select the K, and then by the order of the former (K-J), guess the last J card.

Such a look, there are some intuitively can think of the formula: N-card randomly selected K Zhang is a total of C (n,k) choice, the order of the former K-j Zhang is n (n-1) *. * (n+j-k+1) =n!/(n+j-k)!

Yo, it's not necessary to establish a correspondence between the order of K-j cards and the C (n,k) choice, so that you can always guess the right way.

This is the answer. Assuming that there are n cards, the arrangement of arbitrarily taking K-j cards is n!/(n+j-k)! species, which can have so many different encodings, the combination of randomly selected K-sheets is a C (n,k) species. To determine the entire K combination according to the order of the former k-j, the C (n,k) ≤n!/(n+j-k) must be met!, i.e. (n+j-k)!≤k! (N-K)!.

So the mapping to find is to make k-j this arrangement of all the cards are in C (n,k) This K-card mapping. Of course, such mappings should be of many kinds. Here is a time to talk about a j=1, relatively simple:

Assuming that the audience gets the cards are a0,a1,... ak-1, and A0<a1<a2...<ak-1, their and to k! take the remainder for S, we decide the order according to the following method:

Vector<int> Reorder (vector<int> orig, int S) {//The original array is from small to large ordered array
int x = S;//Make x a0 to ak-1 and remainder k!, i.e. S
vector<int> cards; The card group to be sorted, position 0 is the last card for
(int i = k; i > 0; i) {//i descending from K to 1
  cards.push_back (orig[x% i]);//each time the number of x%i in the original array is placed in the CA RDS
  Orig.erase (Orig.begin () + x% i);//delete this number from the original array
  x/= i;//divide x by i
}
return cards;
One of the cards[0]j is the bottom-masked card. The advantage of this is that the order of the original cards can be inferred according to the inverse process.

such as the last to get cards is this: C0, C1, ... ck-1, first take out ck-1, and then see Ck-2 and ck-1 size relationship. We know that this is the second-to-last cycle when the result of 2, so if ck-2>ck-1, then 2 is 1, the second-to-last cycle x=1; if ck-2<ck-1, then x=0.

Continue to see ck-3, if the ck-3 is the smallest, then in the third cycle of the countdown to 3 of the result is 0; otherwise 1 or 2, from the face of the result of 2 take-off x2, we can get the third cycle of the penultimate time X=X2 * 3 + x3.

In turn, we can get s-s%k.

But this is not the last C0 to ask for. At this time we have known the number of k-1, assuming that the number of k-1 and for the Sk, the unknown number is C0, then we know s = (Sk + c0)% k!, s% k = C0 in a0,a1. The position of AK, now we only poor s and this position do not know. However, the number of times we need to try is only 0 to k-1, by trying to s-s%k with this number of combinations, as well as getting this number in A0,A1. The position in the AK is verified and we can determine the final value.

It says a bunch, or take a real example of it ~

Look at an audience, randomly pumping to 13,19,28,44,49. Next Chico how to deal with it.

1. Calculate S. The sum of five numbers is 153, so s=153%5!=33.

2. I=5, take the 33%5 = 3 number, that is, 44 (starting from 0) into the card group, at this time cards={44}. Remove 44 from the original card group, orig changes to {13,19,28,49},x to 33/5=6

3. i=4, take 6%4 = 2 numbers, i.e. 28 put into cards, at this time cards={44,28}, orig={13,19,49}, X becomes 6/4=1

4. i=3, take 1%3 = 1 numbers, i.e. 19 put into cards, at this time cards={44,28,19}, orig={13,49}, X becomes 1/3=0

5. i=2, take 0%2 = 0 numbers, i.e. 13 put into cards, at this time cards={44,28,19,13}, orig={49}, X becomes 0/2=0

6. I=1, put 49 into cards complete, cards={44,28,19,13,49}

OK, then dico how to pass their tacit understanding to only see after four cards to guess the first card.

Let's take a cameo dico and assume that we can forget the number 44 for a moment, only to see the arrangement of 49,13,19,28.

1.49, take it, it seems that there is no use, put it here. Cards = {49}

2.13, this is useful. From cards we can see that it should have been in the No. 0 place before. We speculate that X is 0 before dividing by 2, so this time x=0. (For what, X before the first step itself is 0, because it is more than 1 is 0 ah, 0*2 or 0 ah ...), cards={13,49}

3.19, observed that 19 is from 13 and 49 is taken out, so it can be inferred that x before divided by 3 is 3, so at this time x=x*3+1=1 (Restore and calculation, when the calculation is the first to seek the remainder of the addition, the restoration need to first multiply plus), cards={13,19,49}

4.28, the same reason X is divided by 4 before 4 is 2, so at this time x=x*4+2=6, cards={13,19,28,49}

5. All the numbers have been read, what else? We can also calculate a step x, although we do not know that x divided by 5 before the more than 5, but the range is certainly between [X*5, X*5+4], that is, [30,34] between, so the range of S is [30,34], that is, the original five number of the sum of the range is [150,154] between.

6. The current 4 numbers are 109, so the range of hidden numbers is between [41,45]. This range is already very small, and basically do not need to try it, it must be between 28 and 49, so the value of s 5 is 3, easily obtained s=33, hidden number 44.

New skills get√. Also can happily install X, but to play proficiency certainly also not easy.


But because of the Caishuxueqian, the last paragraph did not see clearly. It would be nice to have someone teach you.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.