wojiaocbj

random

Apr 6th, 2022
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. /*
  2.  Author: 曹北健(37509)
  3.  Result: AC Submission_id: 4279424
  4.  Created at: Wed Apr 06 2022 15:36:38 GMT+0800 (China Standard Time)
  5.  Problem: 5486  Time: 365   Memory: 2720
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13. #include <time.h>
  14. #pragma warning(disable:4996)
  15. int main(){
  16. #ifdef _DEBUG
  17.     FILE *fp = freopen("../../../input.txt", "r", stdin);
  18.     //FILE *fp2 = freopen("output.txt", "w", stdout);
  19. #endif // _DEBUG
  20.     srand(time(0));
  21.     double x, y;
  22.     double ub;
  23.     int i, n = 0;
  24.     scanf("%lf", &ub);
  25.     //rand();//[0,32767]
  26.     for(i = 0; i < 1919810; i++){
  27.         x = (double)(rand() % RAND_MAX) / (double)RAND_MAX * ub;//[0,ub]
  28.         y = (double)(rand() % RAND_MAX) / (double)RAND_MAX;
  29.         if(exp(-pow(x + 0.5, 2)) > y){
  30.             n++;
  31.         }
  32.     }
  33.     printf("%.6f\n", exp(-((n / 1919810.) * ub)));
  34.  
  35. #ifdef _DEBUG
  36.     freopen("CON", "r", stdin);
  37.     //freopen("CON", "w", stdout);
  38.     system("pause");
  39. #endif // _DEBUG
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment