Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: 曹北健(37509)
- Result: AC Submission_id: 4279424
- Created at: Wed Apr 06 2022 15:36:38 GMT+0800 (China Standard Time)
- Problem: 5486 Time: 365 Memory: 2720
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <string.h>
- #include <ctype.h>
- #include <time.h>
- #pragma warning(disable:4996)
- int main(){
- #ifdef _DEBUG
- FILE *fp = freopen("../../../input.txt", "r", stdin);
- //FILE *fp2 = freopen("output.txt", "w", stdout);
- #endif // _DEBUG
- srand(time(0));
- double x, y;
- double ub;
- int i, n = 0;
- scanf("%lf", &ub);
- //rand();//[0,32767]
- for(i = 0; i < 1919810; i++){
- x = (double)(rand() % RAND_MAX) / (double)RAND_MAX * ub;//[0,ub]
- y = (double)(rand() % RAND_MAX) / (double)RAND_MAX;
- if(exp(-pow(x + 0.5, 2)) > y){
- n++;
- }
- }
- printf("%.6f\n", exp(-((n / 1919810.) * ub)));
- #ifdef _DEBUG
- freopen("CON", "r", stdin);
- //freopen("CON", "w", stdout);
- system("pause");
- #endif // _DEBUG
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment