Advertisement
rudolf222222

Untitled

Nov 1st, 2022
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include <cmath>
  2. #include <iomanip>
  3. #include <iostream>
  4.  
  5. double* Production(const double* arr, double* product, int amount) {
  6.   double lower = static_cast<double>(1) / static_cast<double>(10000);
  7.   product[0] = pow(arr[0], lower);
  8.   for (int i = 1; i < amount; ++i) {
  9.     product[i] = product[i - 1] * pow(arr[i], lower);
  10.   }
  11.   return product;
  12. }
  13. void FindNoise() {
  14.   int num_of_plants = 0;
  15.   std::cin >> num_of_plants;
  16.   double* arr = new double[num_of_plants];
  17.   double* product = new double[num_of_plants];
  18.   for (int i = 0; i < num_of_plants; ++i) {
  19.     std::cin >> arr[i];
  20.   }
  21.   product = Production(arr, product, num_of_plants);
  22.   CountNoise(product, arr);
  23.   delete[] arr;
  24.   delete[] product;
  25. }
  26. void CountNoise(const double* product, const double* arr) {
  27.   int func_calls = 0, left = 0, right = 0;
  28.   double LowerFirstCase =
  29.       static_cast<double>(10000) / static_cast<double>(right - left + 1);
  30.   double LowerSecondCase =
  31.       static_cast<double>(10000) / static_cast<double>(right + 1);
  32.   std::cin >> func_calls;
  33.   for (int i = 0; i < func_calls; ++i) {
  34.     std::cin >> left;
  35.     std::cin >> right;
  36.     if (left != right && left != 0) {
  37.       std::cout << std::fixed << std::setprecision(10)
  38.                 << pow(product[right] / product[left - 1], LowerFirstCase)
  39.                 << "\n";
  40.     } else if (left == right) {
  41.       std::cout << std::fixed << std::setprecision(10) << arr[right] << "\n";
  42.     } else if (left == 0) {
  43.       std::cout << std::fixed << std::setprecision(10)
  44.                 << pow(product[right], LowerSecondCase) << "\n";
  45.     }
  46.   }
  47. }
  48. int main() {
  49.   FindNoise();
  50.   return 0;
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement