DuongNhi99

COALESCE

Dec 16th, 2020 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 1e5 + 5;
  5.  
  6. int n;
  7. int a[N];
  8.  
  9. void solve() {
  10.     if(n == 1) {
  11.         cout << a[1];
  12.         return;
  13.     }
  14.  
  15.     double ans = (double)(a[1] + a[2]) / 2.000000;
  16.     for(int i = 3; i <= n; ++i) {
  17.         ans = ((double)a[i] + ans) / 2.000000;
  18.     }
  19.  
  20.     cout << fixed << setprecision(6) << ans << '\n';
  21. }
  22.  
  23. int main() {
  24. #ifdef DN
  25.     freopen("in.txt", "r", stdin);
  26. #endif
  27.     freopen("COALESCE.inp", "r", stdin);
  28.     freopen("COALESCE.out", "w", stdout);
  29.     ios_base::sync_with_stdio(false);
  30.     cin.tie(NULL); cout.tie(NULL);
  31.  
  32.     cin >> n;
  33.     for(int i = 1; i <= n; ++i)
  34.         cin >> a[i];
  35.     sort(a + 1, a + n + 1);
  36.  
  37.     solve();
  38.  
  39.     return 0;
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment