zoukankan      html  css  js  c++  java
  • 过桥谜题Bridge and torch problem

    老外面试时候考的逻辑题——网上找了个类似的

    题目1:Four people come to a river in the night. There is a narrow bridge, but it can only hold two people at a time. They have one torch and, because it's night, the torch has to be used when crossing the bridge. Person A can cross the bridge in one minute, B in two minutes, C in five minutes, and D in eight minutes. When two people cross the bridge together, they must move at the slower person's pace. The question is, can they all get across the bridge in 15 minutes or less?

    四个人晚上过一个窄桥,桥每次只能通过两个人;过桥的时候必须用到火炬,但四个人只有一个火炬;其中A过桥需要1分钟,B需要2分钟,C需要5分钟,D需要8分钟,而且两个人一起过桥的时候必须以比较慢的人的步伐为准,问四个人如何在15分钟或更少的时间全部通过?

    解答:

    比较常见的逻辑,花费17分钟

    所花时间Elapsed Time开始边Starting Side动作Action结束边Ending Side
    0 minutes A B C D    
    2 minutes       C D A和B 过桥,耗时2分钟 A B
    3 minutes A    C D A返回,耗时1分钟    B
    8 minutes          D A和C 过桥,耗时5分钟 A B C
    9 minutes A       D A返回,耗时1分钟    B C
    17 minutes   A和C 过桥,耗时8分钟 A B C D

    比较妙的逻辑,花费15分钟

    所花时间Elapsed Time开始边Starting Side动作Action结束边Ending Side
    0 minutes A B C D    
    2 minutes       C D A和B 过桥,耗时2分钟 A B
    3 minutes A    C D A返回,耗时1分钟    B
    11 minutes A D和C 过桥,耗时8分钟    B C D
    13 minutes A B B返回,耗时2分钟       C D
    15 minutes   A和B 过桥,耗时2分钟 A B C D

    题目2:盒子里放了黑白两种颜色各十个球,蒙上双眼取球,要求每次取一个,要取多少次才能确保取出来的球有一对颜色一样的球?

           两次?

            你能保证你运气那么好吗?万一前两次分别拿到一黑一白呢?
            那是十一次?
            晕!
            哦,是三次。
            恭喜你,答对了。加十分!那么盒子里放了黑白红三种颜色各十个球,要求每次取一个,要取多少次才能确保有一对颜色一样的球?黑白红黄四种颜色呢?问题如前。
            分别是四次和五次。
            真聪明!有律可循否?
            当然,球的颜色基数加1。
  • 相关阅读:
    【vim使用】替换文本
    Ubuntu中将vim中查找设置为高亮
    【vim使用】查找文本
    【vim使用】缩进 和 重复执行上一次命令
    【vim使用】替换命令
    【vim使用】复制和粘贴
    【vim使用】撤销和恢复撤销
    【vim使用】删除文本
    【vim使用】选中文本(可视模式)
    【vim使用】利用标记返回之前需要编辑的代码位置
  • 原文地址:https://www.cnblogs.com/JoannaQ/p/2968503.html
Copyright © 2011-2022 走看看