fork(1) download
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. //#define D 10000000L
  7. #define D 5000L
  8. #define COUNT 10000000
  9. #define Pi 3.14159265358979323846
  10.  
  11.  
  12. int main() {
  13.  
  14. srand( time(0) );
  15. long i1,j1; //= rand() % D;
  16. long i2,j2; //= rand() % D;
  17. long ic,jc;
  18. //int j = rand() % D;
  19. long qq = 0;
  20. long qw = 0;
  21. double r,DD;
  22. // cout << D*D << " " << D*D*D << "\n";
  23. for (int k=0; k< COUNT; k++)
  24. {
  25. i1 = ((long)rand() % (2*D)) - D;
  26. j1 = ((long)rand() % (2*D)) - D;
  27. i2 = ((long)rand() % (2*D)) - D;
  28. j2 = ((long)rand() % (2*D)) - D;
  29. r = sqrt((i2-i1)*(i2-i1) + (j2-j1)*(j2-j1));
  30.  
  31. // cout << i << " " << j << " " << i*i + j*j << " " << D*D << "\n";
  32. if ((i1*i1 + j1*j1 <= D*D) && (i2*i2 + j2*j2 <= D*D) &&
  33. (r - D < 1) && ( D - r < 1 ) )
  34. {
  35. ic = (i1+i2)/2;
  36. jc = (j1+j2)/2;
  37.  
  38. DD = sqrt (ic*ic + jc*jc);
  39.  
  40. if (DD >= D/2) qw++;
  41.  
  42. // cout << "(" << i1 << "," << j1 << ")" <<"(" << i2 << "," << j2 << ")" << " " << D*D << "\n";
  43. // cout << r << " " << D << "\n";
  44. qq++;
  45. }
  46. }
  47. cout << qw << " " << qq << " " << (1-qw/(qq+0.001)) << "\n"; // your code goes here
  48. return 0;
  49. }
Success #stdin #stdout 0.48s 4528KB
stdin
Standard input is empty
stdout
713 1990 0.641709