daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Mar 25th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int magicFives(int *arr, int p, int r) {
  6.     if ((r-p+1) <= 5) {
  7.         return arr[p + (r-p)/2];
  8.     }
  9.  
  10.     int liczba_median = ((r-p+1)+4)/5;
  11.     int *medians = new int[liczba_median];
  12.     for (int i = 0; i < liczba_median; i++) {
  13.         int begin = p + i*5;
  14.         int size = min(5, r-begin+1);
  15.         sort(arr+begin, arr+begin+size);
  16.         medians[i] = arr[begin+(size-1)/2];
  17.     }
  18.    
  19.     int res = magicFives(medians, 0, liczba_median-1);
  20.     delete[] medians;
  21.     return res;
  22. }
  23.  
  24. int select(int *arr, int p, int r, int i) {}
  25.  
  26. int main() {
  27.     int n;
  28.     cin >> n;
  29.     int *arr = new int[n];
  30.     for (int i = 0; i < n; i++)
  31.         cin >> arr[i];
  32.    
  33.     int res = magicFives(arr, 0, n-1);
  34.     cout << "Wynik = " << res << endl;
  35.     delete[] arr;
  36.     return 0;
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top