Binary Puzzles--1000 apple questions

Source: Internet
Author: User

Tonight, I turned out an interesting question in my previous collection--the 1000-pack of apples:

Now there are 1000 apples, and 10 boxes, how to put the 1000 apples in these 10 boxes, in order to make any number (1-1000) of apples, can be given at once?

Typical binary number variants, 1000 apples, closest to 1024, converted to 2 binary, 10 bit required, then from right to left, the first bit to represent 1 apples, the second bit to represent 2 apples, the third bit to represent 4 apples,, The 10th bit bit represents 488 apples (512-24). Put these through in the same numbered box respectively. When a certain number of apples are needed, check which bits of these numbers are 1 and 1 indicate that the bit bit represents an apple and the corresponding numbered box is taken out.

There are other Bo friends that Amoy to the poison problem, similar:

There are 8 bottles of liquid, one bottle is poison, toxicity can make the mice after drinking in 20 hours killed, need a few mice to determine in 20 hours which bottle is poison?

Analysis:

To encode 8 bottles of poison:

First bottle: 000

Second bottle: 001

Third bottle: 010

Bottle IV: 011

Bottle Five: 100

Six-Ping: 101

Seventh Draw: 110

Eighth draw: 111

Just 3 little mice.

The first mouse drank the last bit of 1, that is, the 2,4,6,8 bottle.

The second mouse drank a median bit of 1, the first 3,4,7,8 bottle

The third mouse drank the first bit of 1, that is, the 5,6,7,8 bottle.

If there is no mouse death in 20, the first bottle is poisonous, otherwise:

Suppose the second and third mouse die, set the corresponding bit to 1, or 110, so the 7th bottle is poisonous.

Binary Puzzles--1000 apple questions

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.