GeeksforGeeks 智力题

博客中整理了学习GeeksforGeeks 站点的智力题。作为自己的学习历程。会在学习中不断的更新。

目录

Puzzle 1 | (How to Measure 45 minutes using two identical wires?)

Puzzle 2 | (Find ages of daughters)

Puzzle 3 | (Calculate total distance travelled by bee)

Puzzle 4 | (Pay an employee using a 7 units gold rod?)

Puzzle 5 | (Finding the poisoned wine)

Puzzle 6 | (Monty Hall problem)

Puzzle 7 | (3 Bulbs and 3 Switches)

Puzzle 8 | (Find the Jar with contaminated pills)

Puzzle 9 | (Find the fastest 3 horses)

Puzzle 10 | (A Man with Medical Condition and 2 Pills)

Puzzle 11 | (1000 Coins and 10 Bags)

Puzzle 12 | (Maximize probability of White Ball)

Puzzle 13 | (100 Prisoners with Red/Black Hats)

Puzzle 14 | (Strategy for a 2 Player Coin Game)

 Puzzle 15 | (Camel and Banana Puzzle)

Solution:

Puzzle 16 | (100 Doors)


Puzzle 1 | (How to Measure 45 minutes using two identical wires?)

How do we measure forty-five minutes using two identical wires, each of which takes an hour to burn. We have matchsticks with us. The wires burn non-uniformly. So, for example, the two halves of a wire might burn in 10 minute and 50 minutes respectively

Puzzle 2 | (Find ages of daughters)

Alok has three daughters. His friend Shyam wants to know the ages of his daughters. Alok gives him first hint.

1) The product of their ages is 72.

Shyam says this is not enough information Alok gives him a second hint.

2) The sum of their ages is equal to my house number.

Shyam goes out and look at the house number and tells “I still do not have enough information to determine the ages”.

Alok admits that Shyam can not guess and gives him the third hint

3) The oldest of the girls likes strawberry ice-cream.

Shyam is able to guess after the third hint. Can you guess what are the ages of three daughters?

Puzzle 3 | (Calculate total distance travelled by bee)

Two trains are on same track and they are coming toward each other. The speed of first train is 50 KMs/h and the speed of second train is 70 KMs/h. A bee starts flying between the trains when the distance between two trains is 100 KMs. The bee first flies from first train to second train. Once it reaches the second train, it immediately flies back to the second train … and so on until trains collide. Calculate the total distance traveled by the bee. Speed of bee is 80 KMs/h.

答案:

先求两辆火车从开始到停止的时间:50*t + 70*t = 100
这个时间也是蜜蜂的飞行时间,所以蜜蜂飞行的距离是:80*t.

Puzzle 4 | (Pay an employee using a 7 units gold rod?)

An employee works for an employer for 7 days. The employer has a gold rod of 7 units. How does the employer pays to the employee so that the employee gets 1 unit at the end of everyday. The employer can make at most 2 cuts in rod.

答案:

最多割两次,一次是【3,4】,第二次再割长度为3的,所以为【1,2,4】.

Puzzle 5 | (Finding the poisoned wine)

You have 240 barrels of wine, one of which has been poisoned. After drinking the poisoned wine, one dies exactly 24 hours. You have 5 slaves whom you are willing to sacrifice in order to determine which barrel contains the poisoned wine. How do you achieve this in 48 hours?

Puzzle 6 | (Monty Hall problem)

Suppose you’re on a game show, and you’re given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what’s behind the doors, opens another door, say No. 3, which has a goat. He then says to you, “Do you want to pick door No. 2?” Is it to your advantage to switch your choice?

220px-Monty_open_door.svg

答案:

分别将车放在3个门后,考虑情况即可。 

Puzzle 7 | (3 Bulbs and 3 Switches)

There is a room with a door (closed) and three light bulbs. Outside the room there are three switches, connected to the bulbs. You may manipulate the switches as you wish, but once you open the door you can’t change them. Identify each switch with its bulb.

