赛马题(转)
转自:http://intearview.com/post/2010/04/04/Ranganathgs-interview-at-google-company.aspx
You have 15 horses that run various speeds. You own a race track on which you can race the horses, and this track holds a maximum of 5 horses per race. If you have no stopwatch or other means of telling exactly how fast the horses are, how many races would you need to run between the horses to be ABSOLUTELY SURE which horses are first, second, and third fastest?
My Answer
Race 1: Horse 1,2,3,4,5 => Assume 1,2,3 win in that order
Race 2: Horse 6,7,8,9,10 => Assume 6,7,8 win in that order
Race 3: Horse 11,12,13,14,15 =>Assume 11,12,13 win in that order
Race 4: Horse 1, 6, 11 (all first place winners) =>Assume 1 wins first (1 is the fastest) for the sake of simplicity and 6 and 11 came 2nd and 3rd place
Race 5: Horse 6, 11, 2, 7, 3 - Notice I did not choose horse 12 in this race because we assumed from Race 4 that horse 11 came in third place so it is of no value having horse 12 in the race.
Total Race 5
1st Place is Horse 1, 2nd and 3rd Place is found from Race 5
5) Follow up, now you have 16 horses. How many races would you need to conduct to find first, second, and third?
My Answer
First three races are identical to the above three races
Assumption 1:
Race 4: Horse 16, 1, 6, 11 => Assume 16 wins first, and Horse 1 and 6 came second and third.
Race 5: Horse 1, 6, 2, 7, 3 =>Notice I did not choose any horses from Race 3 results, this is because we know that horse 11 did not come out in the top 3 in Race 4.
Total Race 5
Assumption 2:
Race 4: Horse 16, 1, 6, 11 => Assume 1 wins first, and Horse 6 and 16 came second and third.
Race 5: Horse 6, 16, 2, 7, 3=>Notice I did not choose any horses from Race 3 results, this is because we know that horse 11 did not come out in the top 3 in Race 4.
Total Race 5
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架