/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.concurrent.ThreadLocalRandom;
class Ideone {
public static void main
(String[] args
) { int ok = 0;
int target = 1100; //цель
for(int k = 0; k < 100; k++) {
int balance = 1000; //текущий баланс
int i = 0;
int reward = 1; // начальная ставка
while (balance > 0 && balance <= target && reward <= balance) {
i++;
int rnd = randomRange(1, 99);
if (rnd >= 51) {
balance -= reward;
reward *= 2;
} else if (rnd <= 49) {
balance += reward;
reward = 1;
}
}
if(balance >= target) {
ok++;
}
}
System.
out.
print("chance: " + ok
); }
public static int randomRange(int min, int max) {
return ThreadLocalRandom.current().nextInt(min, max + 1);
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CmltcG9ydCBqYXZhLnV0aWwuY29uY3VycmVudC5UaHJlYWRMb2NhbFJhbmRvbTsKCmNsYXNzIElkZW9uZSB7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgaW50IG9rID0gMDsKICAgICAgICBpbnQgdGFyZ2V0ID0gMTEwMDsgLy/RhtC10LvRjAogICAgICAgIAogICAgICAgIGZvcihpbnQgayA9IDA7IGsgPCAxMDA7IGsrKykgewogICAgICAgICAgICBpbnQgYmFsYW5jZSA9IDEwMDA7IC8v0YLQtdC60YPRidC40Lkg0LHQsNC70LDQvdGBCiAgICAgICAgICAgIGludCBpID0gMDsKICAgICAgICAgICAgaW50IHJld2FyZCA9IDE7IC8vINC90LDRh9Cw0LvRjNC90LDRjyDRgdGC0LDQstC60LAKICAgICAgICAgICAgd2hpbGUgKGJhbGFuY2UgPiAwICYmIGJhbGFuY2UgPD0gdGFyZ2V0ICYmIHJld2FyZCA8PSBiYWxhbmNlKSB7CiAgICAgICAgICAgICAgICBpKys7CiAgICAgICAgICAgICAgICBpbnQgcm5kID0gcmFuZG9tUmFuZ2UoMSwgOTkpOwogICAgICAgICAgICAgICAgaWYgKHJuZCA+PSA1MSkgewogICAgICAgICAgICAgICAgICAgIGJhbGFuY2UgLT0gcmV3YXJkOwogICAgICAgICAgICAgICAgICAgIHJld2FyZCAqPSAyOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChybmQgPD0gNDkpIHsKICAgICAgICAgICAgICAgICAgICBiYWxhbmNlICs9IHJld2FyZDsKICAgICAgICAgICAgICAgICAgICByZXdhcmQgPSAxOwogICAgICAgICAgICAgICAgfQogCiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYoYmFsYW5jZSA+PSB0YXJnZXQpIHsKICAgICAgICAgICAgICAgIG9rKys7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgU3lzdGVtLm91dC5wcmludCgiY2hhbmNlOiAiICsgb2spOwogICAgfQogICAgICAgCiAgICBwdWJsaWMgc3RhdGljIGludCByYW5kb21SYW5nZShpbnQgbWluLCBpbnQgbWF4KSB7CiAgICAgICAgcmV0dXJuIFRocmVhZExvY2FsUmFuZG9tLmN1cnJlbnQoKS5uZXh0SW50KG1pbiwgbWF4ICsgMSk7CiAgICB9Cn0=