答案:

先开一个灯,等十分钟后,关掉灯,再开另一个灯,然后进门,感受一下灯的温度就好了,烫的就是刚关的,亮的就是刚打开的,否则就是没有打开过的。

Puzzle 8 | (Find the Jar with contaminated pills)

You have 5 jars of pills. Each pill weighs 10 grams, except for contaminated pills contained in one jar, where each pill weighs 9 grams. Given a scale, how could you tell which jar had the contaminated pills in just one measurement?

答案:

第1罐取1片, 第2罐取2片, 第3罐取3片, 第4罐取4片, 第5罐取5片, 一共有15片药,进行称重。

如果重量为149,则被污染的药在第1罐。

如果重量为148,则被污染的药在第2罐。

如果重量为147,则被污染的药在第3罐。

如果重量为146,则被污染的药在第4罐。

如果重量为145,则被污染的药在第5罐。

Puzzle 9 | (Find the fastest 3 horses)

There are 25 horses among which you need to find out the fastest 3 horses. You can conduct race among at most 5 to find out their relative speed. At no point you can find out the actual speed of the horse in a race. Find out how many races are required to get the top 3 horses.

答案:7次,(不想用汉语解释了,哈哈哈哈,没时间了)

First, we group the horses into groups of 5 and race each group in the race course. This gives us 5 races (see image below).

horspuzzle1

In the image, each row represents one race of 5 horses. For convenience, let us name the horses using row and column index. Therefore, the first race(row 1) was contested between the horses R1C1, R1C2, R1C3, R1C4 and R1C5. The second race (row 2) was contested between the horses R2C1, R2C2 and so on. Let us assume that the fifth member of each row won the race (R1C5 won the first race, R2C5 won the second race and so on), the fourth member of each row came second (R1C4 came second in the first race, R2C4 came second in the second race and so on) and the third member of each group came third (R1C3 came third in the first race, R2C3 came third in the second race and so on).

horsepuzzle2

 

Next, we race the 5 level 1 winners (R1C5, R2C5, R3C5, R4C5 and R5C5). Let’s say R1C5 wins this race, R2C5 comes second and R3C5 comes third.

horspicture3

The winner of this race (R1C5) is the fastest horse of the entire group. Now, the horse which is second in the entire group can either be R2C5 or R1C4. The horse which is third in the entire group can either be R3C5, R2C4 or R1C3. Therefore, we race these 5 horses.

horspicture4

Therefore, the horse R1C5 is the fastest horse. The horses which come second and third in the last race are the horses which are second and third in the entire group respectively. in this way, the minimum number of races required to determine the first, second and third horses in the entire group is 7.

Puzzle 10 | (A Man with Medical Condition and 2 Pills)

A man has a medical condition that requires him to take two kinds of pills, call them A and B. The man must take exactly one A pill and exactly one B pill each day, or he will die. The pills are taken by first dissolving them in water.

The man has a jar of A pills and a jar of B pills. One day, as he is about to take his pills, he takes out one A pill from the A jar and puts it in a glass of water. Then he accidentally takes out two B pills from the B jar and puts them in the water. Now, he is in the situation of having a glass of water with three dissolved pills, one A pill and two B pills. Unfortunately, the pills are very expensive, so the thought of throwing out the water with the 3 pills and starting over is out of the question. How should the man proceed in order to get the right quantity of A and B while not wasting any pills?

 答案:

再搞一杯水,然后放一个A药片进去溶解,这样取溶解了一个A药片的一半的溶液和溶解了一个A药片和两个B药片的一半的溶液就可以了。两杯水都不会浪费了。

Puzzle 11 | (1000 Coins and 10 Bags)

A dealer has 1000 coins and 10 bags. He has to divide the coins over the ten bags, so that he can make any number of coins simply by handing over a few bags. How must divide his money into the ten bags?

答案:

考虑十进制数的二进制表示。任何一个1000以内的数,包括1000,都可以用十位二进制数表示:比如十进制(1000)== e二进制(1111101000)

