+70
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
import java.util.Random;
public class A {
public static void main(String args[]) {
int minimalSuccessTime = Integer.MAX_VALUE;
int maximalSuccessTime = Integer.MIN_VALUE;
for(int i = 0; i < 10000; i++) {
Random rnd = new Random();
boolean state = rnd.nextBoolean();
final byte prisonersCount = 100;
boolean prisoners[] = new boolean[prisonersCount];
byte prisonersCounted = 1;
int daysPassed = 0;
while(true) {
daysPassed++;
int tmp = rnd.nextInt(prisonersCount);
if(tmp == 0) {
if(state) {
state = false;
prisonersCounted++;
if(prisonersCounted == prisonersCount) {
break;
}
}
} else {
if(!state && !prisoners[tmp]) {
state = true;
prisoners[tmp] = true;
}
}
}
if(daysPassed < minimalSuccessTime) {
minimalSuccessTime = daysPassed;
}
if(daysPassed > maximalSuccessTime) {
maximalSuccessTime = daysPassed;
}
}
System.out.println("Minimal success time ~= " + minimalSuccessTime/365 + " years!");
System.out.println("Maximal success time ~= " + maximalSuccessTime/365 + " years!");
}
}
One hundred prisoners have been newly ushered into prison. The warden tells
them that starting tomorrow, each of them will be placed in an isolated cell,
unable to communicate amongst each other. Each day, the warden will choose
one of the prisoners uniformly at random with replacement, and place him in
a central interrogation room containing only a light bulb with a toggle switch.
The prisoner will be able to observe the current state of the light bulb. If he
wishes, he can toggle the light bulb. He also has the option of announcing that
he believes all prisoners have visited the interrogation room at some point in
time. If this announcement is true, then all prisoners are set free, but if it is
false, all prisoners are executed.
The warden leaves, and the prisoners huddle together to discuss their fate.
Can they agree on a protocol that will guarantee their freedom?
Запостил: guest2011,
14 Июня 2011
Lure Of Chaos 14.06.2011 21:45 # +4
guest2011 14.06.2011 22:11 # 0
bugmenot 14.06.2011 23:08 # +2
guest 15.06.2011 09:29 # +1
wvxvw 15.06.2011 09:43 # −1
roman-kashitsyn 15.06.2011 10:32 # 0
bugmenot 15.06.2011 19:37 # 0
> статистичиский
wvxvw 15.06.2011 14:00 # 0
EDIT: Вернее, не правильно, выразился, Автор думает, что условие: if (anyInt > int.MAX_VALUE) когда-нибудь выполнится :)
wvxvw 15.06.2011 14:11 # 0
Lure Of Chaos 15.06.2011 16:13 # 0
gegMOPO4 15.06.2011 19:21 # 0
Вот попробуйте поменять знак у MIN_VALUE.
guest8 09.04.2019 10:57 # −999
111111 24.08.2021 20:56 # 0