Ankit_132

D

Jul 7th, 2023
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8. #define ff     first
  9. #define ss     second
  10. #define pb     push_back
  11. #define ppb    pop_back
  12.  
  13. int main()
  14. {
  15.     ios_base::sync_with_stdio(false);
  16.     cin.tie(NULL);
  17.     cout.tie(NULL);
  18.  
  19.     _test
  20.     {
  21.         int n;
  22.         double b, h;
  23.         cin>>n>>b>>h;
  24.  
  25.         vector<ll int> y(n);
  26.         for(auto &e: y)     cin>>e;
  27.  
  28.         double area = (b*h)/2;
  29.  
  30.         ll int prev = -1e9;
  31.         double ans = 0;
  32.  
  33.         for(auto e: y)
  34.         {
  35.             if(prev+h > e)
  36.             {
  37.                 ll int _h = prev+h - e;
  38.                 ll int _b = (_h*b)/h;
  39.                 ans -= (((_h*b))*_h);
  40.             }
  41.  
  42.             ans += area*h*2.0;
  43.             prev = e;
  44.         }
  45.  
  46.         ans /= 2;
  47.         ans /= h;
  48.  
  49.         cout<<fixed<<setprecision(10);
  50.         cout<<ans<<"\n";
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment