Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: 曹北健
- Result: AC Submission_id: 4269402
- Created at: Sat Apr 02 2022 19:34:52 GMT+0800 (China Standard Time)
- Problem_id: 5486 Time: 24 Memory: 2740
- */
- #include <stdio.h>
- #include <math.h>
- double f(double t){
- return exp(-((t + 0.5) * (t + 0.5)));
- }
- double calcrnd(int testcnt, double lbx, double ubx, double lby, double uby){
- int cnt = 0, i;
- double x, y;
- for(i = 1; i <= testcnt; i++){
- x = ((rand() % 32768) / 32768.0) * (ubx - lbx) + lbx;
- y = ((rand() % 32768) / 32768.0) * (uby - lby) + lby;
- if(y < f(x))cnt++;
- }
- return (double)cnt / (double)testcnt * (ubx - lbx) * (uby - lby);
- }
- int main(){
- double ub;
- scanf("%lf", &ub);
- printf("%.6f\n", exp(-calcrnd(114514, 0, ub, 0, 1)));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment