Advertisement
las4

Building

Mar 20th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.44 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void mergeSort(int *floors, int length);
  6. void joinParts(int *floors, int *array1, int *array2, int length1, length2);
  7.  
  8. int main() {
  9.     int testCases, availableFloors;
  10.     cin >> testCases;
  11.  
  12.     for (int i = 0; i < testCases; i++) {
  13.         cin >> availableFloors;
  14.  
  15.         int *floors = new int[availableFloors];
  16.         for (int j = 0; j < availableFloors; j++)
  17.             cin >> floors[i];
  18.  
  19.         int numberBlueOnes = 0;
  20.         for (int j = 0; j < numberBlueOnes; j++) {
  21.             if (floors[j] > 0)
  22.                 numberBlueOnes++;
  23.         }
  24.  
  25.         int numberRedOnes = availableFloors - numberBlueOnes;
  26.         int *blueOnes = new int[numberBlueOnes];
  27.         int *redOnes = new int[numberRedOnes];
  28.  
  29.         int auxs[2] = { 0, 0 };
  30.         for (int j = 0; j < availableFloors; j++) {
  31.             if (floors[j] > 0) {
  32.                 blueOnes[auxs[0]++] = floors[j];
  33.             } else {
  34.                 redOnes[auxs[1]++] = floors[j] * -1;
  35.             }
  36.         }
  37.  
  38.         delete [] floors;
  39.         int *ordered = new int[availableFloors];
  40.  
  41.         if (blueOnes[0] > redOnes[0]) {
  42.             ordered[0] = blueOnes[0];
  43.             auxs[0] = 1;
  44.             auxs[1] = 0;
  45.         } else {
  46.             ordered[0] = redOnes[0];
  47.             auxs[0] = 0;
  48.             auxs[1] = 1;
  49.         }
  50.  
  51.         while (auxs[0] < numberBlueOnes && auxs[1] < numberRedOnes) {
  52.  
  53.         }
  54.     }
  55.  
  56.     return 0;
  57. }
  58.  
  59. void mergeSort(int *floors, int length) {
  60.     if (length > 1) {
  61.         int length1 = length / 2;
  62.         int length2 = (length1 * 2) == length ? length1 : length1 + 1;
  63.  
  64.         int *array1 = new int[length1];
  65.         int *array2 = new int[length2];
  66.  
  67.         for (int i = 0; i < length1; i++)
  68.             array1[i] = floors[i];
  69.  
  70.         for (int i = length1; i < length; i++)
  71.             array2[i - length1] = floors[i];
  72.  
  73.         mergeSort(array1, length1);
  74.         mergeSort(array2, length2);
  75.         joinParts(floors, array1, array2, length1, length2);
  76.     }
  77. }
  78.  
  79. void joinParts(int *floors, int *array1, int *array2, int length1, int length2) {
  80.     int length = length1 + length2;
  81.  
  82.     int auxs[3] = { 0, 0, 0 };
  83.     while (auxs[0] < length1 && auxs[1] < length2) {
  84.         if (array1[auxs[0] > array2[auxs[1]]) {
  85.             floors[auxs[2]] = array1[auxs[0]++];
  86.         } else {
  87.             floors[auxs[2]] = array1[auxs[1]++];
  88.         }
  89.  
  90.         auxs[2]++;
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement