Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void mergeSort(int *floors, int length);
- void joinParts(int *floors, int *array1, int *array2, int length1, length2);
- int main() {
- int testCases, availableFloors;
- cin >> testCases;
- for (int i = 0; i < testCases; i++) {
- cin >> availableFloors;
- int *floors = new int[availableFloors];
- for (int j = 0; j < availableFloors; j++)
- cin >> floors[i];
- int numberBlueOnes = 0;
- for (int j = 0; j < numberBlueOnes; j++) {
- if (floors[j] > 0)
- numberBlueOnes++;
- }
- int numberRedOnes = availableFloors - numberBlueOnes;
- int *blueOnes = new int[numberBlueOnes];
- int *redOnes = new int[numberRedOnes];
- int auxs[2] = { 0, 0 };
- for (int j = 0; j < availableFloors; j++) {
- if (floors[j] > 0) {
- blueOnes[auxs[0]++] = floors[j];
- } else {
- redOnes[auxs[1]++] = floors[j] * -1;
- }
- }
- delete [] floors;
- int *ordered = new int[availableFloors];
- if (blueOnes[0] > redOnes[0]) {
- ordered[0] = blueOnes[0];
- auxs[0] = 1;
- auxs[1] = 0;
- } else {
- ordered[0] = redOnes[0];
- auxs[0] = 0;
- auxs[1] = 1;
- }
- while (auxs[0] < numberBlueOnes && auxs[1] < numberRedOnes) {
- }
- }
- return 0;
- }
- void mergeSort(int *floors, int length) {
- if (length > 1) {
- int length1 = length / 2;
- int length2 = (length1 * 2) == length ? length1 : length1 + 1;
- int *array1 = new int[length1];
- int *array2 = new int[length2];
- for (int i = 0; i < length1; i++)
- array1[i] = floors[i];
- for (int i = length1; i < length; i++)
- array2[i - length1] = floors[i];
- mergeSort(array1, length1);
- mergeSort(array2, length2);
- joinParts(floors, array1, array2, length1, length2);
- }
- }
- void joinParts(int *floors, int *array1, int *array2, int length1, int length2) {
- int length = length1 + length2;
- int auxs[3] = { 0, 0, 0 };
- while (auxs[0] < length1 && auxs[1] < length2) {
- if (array1[auxs[0] > array2[auxs[1]]) {
- floors[auxs[2]] = array1[auxs[0]++];
- } else {
- floors[auxs[2]] = array1[auxs[1]++];
- }
- auxs[2]++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement