Today to see someone else's interview algorithm, to find out 10 packets of powder in two packs of blue powder of the shortest time

Source: Internet
Author: User

Title: There are 4 cups, 10 bags of powder, of which 2 packets dissolved in water to blue, the rest is colorless, powder dissolved in water 2min to show color. Find the shortest time for two packages of blue powder. Suppose the water and powder are not finished.

Method One:

First trip: [12,34,56,78]

Each cup is divided into two packs of water to melt, leaving two packs of whatever. Possible situations:

(1) 0 cups discoloration, indicating that the remaining two bags are blue powder

(2) 1 cups discoloration, then the blue powder in this cup two packs and not melted two packs of two packs, the second trip four packs melted must be able to find

(3) 2 cups discolored, then in the four-pack powder of the two cups, the second trip can be found.

Time mean: E = 2*1/45 + 4*44/45 = 178/45;

Method Two:

First trip: [123;456;78;910]

(1) 1 cups turn blue, if it is 3 or 4th Cup blue, it is put into the cup 2 kinds of powder, otherwise in the Blue Cup of 3 kinds of powder, local time mean E1 = 2*2/45 + 4*6/45 = 26/45

(2) 2 cups turn blue,

-If the first two cups turn blue, the second trip is placed [14; 25; The relationship between the cups 14 and 24 of the contacts.

A. Cup 1 discoloration and cup 4 unchanged

-If the front two cups have a turn blue, the latter two cups have a blue, then 5 kinds of powder randomly take four kinds of in four cups to see the phenomenon.

-If the latter two cups turn blue, then 4 kinds of powders are placed in four cups to see the phenomenon.

Time mean: E = 2*2/45 + 4*43/45 = 176/45;

Method Three:

First trip: [1234; 2567; 3689; 47910]

Each cup has only one separate, each cup with another three cups have a common powder (and a bag of powder can only be placed in two cups), placement method: 1234 placed in the cup 1,234 respectively placed in the Cup 234,567 in the Cup 2,67 respectively put Cup 34 ...

(1) It is impossible to have only one Cup blue, except 1 10, each pack of powder is placed in two cups.

(2) Two cups blue: only the two cups are common and the other two cups are not connected. Two packs of AB in the first Blue Cup are linked to two non-blue cups, and two packs of CDs in another Blue Cup are related to two non-blue cups. 3 packs of powder are left after ABCD exclusion. For example Cup 12_[1234;2567] Blue, then may be 12,15,25, local time mean value E1 = 4*18/45 = 72/45;

(3) Three cup blue, you can exclude the non-blue cup four kinds of powder remaining six possible; at least one package is the common color of the two cups in these three Blue cups, such as cup 123_[1234;2567;3689] blue, it could be 16, 23,26,28,35,36, local time mean value E2 = 4*24/45 = 96/45;

(4) Four cups blue, then the blue powder is placed in two cups, and two packages of blue powder are not put together, it can only be one of 29,37,46 three combinations, local time mean E3 = 4*3/45 = 12/45.

Time mean: E = 4;

Method Four: Enumeration

  That is, each powder is dissolved in a cup until two packages of blue powder are found,

(1) Only one trip succeeded in finding two packages of blue powder, local time mean value E1 = 2*6/45 = 12/45;

(2) Two times successfully found two packets of blue powder, local time mean E2 = 4*23/45 = 92/45;

 (3) Three times only successfully found two packets of blue powder, local time mean E3 = 6*16/45 = 96/45;

Time mean: E = 200/45;

Method Five: Time difference

  The blue powder is judged and confirmed by the time of different powders being served at intervals, and by observing when the water becomes blue.

Method Six: .....

Today to see someone else's interview algorithm, to find out 10 packets of powder in two packs of blue powder of the shortest time

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.