Two interesting Algorithms ~

Source: Internet
Author: User

Today, I spoke to others in the SL group.Algorithm, Discussed a few sub-questions, is summarized as follows:

1. Weighing sugar Problems

There are ten packs of sugar, each containing 10 candy, each containing 1 gram of weight, one of which is very special, each containing 2 grams of weight, there is an electronic scale, please check the bag of sugar only once?

First, set the serial numbers of all sugar packets from 1 to 10. Then take 1 capsule from the first day, 2 for the second, 3 for the third ...... Take 10 pills on the 10th. Then weigh X. We know that if it is normal, the weight should be 10! = 55, the result is certainly not, because there is a heavy package, so X-10! Is the result.

2. Mouse Test Problems

There are 1000 bottles of medicine, and there are 10 little mice. The medicine can be mixed. If these mice are asked to take only one medicine, which bottle will be tested to be toxic?

First, compress the 1000 bottles of Medicine from 1 to 1000, compress the 10 mice into the numbers 1-10, and then convert the numbers 1-to binary, let the mice use their own serial numbers to test the targeted medicine, that is, the first dose of the mouse on the first day of the test, and the N dose of the mouse on the second day of the test, if the mouse is located, the first part is toxic. If no part is found, the second part is toxic. In this way, we can test the bitwise Number of the toxic drug and convert it to the 10th notation to know which drug is toxic.

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.