fork download
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <ctime>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. double p;
  12. long long int n,t1,t2,t1w,t2w,count;
  13. srand (static_cast <unsigned> (time(0)));
  14.  
  15. scanf("%lld",&n);
  16. while(n--)
  17. {
  18. count = 0;
  19. scanf("%lld %lld %lld %lld",&t1,&t2,&t1w,&t2w);
  20. for(long long i=1;i<=100000;i++)
  21. {
  22. //start1= rand()%t1+1;
  23. float x1= static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(t1)));
  24. float x2= x1 + t1w;
  25. float y1= static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(t2)));
  26. float y2= x2 + t2w;
  27. //printf("%f %f %f %f\n",x1,x2,y1,y2);
  28. if(x1>x2)
  29. {
  30. float tmp = x1;
  31. x1 = x2;
  32. x2 = tmp;
  33. tmp = y1;
  34. y1 = y2;
  35. y2 = tmp;
  36. }
  37. if(x1<=y2 && y1<=x2)
  38. count+=1;
  39.  
  40. }
  41. p = double(count)/(100000);
  42. printf("%f\n",p);
  43. }
  44. return 0;
  45. }
Success #stdin #stdout 0.03s 3100KB
stdin
2
2 2 1 1
1 1 1 1
stdout
0.875470
1.000000