当前位置:网站首页>Tencent on the other hand, I was puzzled by the "horse race" problem
Tencent on the other hand, I was puzzled by the "horse race" problem
2022-06-24 16:33:00 【Programmer fish skin】
Classic interview questions that are difficult to answer right at one time , Everywhere is the pit
Hello everyone , I'm fish skin .
Today, I'd like to share an interview question that I have been baffled by , It is also an interview question often asked in the interview of a large factory , The question of horse racing .
The problem is not difficult , But the first time I was asked , A bit careless , You get the wrong answer . therefore , Let's study together !
problem
Yes 64 horse Race , There is no timing tool like a stopwatch , Only... Are allowed on the runway at a time 8 horse Simultaneous ratio , ask least It takes several races to choose the fastest one front 4 name ?
There are so many descriptions , You can think about it first , Then give the answer in the vote ~
( vote )
Here are the solutions and answers .
Their thinking
This topic is full of pitfalls , Any number change in the title will affect the final result , So be sure to clarify the key figures on the topic .
There are also many variations on the Internet , such as 36 horse 6 Look for the top three on each runway , But the ideas are the same , Let's simulate the whole course of the competition .
The first round
First , A maximum of... Is allowed on the runway 8 Horses compete at the same time , Then we must make the best use of resources , Every game should be full 8 horse .
So the first round is the easiest , No brain take 64 Horses are divided into 8 Group , Each group 8 A horse race Just fine , total 8 game .
Group number | Contestant |
|---|---|
Group 1 | |
Group 2 | |
Group 3 | |
Group 4 | |
Group 5 | |
Group 6 | |
Group 7 | |
Group 8 |
After this round , Because the title requires that before the election 4 name , therefore , The first of each group 4 The horse after the first place can be eliminated directly , And then there were 32 horse .
Group number | Contestant ( = The champion in the group ) |
|---|---|
Group 1 | |
Group 2 | |
Group 3 | |
Group 4 | |
Group 5 | |
Group 6 | |
Group 7 | |
Group 8 |
The second round
The second round begins , We must budget carefully .
The simplest way is to take the rest 32 Horses are divided directly into 4 Group to play , But in fact, using the information from the last round , We can have a better way .
Let the last round of competition , Each group 1 We will compete together 1 site , Then according to the results of this round of competition , Before election 4 Group .
The field :
The result of the game :
Group number | Contestant ( = The champion in the group ) |
|---|---|
Group 1 | |
Group 2 | |
Group 3 | |
Group 4 | |
|
The reason for this is : If the first place in a group can't get ahead 4, Then the rest of the group, Ma Keng, will not be able to get ahead 4, The whole group can be eliminated directly .
Up to now , There is still left 16 horse , Is this round of elimination over here ?
Not really , Take the group of the fourth ranked horse in this round as an example , The highest champion in this group is only the fourth , Then the other horses in this group can also be eliminated . Empathy , More horses can be eliminated , The remaining 10 horse .
Group number | Contestant ( = The champion in the group ) |
|---|---|
Group 1 | |
Group 2 | |
Group 3 | |
Group 4 |
Now there are still 10 horse , It seems that victory is close at hand , But in fact , The next step is the key !
The third round
Our next goal is to start from 10 Before the horse is chosen 4 name , But a game can only accommodate 8 horse , That seems to be at least two more games .
Step by step , Choose... First 8 A horse race , The question is which one to choose 8 Where's the horse ?
I don't know if you found out , Inadvertently , The champion has been born , That's the horse that hasn't failed both inside and outside the team , The best of the best !
Group number | Contestant ( = The champion in the group ) |
|---|---|
Group 1 | |
Group 2 | |
Group 3 | |
Group 4 |
therefore , It doesn't have to be compared , The goal becomes , From surplus 9 Choose the second horse from the horses 2 - 4 name .
Let's choose whatever 8 Let's race the horses first , Before election 3 name .
Group number | Contestant ( = The champion in the group ) |
|---|---|
Group 1 | To play |
Group 2 | To play |
Group 3 | To play |
Group 4 | 🦓( A horse that has not competed ) |
So the last round , We also need to keep the horse that was not compared with the previous round with the front 3 Namebee 1 site , What if someone is a dark horse ?
The field : 🦓
thus , The answer comes out , Minimum need 8 + 1 + 1 + 1 = 11 site .
However , This is a wrong answer !
Actually , There are better solutions !
There is still 9 When the horse , If you don't choose 8 A horse race , Instead, remove the group first 2 The winner of the , Leave 8 A horse race .
If this game , Group 3 The champion won the first place , So, since the group has been proved before 2 The champion is better than the group 3 The winner of the , Before 4 The name has been determined , Just compare 10 site . If it's not the first , Then it's still more than one game .
So the correct answer is , Minimum need 10 site , Did you do it right ?
Last , Why does this question appear in the programmer interview ? Smart you must have found out , The above-mentioned horse racing problem is essentially a TopN( Take the top ) problem , It can be solved by divide and conquer , It is a classical algorithmic thinking . If it is in a distributed system , It shows Parallel computing The advantages of , Available resources ( Such as the 8 A track ) Calculate simultaneously for each group , So as to improve the operation efficiency . Besides , It is also very important to use the existing data results .
Have a good weekend , Don't forget to order the fish skin Fabulous Support me !️
边栏推荐
- @There is a free copyright protection service for enterprises in Dawan District
- What is Ethernet
- 对深度可分离卷积、分组卷积、扩张卷积、转置卷积(反卷积)的理解
- AI video structured intelligent security platform easycvr realizes intelligent security monitoring scheme for procuratorate building
- If only 2 people are recruited, can the enterprise do a good job in content risk control?
- Where is the most formal and safe account opening for speculation futures? How to open a futures account?
- How to pop up an alarm through the national standard gb28181 protocol video platform easygbs for mobile detection / perimeter intrusion detection video recording
- Is Guotai Junan Futures safe? How to open a futures account? How to reduce the futures commission?
- MySQL日期时间戳转换
- MySQL Innodb和Myisam
猜你喜欢

