#include <cstdio>
#include <cmath>
#include <random>
using namespace std;
std::mt19937 rnd;
double rndf() {
return (rnd() - rnd.min() + 0.5) / (rnd.max() + 1.0 - rnd.min());
}
/* Box Muller transform */
double rnorm() {
double u1 = rndf(), u2 = rndf();
return sqrt(-2 * log(u1)) * cos(2 * M_PI * u2);
}
bool win(double v) {
int potions = 10;
bool ok = true;
for(int a=0; a<2000; a++) {
while(rndf() < 0.4) potions++;
double x = 2 * rnorm() + 4;
if(x < v && potions) { potions--; continue; }
double y = x + rnorm();
if(y < 0) return false;
}
return true;
}
int main() {
printf("cutoff;wins\n");
int ngames = 100;
for(double v=1; v<6; v+=0.1) {
int good = 0;
for(int a=0; a<ngames; a++) if(win(v)) good++;
printf("%6.2f;%f\n", v, good * 1. / ngames);
}
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8cmFuZG9tPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RkOjptdDE5OTM3IHJuZDsKCmRvdWJsZSBybmRmKCkgeyAKICByZXR1cm4gKHJuZCgpIC0gcm5kLm1pbigpICsgMC41KSAvIChybmQubWF4KCkgKyAxLjAgLSBybmQubWluKCkpOwogIH0KCi8qIEJveCBNdWxsZXIgdHJhbnNmb3JtICovCmRvdWJsZSBybm9ybSgpIHsKICBkb3VibGUgdTEgPSBybmRmKCksIHUyID0gcm5kZigpOwogIHJldHVybiBzcXJ0KC0yICogbG9nKHUxKSkgKiBjb3MoMiAqIE1fUEkgKiB1Mik7CiAgfQoKYm9vbCB3aW4oZG91YmxlIHYpIHsKICBpbnQgcG90aW9ucyA9IDEwOwogIGJvb2wgb2sgPSB0cnVlOyAKICBmb3IoaW50IGE9MDsgYTwyMDAwOyBhKyspIHsKICAgIHdoaWxlKHJuZGYoKSA8IDAuNCkgcG90aW9ucysrOwogICAgZG91YmxlIHggPSAyICogcm5vcm0oKSArIDQ7CiAgICBpZih4IDwgdiAmJiBwb3Rpb25z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