// Monte-Carlo, baby! !!!!!! DONE !!!!!!! // NOTE: changes for L = 2.0 in 3rd place!!! // error seems to be 1/n^(1/2) #include #include #include #include void main() { float L; ifstream in; in.open("mafia.in"); ofstream out; out.open("mafia.out"); while (1) { in >> L; if (L < 0.0) break; randomize(); long in = 0; for (long pts=1; pts <= 30000; pts++) { float x = (float) rand() / (float) RAND_MAX * L; float y = (float) rand() / (float) RAND_MAX * 1.0; if (y <= exp(-x*x)) in++; } out << L*(float) in / (float) (pts-1) << endl; } in.close(); out.close(); /****************** actual int. double x = 0.0; double area = 0.0; while (x < L) { area += 0.5*(exp(-x*x) + exp(-(x+0.02)*(x+0.02)) ) * 0.02; x+= 0.02; } cout << "Actual : " << area << endl; *****/ } Downloader failed! Response object 006~ASP 0159~Buffering Off~Buffering must be on.