A programmer interview question in 2021, it is said that few people answer it correctly

topic:

Assume there are 64 bottles of Coke, one of which is poisonous, and a mouse will die within a day after drinking one drop. If you want to find out which bottle of Coke is poisonous, the time limit is 5 days. How many mice can be used at most? Toxic Coke?

 

I think the answer should be: 7

Day 1: First use a mouse to lock 32 of the bottles, and eliminate 32 bottles

The first choice is to take out 32 bottles of 64 bottles of cola, and drop a drop of cola in each bottle to give the mice to drink. An additional 32 vials were excluded regardless of whether the mice died the next day.

Sacrifice at most one mouse on the first day

 

The next day: Similarly, at most one mouse will be sacrificed, 16 bottles will be locked, and 16 bottles will be eliminated.

Sacrifice at most one mouse on the second day

 

Day 3: Similarly, at most one mouse will be sacrificed, 8 bottles will be locked, and 8 bottles will be eliminated.

On the third day, at most one mouse was sacrificed

 

Day 4: Similarly, at most one mouse will be sacrificed, 4 bottles will be locked, and 4 bottles will be eliminated.

On the fourth day, at most one mouse was sacrificed

 

Day 5: Because the time is up, there are 4 bottles of Coke to be verified, so today we need to use 3 mice to verify at the same time (if the 3 mice are all right, the fourth bottle of Coke is considered poisonous)

So I think sacrificing up to 7 mice can locate the poisonous bottle of 64 bottles of Coke in five days, don't you think so?

 

 

 

Guess you like

Origin blog.csdn.net/weixin_48914851/article/details/113761011