B. Terry sequence (thinking + greed) codeforces round 665 (Div. 2)
Advanced programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization
![[go] concurrent programming channel](/img/6a/d62678467bbc6dfb6a50ae42bacc96.jpg)
[go] concurrent programming channel

C. K-th Not Divisible by n(数学+思维) Codeforces Round #640 (Div. 4)
MySQL進階系列:鎖-InnoDB中鎖的情况

ZOJ——4104 Sequence in the Pocket(思维问题)

Cap: multiple attention mechanism, interesting fine-grained classification scheme | AAAI 2021

There are potential safety hazards Land Rover recalls some hybrid vehicles

Applet - use of template

B. Ternary Sequence(思维+贪心)Codeforces Round #665 (Div. 2)
随机推荐
What does the router pin mean?
Cognition and difference of service number, subscription number, applet and enterprise number (enterprise wechat)
[tke] analysis of CLB loopback in Intranet under IPVS forwarding mode
Applet wxss
Fastjson vulnerability utilization techniques
Join in ABAP CDs
How to select an open source license
A memory leak caused by timeout scheduling of context and goroutine implementation
【prometheus】1. Monitoring overview
How does easydss, an online classroom / online medical live on demand platform, separate audio and video data?
Global and Chinese market for commercial barbecue smokers 2022-2028: Research Report on technology, participants, trends, market size and share
It may be a good idea to use simulation software in the cloud for simulation
D. Solve the maze (thinking +bfs) codeforces round 648 (Div. 2)
A set of very good H3C and Tianrongxin Internet cutover scheme templates, with word document download
Is Guotai Junan Futures safe? How to open a futures account? How to reduce the futures commission?
Page scrolling effect library, a little skinny
Development trend of CAE simulation analysis software
Experience and suggestions on cloud development database
Dismantle the industrial chain of synthetic rubber industry, and the supply chain may become a sharp weapon for breakthrough
山金期货安全么?期货开户都是哪些流程?期货手续费怎么降低?