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.
Solution: The following gives four kinds of solutions, labeled 10 packets of powder (...) cup for [1,2,3,4]
First of all I think there will be some algorithm, DP two. @[email protected]. No, you are ignorant.
FA One: this is the stupid way I thought of it at first.
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 discoloration, in the four-pack powder of the two cups, the second trip can be found
Law II: Sumitomo Wan (3) Ting (2) June thought of
First trip: [123;456;789;10]
(1) 1 cups discoloration, only in the Cup 1-3 discoloration, blue powder in three colors take two. Second trip to find
(2) 2 cups discoloration,
-If it is 1/2/3 + 4 discoloration, the next trip to find 1/2/3 can be.
-If it is 123 to two, assuming it is cup 1 and cup 2, then 123 and 1 take 456, the second pass is placed [11; 25; The Relationship between the cups 14 and 24 of the contacts.
A. Cup 1 discoloration and cup 4 unchanged
Law Three: I tried it from the French and the French, and successfully solved it:
First trip: [A. 56; 5678;78910]
4 consecutive packets, adjacent to two packets of contact, 12,23,34, the so-called contact means that there are two cups put the same powder
(1) 1 cup blue, it must be Cup 1 12 or Cup 4 of 9 10,2 will cause 13 blue, 3 the same.
(2) 2 cup blue, it must be Cup 1 (12) and cup 4 (9 10) Blue, the second trip in four bags to observe. Can't be the analysis of the Cup 2/3 Same as (1)
(3) 3 cup blue, it must be cup 123 or 456 blue.
Analysis 123 Blue, if 1/2 blue, then 5/6 must be blue (4 kinds), the two have dependence, 3/4 and 9/10 Same (4 kinds). There are 8 possible answers.
Second trip: [15; 26; 39; 410]
If there is only one Cup blue, take Cup 1_15 for example, the answer is 15, if two cups blue, such as 1_15 Blue, then another Blue Cup must contain 6 2_26.
The above analysis is that when I try to enumerate, I feel that there is something fishy between them and extract the analysis characteristics.
Law IV: The interviewer gave, I analyzed the next, good wonderful. This method I think of law one in the look, did not find the law, view two feel very much like, to law three finally enlightened.
First trip: [1234; 25;89; 479]
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. such as cup 12_[1234;2567] blue, it may be
(3) Three cup blue, you can exclude the non-blue cup four kinds of powder remaining six kinds of possible; there must be one package that is the common color of the two cups in these three Blue cups + the other cup differs from the non-blue cup color, such as cup 12 common _2+ Cup 3_368, or 3+256, or 6+123.
Note that the powder 158 is independent, that is, 1 Blue is 61 fixed blue, remove the three is (2_36,3+26,6+23), then only 236 can be detected, for easy to understand rewrite as [6,3,2; 1,5, 8; 23,26,36]. Situation Analysis:
-If a blue Cup appears (only 2/3/6), then the corresponding 8/5/1 consists of two packages, even if the blue powder
-If the two Blue Cups (23,26,36) is the answer
I suddenly think this is a (permutation) combinatorial problem??
Law V: ...
The idea of enumeration has two ways of changing the color of a toast and the possibility of powder.
If the above analysis is wrong, please indicate ~
When I wrote this article, I thought,
My roommate's strong imagination, my strong analytical power and comparative summary of the strength hahaha with a face.
APP: Free to select a QR code and then identify the QR code in the graph. Consider sharing WiFi to friends, I want to see the contents of the content. In the long press to identify the two-dimensional code how to do it?? Can you identify any QR code? Is it because of the input format or the??
Chance to see the interview algorithm problem _ the shortest time to find 10 packets of powder in the two blue powder.