Smart question collection

Source: Internet
Author: User
1st train Coal Transportation

You are a coal boss in Shanxi province. You have mined 3000 tons of coal in the mining area and need to transport it to the market for sale. there are 1000 kilometers from your mining area to the market, there is a coal-burning train in your hand. This train can only hold up to 1000 tons of coal, and its energy consumption is relatively high-each kilometer consumes one ton of coal. How can you transport the most suitable coal to the market as a programmer?

This question seems to have no solution at first, because each kilometer of your train consumes one ton of coal, and the destination is 1000 kilometers, while the train can only load 1000 tons of media at most. If all your trains can be loaded, all the trains will be burned out at the destination. Therefore, many people think this is unlikely in their first response.

It would be normal if you thought it was not possible at the beginning. But I don't know if you will continue to think about it. If you don't want to think about it, then I am worried about you because you may not be a bad thinker, but a person who is afraid of difficulties, or who is easy to give up. This may not be suitable for a programmer who needs to think a lot.

I thought it was impossible at the beginning. Later I thought about it and thought of a solution that could transport up to 500 tons of coal to the market.


XI

Hope

You

First

From

Ji

Think

I

Think

Again

Query

View

Answer:

Case

[Reference answer]

  1. Loaded 1000 tons of coal, took 250 kilometers, dropped 500 tons of coal, back to the mine.
  2. Load 1000 tons of coal, go to 250 kilometers, pick up 250 tons of coal and continue to 500 kilometers forward, drop 500 tons of coal, back to the mine. At this time, there are still 250 tons on the train, plus 250 tons of coal at 250 km, so the train can be returned to the mine.
  3. Mount the last 1000 tons of coal, walk to 500 kilometers, install the 500 tons of coal there, and then continue to reach the goal. Therefore, you can transport up to 500 tons of coal to the market (of course, the train cannot go back because the mine has no coal)

It seems like this is good, but there are better ways to run more media. Do you know this method? It can be noted that the above method is used. I will not release the answer for the moment. You can think about it by yourself.

533 is the optimal solution.

Above Reprinted from here: http://coolshell.cn/articles/4429.html

2nd horse racing Problems

It is said that this is Google's interview question. The interview questions are as follows:

There are a total of 25 horses and a game venue with 5 tracks. That is to say, a maximum of five horses can be played together. Assume that each horse runs very stably and does not use any other tools. It only passes the competition between the horse and the horse, which of the following five horses can be found at least? (The collision algorithm cannot be used)

Obviously, this is an algorithm question. Many posts on the Internet are discussing this question, but no definite answer is provided. I thought about the following algorithm:

1) divided into five groups: A, B, C, D, E. Sort the five horses in the five groups (from fast to slow) based on each result ).
2) the first name of each group matches again, takes the first name, and then the second name of the group is topped.
3) Repeat Step 2 until the first five members are selected.

This algorithm is a relatively stupid algorithm, which requires 10 matches in total. This algorithm should be foolproof. Now the question is how to optimize this algorithm. I thought about it. There is indeed room for optimization. That is to say, it can be less than 10 times.

After thinking about it, the above algorithm used the top names of five sort arrays as the "Bubble Method" since 6th times, always pick the best one. In fact, in addition to picking out the best ones after the first round, we can also get rid of some slower ones after each round. The number of eliminated horses is naturally more than the number of horses, on the one hand, we are looking for it, and on the other hand, we are eliminating it. It should be faster to find the top five.

For example, after the sixth round of the competition, we will get the following sorting: (each group is sorted from left to right, and each group is sorted from top to bottom)

Group A A1 A2 A3 A4 A5
Group B B1 B2 B3 B4 B5
Group C C1 C2 C3 C4 C5
Group D D1 D2 D3 D4 D5
Group E E1 E2 E3 E4 E5

In this way, we not only know that A1 is the fastest horse in 25 Mali, but we can also eliminate nearly half of the horses, such as E2, E3, E4, and E5, why? Because there are A1, B1, C1, D1, and E1 horses faster than E2, the horses behind E2 cannot enter the first five. Likewise, d3 and the latter cannot enter the first 5. Similarly, C4, C5, and B5 can be eliminated.

Therefore, after the sixth round, we can know that the top 4 except A1:

Group A A2 A3 A4 A5
Group B B1 B2 B3 B4
Group C C1 C2 C3
Group D D1 D2
Group E E1

I don't need to talk about the next process. Repeat the previous method to try to eliminate the first n horses, so there will be fewer and fewer horses behind them and fewer games you need.

So, do you know the minimum number of matches for this question?

What if there are 64 horses and 8 tracks? If there are n horses and M tracks? N = m * M. What is the formula?

Looking forward to your answer!

Above Reprinted from here: http://coolshell.cn/articles/1202.html/comment-page-1#comments

***************

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.