Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3.  
  4. int main() {
  5.   uint64_t in_count = 0;
  6.  
  7.   uint32_t N = 1000*100*2;
  8.   for (uint32_t i = 0 ; i < N ; i++) {
  9.     in_count += N-i-1;
  10.     const auto y = static_cast<double>(i)/N;
  11.     for (uint32_t j = N-i ; j < N ; j++) {
  12.       const auto x = static_cast<double>(j)/N;
  13.       if ((x*x + y*y) < 1) {
  14.     in_count ++;
  15.       }
  16.     }//std::cout << std::endl;
  17.   }
  18.  
  19.   std::cout << in_count << std::endl;
  20.   double four = 4;
  21.   std::cout << std::fixed; std::cout.precision(10);
  22.   std::cout << (four*in_count / N) << std::endl;
  23.  
  24.  
  25.   return 0;
  26. }
  27.  
  28.  
  29. #include <iostream>
  30. #include <random>
  31.  
  32. int main() {
  33.   uint64_t in_count = 0;
  34.  
  35.   uint32_t N = 1000*100*2;
  36.   for (uint32_t i = 0 ; i < N ; i++) {
  37.     //in_count += N-i-1;
  38.     const auto y = static_cast<double>(i)/N;
  39.     for (uint32_t j = N-i ; j < N ; j++) {
  40.       const auto x = static_cast<double>(j)/N;
  41.       if ((x*x + y*y) >= 1) {
  42.     in_count += j-1;
  43.     break;
  44.       }
  45.     }//std::cout << std::endl;
  46.   }
  47.  
  48.   std::cout << in_count << std::endl;
  49.   double four = 4;
  50.   std::cout << std::fixed; std::cout.precision(10);
  51.   std::cout << (four*in_count / N) << std::endl;
  52.  
  53.  
  54.   return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement