Algorithm title------"A bucket of 100 white balls, 100 black balls, the last one is the probability of a black ball? 】

Source: Internet
Author: User


today to see an interesting topic, heard is "The beauty of programming" in a problem, instantly feel that they are a lot behind. Take out today and share my insights on this topic!

The original problem: a bucket with 100 black balls, 100 white balls. Take the ball in the bucket in the following order:

1. Take out 2 balls at a time;

2. If the same color ball is put back a black ball;

3. If the ball is a different color, put back a white ball.

I was very excited to see the brain at first sight, isn't that the probability problem of high school? Then I started to oracleof the bottom of the pen, and I didn't say it. It took quite a long time anyway. Later turned to see his answer, I suddenly have a feeling of jumping. The world only with few words to solve the problem, I spent a long time unexpectedly the result is wrong. In short I said nothing, the following analysis of the answer to the question:

First we see the problem do not act recklessly, we must first learn to analyze the problem, we follow his process can draw the following results:

1. Each time a ball will be taken out, the total bucket will only have one ball left. (We've got 50% of answers here,

So I can get the answer right here.

2. Note at 2nd, 3, we can actually find that the change in the number of spin placed struck each time is double or 0.

So it's impossible to have a white ball in the bucket at the end. (Now we're 100% sure the black ball is the last one)

Right is so simple, this is the difference, as if we from A to B is only 100 meters, but you have to go around 1000 meters of the road, may be in the real life will say you enjoy life process, but we are solving the problem, the faster the solution, and the simpler the method, this is the result we want ultimately. So, sometimes we need to be flexible and don't get into problems and make him more complicated. Most of the time you make, uh, things must be eliminated soon.


Algorithm title------"A bucket of 100 white balls, 100 black balls, the last one is the probability of a black ball? 】

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.