所以10个包分别为:

(1): 1, 2的0次方

(2): 2, 2的1次方

(3): 4, 2的2次方

(4): 8, 2的3次方

(5): 16, 2的4次方

(6): 32, 2的5次方

(7): 64, 2的6次方

(8): 128, 2的7次方

(9): 256, 2的8次方

(10): 489,2的9次方为512 ,由于只有1000个硬币,所以最后一个放489个,刚好1000,如果放512,则超过1000了。

这样,1000(包含1000)以内的数都可以用上面10个数的其中一些数表示。比如17的二进制为:10001,则用第1个包和第5个包表示。

Puzzle 12 | (Maximize probability of White Ball)

There are two empty bowls in a room. You have 50 white balls and 50 black balls. After you place the balls in the bowls, a random ball will be picked from a random bowl. Distribute the balls (all of them) into the bowls to maximize the chance of picking a white ball.

答案:

设第一个碗中有球 y 个,其中白球有 x 个,则另一个碗有球 100-y 个,其中白球有 50-x 个。

则取白球概率为(1/2)(x/y + (50-x)(100-y)),则 x=y=1 或者 x=49,y=99

Puzzle 13 | (100 Prisoners with Red/Black Hats)

100 prisoners in jail are standing in a queue facing in one direction. Each prisoner is wearing a hat of color either black or red. A prisoner can see hats of all prisoners in front of him in the queue, but cannot see his hat and hats of prisoners standing behind him.
The jailer is going to ask color of each prisoner’s hat starting from the last prisoner in queue. If a prisoner tells the correct color, then is saved, otherwise executed. How many prisoners can be saved at most if they are allowed to discuss a strategy before the jailer starts asking colors of their hats.


Answer:
At-most 99 prisoners can be saved and the 100th prisoner has 50-50 chances of being executed.
The idea is that every prisoner counts number of red hats in front of him.

100th prisoner says red if the number of red hats is even. He may or may not be saved, but he coneys enough information to save 99th prisoner.

The 99’th prisoner decides his answer on the basis of answer of 100’th prisoner’s answer. There are following possibilities and 99’th prisoner can figure out color of his hat in every case.

If 100’th prisoner said ‘Red’ (There must have been even number of red hats in front of him)
a) If 99’th prisoner sees even number of red hats in front of him, then his color is black.
b) If 99’th prisoner sees odd number of red hats in front of him, then his color is red.

If 100’th prisoner said ‘Black’ (There must have been odd number of red hats in front of him)
a) If 99’th prisoner sees even number of red hats in front of him, then his color is Red.
b) If 99’th prisoner sees odd number of red hats in front of him, then his color is Black.

The 98’th prisoner decides his answer on the basis of answer of 99’th prisoner’s answer and uses same logic.

Similarly other prisoners from 97 to 1 are saved.

Puzzle 14 | (Strategy for a 2 Player Coin Game)

Consider a two player coin game where each player gets turn one by one. There is a row of even number of coins, and a player on his/her turn can pick a coin from any of the two corners of the row. The player that collects coins with more value wins the game. Develop a strategy for the player making the first turn, such he/she never looses the game.

Note that the strategy to pick maximum of two corners may not work. In the following example, first player looses the game when he/she uses strategy to pick maximum of two corners.

Example
  18 20 15 30 10 14
First Player picks 18, now row of coins is
  20 15 30 10 14
Second player picks 20, now row of coins is
  15 30 10 14
First Player picks 15, now row of coins is
  30 10 14
Second player picks 30, now row of coins is
  10 14
First Player picks 14, now row of coins is
  10 
Second player picks 10, game over.

The total value collected by second player is more (20 + 
30 + 10) compared to first player (18 + 15 + 14).
So the second player wins. 

答案:

先计算偶数位上的硬币的数值,以及计算奇数位上的硬币的数量。比如奇数位上的数值和最大。那么第一个人只要拿奇数位上的硬币,或者让第二个人拿不到奇数位上的硬币就可以了。

 Puzzle 15 | (Camel and Banana Puzzle)

