C Language: 1000 bottles of water, a bottle is poisonous, there are a total of 10 mice, how to judge the poison water?

Source: Internet
Author: User

Question: 1000 bottles of water, one of which is poisonous, a rat drinking poison water will die after a day, there are now a total of 10 mice, how to determine which bottle of water is poisonous water?

Analysis: 2^10=1024, you can consider using binary solution

Solution: To 1000 bottles of water labeled 1 to 1000, 10 mice from right to left into a column, the first bottle of water to the right 1th mouse to drink, 2nd bottle of water let 2nd mouse drink, 3rd bottle of water let 1th, 2 mice drink, then 4th bottle of water let 3rd mice drink,...... The 1000th bottle of water let the first 4,6,7,8,9,10 mouse drink, remember the death of the mouse is 1, the dead mouse is 0, according to the method of binary notation to find this number, we know which bottle is poisonous water

This article is from the "Rock Owl" blog, please be sure to keep this source http://10742111.blog.51cto.com/10732111/1722548

C Language: 1000 bottles of water, a bottle is poisonous, there are a total of 10 mice, how to judge the poison water?

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.