《A Practical Guide To Quantitative Finance Interviews》,被称为量化绿皮书,是经典的量化求职刷题书籍之一,包含以下七章:
Chapter 1 General Principles 通用技巧
Chapter 2 Brain Teasers 脑筋急转弯
Chapter 3 Calculus and Linear Algebra 微积分与线性代数
Chapter 4 Probability Theory 概率论
Chapter 5 Stochastic Process and Stochastic Calculus 随机过程与随机微积分
Chapter 6 Finance 金融
Chapter 7 Algorithms and Numerical Methods 算法与数值方法
目录
文章目录
2.1 Problem Simplification 问题简化
2.1.1 Screwy pirates 海盗分金
五个海盗抢劫了一个装满100枚金币的箱子。作为一群民主的海盗,他们同意以下分配战利品的方法:
- 最资深的海盗将提出分配金币的建议。所有的海盗,包括最资深的海盗,都将投票。
- 如果至少有**50%**的海盗接受这个提议,那么金币将按照提议进行分配。如果不是,最年长的海盗将被喂给鲨鱼,这个过程将从下一个最年长的海盗开始。
- 重复这个过程,直到计划获得批准。
假设所有海盗都是完全理性的:他们首先想要活命,然后再尽可能多地获得金币。最后,作为嗜血的海盗,如果让他们在两种结果相等的情况下做出选择,他们希望船上的海盗更少。
金币最终会如何分配?
Five pirates looted a chest full of 100 gold coins. Being a bunch of democratic pirates, they agree on the following method ot divide the loot:
The most senior pirate will propose a distribution of the coins. All pirates, including the most senior pirate, will vote. If at least 50% of the pirates(3 pirates in this case) accept the proposal, the gold is divided as proposed. If not, the most senior pirate will be fed to shark and the process starts over with the next most senior pirate… The process is repeated until a plan is approved. You can assume that all pirates are perfectly rational: they want to stay alive first and to get as much gold as possible second. Finally, being blood-thirsty pirates, they want ot have fewer pirates on the boat if given a choice between otherwise equal outcomes.
How will the gold coins be divided in the end?
答案:(98,0,1,0,1)。
从一个海盗开始推理:
- 一个海盗:分法为(100);
- 两个海盗:最资深的(第一个)海盗占50%的投票,分法为(100,0);
- 三个海盗:最资深的(第一个)海盗还需要一票,对第三个海盗来说,如果提议被否决,自己会一无所获**(成为两个海盗中的第二个海盗)**,因此最资深的(第一个)海盗给第三个海盗1枚金币就可以获得2/3的支持,分法为(99,0,1);
- 四个海盗:最资深的(第一个)海盗还需要一票,对第三个海盗来说,如果提议被否决,自己会一无所获**(成为三个海盗中的第二个海盗)**,因此最资深的(第一个)海盗给第三个海盗1枚金币就可以获得2/4的支持,分法为(99,0,1,0);
- 五个海盗:最资深的(第一个)海盗还需要两票,对第三个和第五个海盗来说,如果提议被否决,自己会一无所获**(成为四个海盗中的第二个和第四个海盗)**,因此最资深的(第一个)海盗分别给第三个和第五个海盗1枚金币就可以获得3/5的支持,分法为(98,0,1,0,1)。
最资深的海盗分别用1枚金币拉拢第三个、第五个、第七个、第2n+1个海盗使提议被接受:
- 对2n+1个海盗(1<n<金币数-1),分法为(剩余金币,0,1,0,1,……,1)
- 对2n+2个海盗(1<n<金币数-1),分法为(剩余金币,0,1,0,1,……,0)
2.1.2 Tiger and sheep 老虎和羊
一百只老虎和一只羊被放在一个只有草的魔法岛上。
-
老虎可以吃草,但它们更喜欢吃羊。
-
每次只能有一只老虎吃掉一只羊,而老虎吃掉羊后自己也会变成一只羊。
-
所有的老虎都很聪明,非常理性,它们想要生存。
那么羊会被吃掉吗?
One hundred tigers and one sheep are put on a magic island that only has grass. Tigers can eat grass, but they would rather eat sheep. Assume: A. Each time only one tiger can eat one sheep, and that tiger itself wil become a sheep after it eats the sheep. B. Al tigers are smart and perfectly rational and they want to survive. So will the sheep be eaten?
答案:不会。
从一只老虎开始推理:
- 一只老虎:羊会被吃掉。因为老虎吃掉羊之后没有其他老虎吃它;
- 两只老虎:羊不会被吃掉。因为吃掉羊的那只老虎会变成羊,被另外一只老虎吃掉**(回到一只老虎的情况**);
- 三只老虎:羊会被吃掉。因为吃掉羊的那只老虎虽然会变成羊,但不会被另外两只老虎之一吃掉**(回到两只老虎的情况)**;
- 四只老虎:羊不会被吃掉。因为吃掉羊的那只老虎会变成羊,被另外三只老虎之一吃掉**(回到三只老虎的情况)**,为了保证最大的生存可能性,没有老虎会吃掉绵羊。
以此类推,100只老虎时羊不会被吃掉。
偶数只老虎时,羊不会被吃掉;奇数只老虎时,羊会被吃掉
2.2 Logic Reasoning 逻辑推理
2.2.1 River crossing 快速过河
A、B、C、D四个人需要过河,过河的唯一办法是走一座旧桥,一次最多只能容纳两个人。天黑了,他们没有火炬就过不了桥,而他们只有一支火炬,所以每一对都只能以较慢的人的速度行走,他们需要尽快把所有人送到对岸。
- A最慢,需要10分钟才能通过
- B需要5分钟
- C需要2分钟
- D需要1分钟
过河的最短时间是多少?
Four people, A, B, C, and D need to get across a river. The only way to cross the river is by an old bridge, which holds at most 2 people at a time. Being dark, they can’t cross the bridge without a torch, of which they only have one. So each pair can only walk at the speed of the slower person. They need to get all of them across to the other side as quickly as possible. A is the slowest and takes 10 minutes to cross; B takes 5 minutes; C takes 2 minutes; and D takes 1 minute.
What is the minimum time to get all of them across to the other side?
答案:17分钟。
因为每一对都只能以较慢的人的速度行走,为了不浪费时间和速度,快的和快的一起过,慢的和慢的一起过。此外还要考虑要把火炬送回来,为了让快的送,快的组合先走。
- 第一趟:C、D一起过,2min
- D返回送火炬,1min
- 第二趟:A、B一起过,10min
- C返回送火炬,2min
- 第三趟:C、D一起过,2min
最短时间2+1+10+2+2=17min
2.2.2 Birthday problem 猜生日
你和你的同事都知道你老板A的生日是以下10个日期之一:
3月4日、3月5日、3月8日
6月4日、6月7日
9月1日、9月5日
12月1日、12月2日和12月8日
A告诉你他生日的月份,告诉同事C他生日的号数。
- 你先说:“我不知道A的生日,C也不知道。”
- 听了你的话,C回答:“我以前不知道A生日,但现在我知道了。”
- 你笑着说:“现在我也知道了。“
在看了10个日期并听取了你的意见后,你的行政助理没有问任何问题就写下了A的生日。那么助理写了什么?
You and your colleagues know that your boss A’s birthday is one of the following 10 dates:
Mar 4, Mar 5, Mar 8 Jun 4, Jun 7
Sep 1, Sep 5
Dec 1, Dec 2, Dec 8
A told you only the month of his birthday, and told your colleague C only the day. After that, you first said: “I don’t know A’s birthday; C doesn’t know it either.” After hearing what you said, C replied: “I didn’t know A’s birthday, but now I know it.” You smiled and said: “Now I know it, too.” After looking at the 10 dates and hearing your comments, your administrative assistant wrote down A’s birthday without asking any questions. So what did the assistant write?
答案:9月1日
不要让“他说,她说”的部分混淆你。只需解释每个人评论背后的逻辑,并尽最大努力从这些评论中获得有用的信息。从助理的角度分析
- 你先说:“我不知道A的生日,C也不知道。”
- ”我不知道A的生日“:月份都有重复,没有信息
- ”C也不知道”:号数中7日和2日非重复,因此月份一定不是这两个号数所在的月份**(月份是3月或9月)**
- 听了你的话,C回答:“我以前不知道A生日,但现在我知道了。”
- “我以前不知道A生日,但现在我知道了”:C在知道月份是3月或9月后,就知道了月份,因此号数没有同时出现在3月和9月**(号数不是5日)**
- 你笑着说:“现在我也知道了。“
- “现在我也知道了“:我在知道号数不是5日后,就知道了号数,因此在去掉5日后该月份只剩一个日期**(月份是9月,日期是9月1日)**
2.2.3 Card game 纸牌游戏
赌场提供一种使用一副普通52张牌的纸牌游戏。
规则是你每次交出两张牌,对于每一双,如果都是黑色的,它们就会进入经销商的牌堆;如果两者都是红色的,它们就会进入你的牌堆;如果一个是黑色,一个是红色,它们就会被丢弃。重复这个过程,直到你们两个用完所有52张牌。
如果你的牌堆里有更多的牌,你就赢了100美元;**否则(包括牌数相同)**你一无所获。
赌场允许你协商你想为游戏支付的价格。你愿意花多少钱玩这个游戏?
A casino offers a card game using a normal deck of 52 cards. The rule is that you turn over two cards each time. For each pair, if both are black, they go to the dealer’s pile; if both are red, they go to your pile; if one black and one red, they are discarded. The process is repeated until you two go through all 52 cards. If you have more cards in your pile, you win $100; otherwise (including ties) you get nothing. The casino alows you ot negotiate the price you want to pay for the game. How much would you be willing to pay to play this game?
答:0。
无论怎么玩,最终双方的牌数都是相同的,我总是一无所获。
除了被丢弃的卡之外,剩余所有的黑卡都是经销商的,所有的红卡都是我的,而每一次丢弃都是一张黑色,一张红色,不会影响剩余的黑卡和红卡数量相等,最后双方的牌数都是相同的。
2.2.4 Burning ropes 烧绳计时
你有两根绳子,每根绳子都可以燃烧一个小时。 但是任何一根绳子密度不均,密的地方烧的慢,疏的地方烧的快,不能保证绳子不同段燃烧速度的一致性。
你如何用这两条绳子测量45分钟?
You have two ropes, each of which takes 1 hour to burn. But either rope has different densities at different points, so there’s no guarantee of consistency in the time it takes different sections within the rope to burn. How do you use these two ropes ot measure 45 minutes?
答案:烧两头。
密度不均意味着在空间上不会在一半的地方上相遇,但在时间上肯定在一半的时间上相遇。
烧两头,时间为1/2
- 先点燃第一根绳子的两头和第二根绳子的一头
- 第一根绳子烧完意味着30分钟(60/2),第二根绳子还可以燃烧30分钟(60-30)
- 再点燃第二根的另一头
- 第二根绳子烧完意味着15分钟(30/2),加起来45分钟
2.2.5 Defective ball 找次品球
你有12个相同的球。其中有一个次品球,可能比其他球重,也可能比其他球轻。使用一个只能显示哪一侧较重的天平,如何通过3次测量来确定哪个球是次品球?
You have 12 identical balls. One of the balls is heavier OR lighter than the rest (you don’t know which). Using just a balance that can only show you which side of the tray is heavier, how can you determine which ball is the defective one with 3 measurements?
总体思路原则:
- 将球分成三组,而不是两组,两组之间的比较结果可以提供第三组的信息;
- 使用已知的正常球构造中间的分组,减少不确定性;
- 剩下待定的球中,
- 如果两个球有相同可能的问题(9/10 L or 11 H),对比两个球
- 如果两个球有不同可能的问题(5 H or 3 L),或一个球有多种可能的问题(12 L or 12 H),将一个球与已知的正常球对比
将球标记为1-12号,并分为3组,每组4个球。
**第一步:**对比(1,2,3,4)和(5,6,7,8)
-
情况1:(1,2,3,4)比(5,6,7,8)轻(重的话相当于换一下标记),次品球在(1,2,3,4)中且为轻,或在(5,6,7,8)中且为重**(1/2/3/4 L or 5/6/7/8 H)**
**第二步:**对比(1,2,5)和(3,6,9)(从第一组中取1,2,3;从第二组中取5,6;取已知的正常球9)
-
情况1.1:(1,2,5)比(3,6,9)轻,次品球在(1,2)中且为轻,或为6且为重**(1/2 L or 6 H)**
第三步:对比1和2
- 情况1.1.1:1比2轻,1为轻次品球**(1 L)**
- 情况1.1.2:1和2平衡,6为重次品球**(6 H)**
- 情况1.1.3:1比2重,2为轻次品球**(2 L)**
-
情况1.2:(1,2,5)和(3,6,9)平衡,次品球为4且为轻,或在(7,8)中且为重**(4 L or 7/8 H)**
第三步:对比7和8
- 情况1.2.1:7比8轻,8为重次品球**(8 H)**
- 情况1.2.2:7和8平衡,4为轻次品球**(4 L)**
- 情况1.2.3:7比8重,7为重次品球**(7 H)**
-
情况1.2:(1,2,5)比(3,6,9)重,次品球为5且为重,或为3且为轻**(5 H or 3 L)**
第三步:对比3和9
- 情况1.3.1:3比9轻,3为轻次品球**(3 L)**
- 情况1.3.2:3和9平衡,5为重次品球**(5 H)**
-
-
情况2:(1,2,3,4)和(5,6,7,8)平衡,次品球在(9,10,11,12)中,但轻重不定**(9/10/11/12 L or H)**
**第二步:**对比(9,10)和(8,11)(从第三组中取9,10,11;取已知的正常球8)
-
情况2.1:(9,10)比(8,11)轻,次品球在(9,10)中且为轻,或为11且为重**(9/10 L or 11 H)**
第三步:对比9和10
- 情况2.1.1:9比10轻,9为轻次品球**(9 L)**
- 情况2.1.2:9和10平衡,11为重次品球**(11 H)**
- 情况2.1.3:9比10重,10为轻次品球**(10 L)**
-
情况2.2:(9,10)和(8,11)平衡,次品球为12,但轻重不定**(12 L or 12 H)**
第三步:对比8和12
- 情况2.2.1:8比12轻,8为轻次品球**(12 H)**
- 情况2.2.2:8比12重,8为重次品球**(12 L)**
-
情况2.3:(9,10)比(8,11)重,次品球在(9,10)中且为重,或为11且为轻**(9/10 H or 11 L)**
第三步:对比9和10
- 情况2.3.1:9比10轻,10为重次品球**(10 H)**
- 情况2.3.2:9和10平衡,11为轻次品球**(11 L)**
- 情况2.3.3:9比10重,9为重次品球**(9 H)**
-
如果次品球轻重已知, n n n次测量可以确定 3 n 3^n 3n个球中的一个次品球
如果次品球轻重未知, n n n次测量可以确定 ( 3 n − 3 ) / 2 (3^n-3)/2 (3n−3)/2个球中的一个次品球
2.2.6 Trailing zeros 阶乘尾部的0
100阶乘100!尾部有几个0?
How many trailing zeros are there in 100! (factorial of 100)?
答案:24。
分解后每对2和5会在尾部产生一个0,而分解后2的数量显然比5的数量多得多,所以尾部0的个数取决分解后有多少个5。
- (5,10,……,100)分解出20个5得(1,2,……,20)
- (1,2,……,20)中(5,10,15,20)分解出4个5得(1,2,3,4),不能继续分解了
100/5 + 100/5/5 = 20 + 4 =24
2.2.7 Horse race 找最快的马
有25匹马,每匹马都以不同于其他马的恒定速度奔跑。由于赛道只有5条车道,每场比赛最多可以有5匹马。如果你需要找到3匹最快的马,那么识别它们所需的最低比赛次数是多少?
There are 25 horses, each of which runs at a constant speed that is different from the other horses. Since the track only has 5 lanes, each race can have at most 5 horses. If you need ot find the 3 fastest horses, what is the minimum number of races needed to identify them?
答案:7次。
将马标记为1-25号,并分为5组,每组5匹马。(假设数字和速度正比)
- 第一步:每组分别进行一场比赛,淘汰每组的后两名(4-5,9-10,14-15,19-20,24-25)
- 第二步:每组第一名(1,6,11,16,21)进行一场比赛,第一名为整体第一名,淘汰后两名所在组的全部(16-18,21-23),淘汰第三名所在组的第二名和第三名(12,13),淘汰第二名所在组的第三名(8)
- 第三步:剩下的候选人(2,3,6,7,11)进行一场比赛,前两名为整体第二名和第三名
5+1+1=7次
2.2.8 Infinite sequence 无限序列
x x x$x$ x x x$x$ x . . . = 2 x...=2 x...=2,其中 x x x^ y = x y y= x^y y=xy,求 x x x?
If x x x$x$ x x x$x$ x . . . = 2 x...=2 x...=2, where x x x^ y = x y y= x^y y=xy , what is x x x?
答案: x = 2 x=\sqrt2 x=2
x x x$x$ x x x$x$ x . . . = x...= x...= x x x$(x$ x x x$x$ x . . . ) = x x...)=x x...)=x^ 2 = 2 2=2 2=2
所以 x = 2 x=\sqrt2 x=2
2.3 Thinking Out of the Box 跳出思维的框架
2.3.1 Box packing 打包箱子
你能把53块1x1×4的小砖块装进一个6x6x6的箱子里吗?
Can you pack 53 bricks of dimensions 1x1×4 into a 6x6x6 box?
答案:不能。
配色法,国际象棋问题(二维)的升级版(三维)
国际象棋问题:你有一个8x8的国际象棋棋盘,去掉了对角的两个小方块。你能把31块1×2的小方格装进剩下的62个方格里吗?(棋盘天然黑白相间,容易理解配色法)
答案:不能。
不管怎么放1x2的方格,都会占据1黑1白两个方格,因此最多能放几个1x2方格,取决于黑方块和白方块数量较小值。去掉了对角的两个黑方块,剩下30个黑方块和32个白方块,最多只能把30块1×2的小方格装进剩下的62个方格里。
参考国际象棋问题的解法,让1x1×4的小砖块占据两个色块(长度为2),色块为与箱子相似的正方体,所以每个黑或白色块大小为2x2x2,共27个。黑白相间,只能为14黑13白或13黑14白。
每个小砖块必须一半在黑色块,一半在白色块中,1黑1白两个色块可以装4个小砖块,因此箱子最多只能装4x13=52个小砖块,有一个色块浪费。
2.3.2 Calendar cubes 日历骰子
你有两个自制的骰子,如何分别在两个骰子6个面上刻上个位数,使得每天早上可以排列骰子显示当前日期(仅号数)?
- 必须同时使用两个骰子(1-9号必须显示为01-09)
You just had two dice custom-made. Instead of numbers 1- 6, you place single-digit numbers on the faces of each dice so that every morning you can arrange the dice in a way as to make the two front faces show the current day of the month. You must use both dice (in other words, days 1 - 9 must be shown as 01 - 09), but you can switch the order of the dice if you want. What numbers do you have to put on the six faces of each of the two dice to achieve that?
答案:一个骰子刻012345,一个骰子刻012678。
0-9十个数字,骰子12个面
- 重复数字的11号和22号:1和2两个骰子都要刻
- 1-9号需要显示为01-09:0两个骰子都要刻(1-9分布在两个骰子上)
- 6和9对称,且不会同时被使用:9不用刻
012两个骰子都刻,剩下6个面分别刻345678
2.3.3 Door to offer Offer之门
两个守卫守着两扇门,一扇通向offer,一扇通向fail。两个守卫一个诚实(总是说实话),一个狡猾(总是说谎)。你不知道谁守着offert之门,只能问一个守卫一个只能用是/否回答的问题,如何才能打开offer之门?
You are facing two doors. One leads to your job offer and the other leads to exit. In front of either door is a guard. One guard always tells lies and the other always tells the truth. You can only ask one guard one yes/no question. Assuming you do want to get the job offer, what question will you ask?
答案:问一个守卫**“另一个守卫会说你守的是offer之门吗?”**如果守卫说“是”,则选另一扇门;如果守卫说“否”,则选他守着的门。
关键在于让问题关联到两个守卫。
- 如果问的是守着offer之门的诚实守卫,因为另一个狡猾守卫会说谎说**“否”,因此这个诚实守卫会实话说另一个守卫说“否”**;
- 如果问的是守着offer之门的狡猾守卫,因为另一个诚实守卫会实话说**“是”,因此这个狡猾守卫会说谎说另一个守卫说“否”**;
- 如果问的是守着fail之门的诚实守卫,因为另一个狡猾守卫会说谎说**“是”,因此这个诚实守卫会实话说另一个守卫说“是”;**
- 如果问的是守着fail之门的狡猾守卫,因为另一个诚实守卫会实话说**“否”,因此这个狡猾守卫会说谎说另一个守卫说“是”**。
因此,问的守卫说“否”对应着他守着offer之门,问的守卫说“是”对应着他守着fail之门。
2.3.4 Message delivery 挂锁快递
你和在格林威治的同事传递文件,快递要上锁才安全,不然东西会丢。你和你同事各自有一把锁和一把对应的钥匙,怎么才能安全地传递文件?
You need to communicate with your colleague in Greenwich via a messenger service. Your documents are sent in a padlock box. Unfortunately the messenger service is not secure, so anything inside an unlocked box will be lost (including any locks you place inside the box) during the delivery. The high-security padlocks you and your colleague each use have only one key which the person placing the lock owns. How can you securely send a document to your colleague?
答案:
- 第一趟(去):我挂上自己的锁,快递安全送到格林威治(此时同事打不开快递)
- 第二趟(回):同事再挂上他的锁,快递安全回来(此时我打不开快递)
- 第三趟(去):我解开自己的锁,再安全快递到格林威治(此时同事可以打开快递)
通过多次运输来保证安全。
2.3.5 Last ball 最后一个球的颜色
袋子有20个蓝球和14个红球,每次随机取出两个球,不放回。
- 如果两个球颜色相同,则在袋子中添加一个蓝球
- 如果两个球颜色不同,则在袋子中添加一个红球
假设你有无限量的蓝球和红球,无限重复这个过程,袋子里最后一个球的颜色会是什么?
如果袋子里有20个蓝球和13个红球呢?
A bag has 20 blue balls and 14 red balls. Each time you randomly take two balls out. (Assume each ball in the bag has equal probability of being taken). You do not put these two balls back. Instead, if both balls have the same color, you add a blue ball to the bag; if they have different colors, you add a red ball to the bag. Assume that you have an unlimited supply of blue and red balls, if you keep on repeating this process, what will be the color of the last ball left in the bag? What if the bag has 20 blue balls and 13 red balls instead?
答案:蓝球(20个蓝球和14个红球);红球(20个蓝球和13个红球)。
组合(丢弃) | 添加 | 蓝球变动 | 红球变动 |
---|---|---|---|
蓝蓝 | 蓝 | -1 | 0 |
红红 | 蓝 | 1 | -2 |
蓝红 | 红 | -1 | 0 |
蓝球只会奇数变动(+1或-1),红球只会偶数变动(0或-2),因此红球为偶数最后一个球为蓝球,红球为奇数最后一个球为红球。
2.3.6 Light switches 控制灯的开关
房间里有一盏灯,外面有四个开关,只有一个是控制灯的。你可以打开任意数量的开关,也可以打开开关任意次。你需要进房间多少次才能知道是哪个开关控制着灯?
There is a light bulb inside a room and four switches outside. All switches are currently at off state and only one switch controls the light bulb. You may turn any number of switches on or of any number of times you want. How many times do you need to go into the room to figure out which switch controls the light bulb?
答案:1次。
灯除了明灭信息,还有冷热信息,灯开了一段时间后会发热。通过2×2种状态对应四个开关。
打开开关1和2,一段时间后,关闭2,打开3,进房间查看灯。
- 灯亮且热,开关1控制
- 灯亮但冷,开关3控制
- 灯灭但热,开关2控制
- 灯灭且冷,开关4控制
2.3.7 Quant salary 量化工资
八位量化分析师聚在一起喝酒,他们都想知道行业平均工资,但都不想透露自己的工资。如何才能在每个人都不知道其他人工资的情况下计算行业平均工资吗?
Eight quants from different banks are getting together for drinks. They are all interested in knowing the average salary of the group. Nevertheless, being cautious and humble individuals, everyone prefers not to disclose his or her own salary to the group. Can you come up with a strategy for the quants to calculate the average salary without knowing other people’s salaries?
答案:第一个分析师设置一个随机数,写上自己的工资和随机数之和,传递给下一个分析师,依次加上自己的工资后还给第一个分析师。第一个分析师将总数减去随机数后取平均即为行业平均工资。(随机数和真实工资不能差距太大或太小,不然也可能会泄露大概的工资水平,以工资的3到10倍为佳)
2.4 Application of Symmetry 巧用对称性
2.4.1 Coin piles 硬币堆
假设你被蒙上了眼睛,地上有1000枚硬币,其中980个花面朝上的,20个字面朝上的。如何把硬币分成两堆字面朝上的硬币数量相等(总数不用相等)的硬币堆?(不能通过触摸判断硬币,但可以翻转任意枚硬币)
Suppose that you are blind-folded in a room and are told that there are 1000 coins on the floor. 980 of the coins have tails up and the other 20 coins have heads up. Can you separate the coins into two piles so to guarantee both piles have equal number of heads? Assume that you cannot tell a coin’s side by touching it, but you are allowed to turn over any number of coins.
答案:第一堆分20个,另一堆分980个,将第一堆的所有硬币都翻转过来。
- 第一步:初始分硬币。第一堆分了n个,其中m个字面朝上的;则另一堆分了1000-n个,其中20-m个字面朝上的
- 第二步:将第一堆的所以硬币都翻转过来,则第一堆变成其中n-m个字面朝上的
我们能控制n,为了使得n-m=20-m,n=20
2.4.2 Mislabeled bags 贴错标签的水果袋
三袋水果,一袋装着苹果,一袋装着橙子,一袋混合装着苹果和橙子,每个袋子上都贴有一个标签(苹果、橙子或混合),但老板说所有袋子的标签都贴错了。
如何通过取出最少的水果来更正袋子的标签?你可以从任何袋子里拿走任何数量的水果。
You are given three bags of fruits. One has apples in it; one has oranges in it; and one has a mix of apples and oranges in it. Each bag has a label on it (apple, orange or mix). Unfortunately, your manager tells you that ALL bags are mislabeled. Develop a strategy to identify the bags by taking out minimum number of fruits? You can take any number of fruits from any bags.
答案:从贴着混合标签的袋子里拿一个水果。
- 所有袋子的标签都贴错了,从贴着混合标签的袋子里拿一个即可确定贴着混合标签的袋子的结果。
- 贴着混合标签的袋子,只能装着苹果或橙子,如果拿出来是苹果,则混合标签对应苹果;如果拿出来是橙子,则混合标签对应橙子
- 贴着苹果标签的袋子,只能装着橙子或混合装着苹果和橙子
- 贴着橙子标签的袋子,只能装着苹果或混合装着苹果和橙子
- 标着苹果和橙子的袋子是对称的,可以通过贴着混合标签的袋子的结果判断贴着苹果/橙子标签的是什么。
- 如果混合标签对应苹果,那苹果标签只能对应橙子(对应混合的话,橙子标签就没贴错)
- 如果混合标签对应橙子,那橙子标签只能对应苹果(对应混合的话,苹果标签就没贴错)
2.4.3 Wise men 智者斗酋长
一位苏丹王抓了50位智者。
-
他有一个杯子,现在是正放的。
-
他每分钟都会随机召唤一位智者,智者可以选择把杯子翻过来,也可以什么都不做。
-
智者被随机召唤,可能会被召唤无数次。
-
当有人正确地和苏丹王说所有的智者都已经至少被召唤过一次时,所有人就都自由了;但如果他说错了的话,苏丹王就会处死所有人。
智者在被单独监禁在各自的房间里之前只能交流一次。设计一个让能让所有智者自由的策略。
A sultan has captured 50 wise men. He has a glass currently standing bottom down. Every minute he calls one of the wise men who can choose either to turn it over (set it upside down or bottom down) or to do nothing. The wise men will be called randomly, possibly for an infinite number of times. When someone called to the sultan correctly states that all wise men have already been called to the sultan at least once, everyone goes free. But if his statement is wrong, the sultan puts everyone to death. The wise men are allowed to communicate only once before they get imprisoned into separate rooms(one per room). Design a strategy that lets the wise men go free.
答案:
设置一个发言人,其他49个普通智者同质,发言人利用无限次随机召唤搜集信息。
- 普通智者要在第一次看到杯子未被标记的时候标记(把杯子翻过来),如果杯子已经被标记或自己已经标记过则不再标记(什么都不做)
- 发言人在得到标记信息后要归置回初始状态,计数到49后喊话
正放 | 反放 | |
---|---|---|
未标记过的普通智者 | 把杯子翻过来 | 什么都不做 |
已标记过的普通智者 | 什么都不做 | 什么都不做 |
发言人 | 什么都不做 | 把杯子翻过来,计数+1 |
2.5 Series Summation 数列求和
∑ n = 1 N n = N ( N + 1 ) 2 \sum^N_{n=1}n=\frac{N(N+1)}{2} n=1∑Nn=2N(N+1)
∑ n = 1 N n 2 = N 3 3 + N 2 2 + N 6 \sum^N_{n=1}n^2=\frac{N^3}{3}+\frac{N^2}{2}+\frac{N}{6} n=1∑Nn2=3N3+2N2+6N
平方和公式记不住可以设 ∑ n = 1 N n 2 = a N 3 + b N 2 + c N + d \sum^N_{n=1}n^2=aN^3+bN^2+cN+d ∑n&