A person has 3000 bananas and a camel. The person wants to transport maximum number of bananas to a destination which is 1000 KMs away, using only the camel as a mode of transportation. The camel cannot carry more than 1000 bananas at a time and eats a banana every km it travels. What is the maximum number of bananas that can be transferred to the destination using only camel (no other mode of transportation is allowed).

Solution:

First of all, the brute-force approach does not work. if Camel start by picking up the 1000 bananas and try to reach point B, then Camel will eat up all the 1000 bananas on the way and there will be no banana left for the Camel to return to point A.

So we have to take an approach that Camel drop the bananas in between and then return to point A, to pick bananas again.

Since there are 3000 bananas and camel can only carry 1000 bananas, Camel will have to make 3 trips to carry them all to any point in between.

When bananas are reduced to 2000 then Camel can shift them to another point in 2 trips and when the number of bananas left are

In the first part, P1, to shift the bananas by 1Km Camel will have to

1. Move forward with 1000 bananas – Will eat up 1 banana in the way forward 
2. Leave 998 banana after 1 km and return with 1 banana – will eat up 1 banana in the way back
3. Pick up the next 1000 bananas and move forward – Will eat up 1 banana in the way forward 
4. Leave 998 banana after 1 km and return with 1 banana - will eat up 1 banana in the way back
5. Will carry the last 1000 bananas from point a and move forward – will eat up 1 banana

Note: After point 5 the camel does not need to return to point A again.

So to shift 3000 bananas by 1km Camel will eat up 5 bananas.

After moving to 200 km the camel would have eaten up 1000 bananas and is now left with 2000 bananas.

Hence, the length of part P1 is 200 Km.

Now in the Part P2, the Camel need to do the following to shift the Bananas by 1km.

1. Move forward with 1000 bananas - Will eat up 1 banana in the way forward
2. Leave 998 banana after 1 km and return with 1 banana - will eat up this 1 banana in the way back
3. Pick up the next 1000 bananas and move forward - Will eat up 1 banana in the way forward

Note: After point 3 the camel does not need to return to the starting point of P2.

So to shift 2000 bananas by 1km Camel will eat up 3 bananas.

After moving to 333 km the camel would have eaten up 1000 bananas and is now left with the last 1000 bananas.

The camel will actually be able to cover 333.33 km, 
I have ignored the decimal part because it will not make a difference in this example.

Hence the length of part P2 is 333 Km.

Now, for the last part, P3, the Camel only has to move forward. He has already covered 533 (200+333) out of 1000 km in Parts P1 & P2. Now he has to cover only 466 km and he has 1000 bananas.

He will eat up 466 bananas on the way forward, and at point B the Camel will be left with only 533 Bananas.

Puzzle 16 | (100 Doors)

There are 100 doors in a row, all doors are initially closed. A person walks through all doors multiple times and toggle (if open then close, if close then open) them in following way:

In first walk, the person toggles every door

In second walk, the person toggles every second door, i.e., 2nd, 4th, 6th, 8th, …

In third walk, the person toggles every third door, i.e. 3rd, 6th, 9th, …

………
……….

In 100th walk, the person toggles 100th door.

Which doors are open in the end?

答案:

A door is toggled in ith walk if i divides door number. For example the door number 45 is toggled in 1st, 3rd, 5th, 9th and 15th walk.
The door is switched back to initial stage for every pair of divisors. For example 45 is toggled 6 times for 3 pairs (5, 9), (15, 3) and (1, 45).
It looks like all doors would become closes at the end. But there are door numbers which would become open, for example 16, the pair (4, 4) means only one walk. Similarly all other perfect squares like 4, 9, ….

So the answer is 1, 4, 9, 16, 25, 36, 49, 64, 81 and 100.

就是看一个数能够被哪些数整除,算一下因子的个数就好了。

猜你喜欢

转载自blog.csdn.net/wchzh2015/article/details/89328694