C language: 1000 bottles of water, one of which is toxic. Now there are 10 rats in total. How can we determine the toxic water?

Source: Internet
Author: User

C language: 1000 bottles of water, one of which is toxic. Now there are 10 rats in total. How can we determine the toxic water?
Q: 1000 bottles of water, one of which is toxic. A mouse will die one day after drinking poisonous water. Now there are 10 rats in total. How can I determine which bottle of water is poisonous? Analysis: 2 ^ 10 = 1024, you can consider using the binary solution: to 1000 bottles of water in order to mark 1 to 1000, 10 rats from the right to the left into a column, the first bottle of water let the right side of 1st mice to drink, 2nd bottles of water Let 2nd mice to drink, 3rd bottles of water let the second mouse to drink, then 4th bottles of water Let 3rd mice drink ,...... 1,000th bottles of water in turn let the 4, 6, 7, 8, 9, 10 mice drink, remember the dead mouse is 1, the dead mouse is 0, according to the binary representation of the number method to find this number, you will know which bottle is poisonous water.

Related Article

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.