Basic Algorithm----Monks on the Island

There is this question:

从前,有个小岛上只住着和尚。有些和尚的眼睛是红色的,而另一些的则是褐色。红色眼睛的和尚受到诅咒,如果得知自己的眼睛是红色的,那么当晚12点必须自行了断。(因为受到诅咒,所以只要得知自己的眼睛是红色的,则必须选择自杀,无一例外。)”

和尚们之间有一条不成文的规定,彼此不能提起对方眼睛的颜色。小岛上没有一面镜子,也没有可以反射自己容貌的物体。因此,没有任何人能够得知自己眼睛的颜色。出于这些原因,每个和尚都过着幸福的日子,也没有一个和尚自杀。


有一天,岛上突然来了一位游客,她对这个秘密并不知情。于是,这位游客对和尚们说:

“你们当中,至少有一位的眼睛是红色的。”

这位无心的游客当天就离岛而去,而和尚们却因第一次听到有关眼睛颜色的话题而惴惴不安。当晚,小岛上开始出现了可怕的事情,究竟是什么事呢?

Think for a few seconds.

In fact, this question is not an algorithm question, but a computer thinking examination question.

More often, it is to examine whether a programmer can think from multiple perspectives when he obtains a requirement, and at the same time dig out whether there are hidden requirements behind the requirements given by the product manager that he did not think of or express, and at the same time can fully Orientation considers whether there are bugs in the design of this system.

untie

  1. We can assume that if none of the monks have red eyes, the result will be scary, because all monks see other monks as normal, so they suspect that only themselves are red, so maybe all monks committed suicide at night.

  2. If there is a red-eyed monk, he should be the one who died. The reason is the same as the first one. After the first red-eyed monk dies, the next day will be peaceful.

  3. If there are two monks with red eyes, because all monks see at least one monk with red eyes, they will not commit suicide, but the next night, all monks may think that the reason why monks with red eyes did not commit suicide is themselves It is another red-eyed monk. It is possible that all the monks committed suicide the next night. It is also possible that all the monks knew at least one red-eyed monk, but they would not commit suicide.

  4. . . . Other results are similar to the derivation, but we will not hardcode the conditional judgment through the if/else method, and we need to extract a corresponding configuration platform service.

Therefore, this question is not an algorithm question, but a computer thinking question. It examines that we can use the computer perspective to help the product requirements to be more perfect.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325474505&siteId=291194637