Careercup | Chapter 6

6.2 There is an 8x8 chess board in which two diagonally opposite corners have been cut off. You are given 31 dominos, and a single domino can cover exactly two squares. Can you use the 31 dominos to cover the entire board? Prove your answer (byproviding an example or showing why it's impossible).

很巧妙的反证。

6.3 You have a five-quart jug, a three-quart jug, and an unlimited supply of water (but no measuring cups). How would you come up with exactly four quarts of water? Note that the jugs are oddly shaped, such that filling up exactly "half" of the jug would be impossible.

得到1:装满3---从3倒进5---装满3---从3倒进5,此时3的瓶子里装的就是1.

得到2:装满5---从5倒进3,此时5的瓶子里装的就是2;

得到3:装满3;

得到4:装满5--从5倒进3--倒空3--从5倒进3(3里面有2)---装满5---从5再倒进3(倒进了1),现在5的瓶子里装的就是4;

得到5:装满5;

得到6:得到1之后再装满5就行;

得到7,得到2之后再装满5;

得到8, 装满3和5;

6.4 A bunch of people are living on an island, when a visitor comes with a strange order: all blue-eyed people must leave the island as soon as possible. There will be a flight out at 8:00pm every evening. Each person can see everyone else's eye color, but they do not know their own (nor is anyone allowed to tell them). Additionally, they do not know how many people have blue eyes, a/though they do know that at least one person does. How many days will it take the blue-eyed people to leave?

没想到。应该从最基础的case开始。

6.6 There are 100 closed lockers in a hallway. A man begins by opening all 100 lockers. Next, he closes every second locker. Then, on his third pass, he toggles every third locker (closes it if it is open or opens it if it is closed). This process continues for / 00 passes, such that on each pass i, the man toggles every ith locker. After his 100th pass in the hallway, in which he toggles only locker #100, how many lockers are open?

都是好题。

微软面试题(考思维)

1. 有两个房间,一间房里有三盏灯,另一间房有控制着三盏灯的三个开关, 这两个房间是分割开的,从一间里不能看到另一间的情况。 现在要求受训者分别进这两房间一次,然后判断出这三盏灯分别是由哪个开关控制的。 有什么办法呢?

进入开关房, 打开a灯,约5分钟后关掉,打开b灯;马上进入灯房,亮着的灯为b灯,灯泡有点热的是a灯,另一个就是c灯;

关键是利用到灯泡发热。

2. 你让一些人为你工作了七天,你要用一根金条作为报酬。金条被分成七小块,每天给出一块。 如果你只能将金条切割两次,你怎样分给这些工人?

1+2+4

3. 假设你有一个用1001个整数组成的数组,这些整数是任意排列的,但是你知道所有的整数都在1到1000(包括1000)之间。此外,除一个数字出现两次外,其他所有数字只出现一次。假设你只能对这个数组做一次处理,用一种算法找出重复的那个数字。如果你在运算中使用了辅助的存储方式,那么你能找到不用这种方式的算法吗?

可以用求和+减法,也可以用xor。

原文地址:https://www.cnblogs.com/linyx/p/3800116.html