█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 5401

Problema 0xde - Ordenar un arreglo grande

  • Autor: slash
  • Fecha: 2021-12-15 05:11:18 UTC (Hace más de 2 años)
Caso # Resultado Tiempo Memoria
#1
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#2
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#3
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#4
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#5
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#6
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#7
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#8
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#9
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#10
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#11
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#12
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#13
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#14
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#15
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#16
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#17
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#18
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#19
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#20
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#21
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#22
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#23
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#24
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#25
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#26
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
#27
Error de compilación
                      /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    
Puntos totales: 0 / 100

Código

//
// Created by danie on 12/11/2021.
//

#include "iostream"
#include "random"

using namespace std;



void swap(int &a, int &b){
//    a = b + a;
//    b = a - b;
//    a = a - b;
    int temp = b;
    b = a;
    a = temp;
}

int partition(vector<int> &cards, int from, int to){
    int x = cards[to];
    int i = from;
    for (int j = from; j < to; j++){
        if (cards[j] <= x){
            swap(cards[i], cards[j]);
            i++;
        }
    }
    swap(cards[i], cards[to]);
    return i;
}

void quicksort(vector<int> &cards, int from, int to){
    if (to > from){
        int part = partition(cards, from, to);
        quicksort(cards,from, part  -1);
        quicksort(cards, part + 1, to);
    }
}

int randomized_partition(vector<int> &cards, int from, int to){
    int k = rand();
    int i = (rand() % (to - from)) + from;
    swap(cards[to], cards[i]);
    return partition(cards,from,to);
}

int randomized_select(vector<int> &cards, int from, int to, int ith){ // este es el bueno
    if(to == from) return cards[from];
    int ordered_item = randomized_partition(cards, from, to);
    int distance = ordered_item - from;
    if (ith == ordered_item) return cards[ordered_item];
    if (ith < ordered_item) return randomized_select(cards, from, ordered_item - 1, ith);
    return randomized_select(cards, ordered_item + 1, to, ith);
}

//int randomized_select(vector<int> &cards, int from, int to, int ith){
//    if(to == from) return cards[from];
//    int ordered_item = randomized_partition(cards, from, to);
//    int elements_on_left_array = (ordered_item - from) ;
//    if (ith == elements_on_left_array) return cards[ordered_item];
//    if (ith < ordered_item) return randomized_select(cards, from, ordered_item - 1, ith);
//    return randomized_select(cards, ordered_item + 1, to, ith - elements_on_left_array);
//}

void randomized_quicksort(vector<int> &cards,int from,int to){
    if (to > from){
        int part = randomized_partition(cards, from, to);
        randomized_quicksort(cards,from, part - 1);
        randomized_quicksort(cards, part + 1, to);
    }
}

//void tests(){
//    vector<int> cards = {8,7,5,7,3,5,1,0}; // 0 1 3 5 5 7 7 8 sorted
//    vector<int> cpcopy_cards = cards;
//    vector<int> copy_cards = cards;
////    quicksort(cpcopy_cards, 0, cpcopy_cards.size() - 1);
////    for(int card:cpcopy_cards)cout<<card<<' ';
////    cout<<'\n';
////    randomized_quicksort(cards,0,cards.size() - 1);
////    for(int card:cards)cout<<card<<' ';
////    cout<<'\n';
////    for(int card:copy_cards)cout<<card<<' ';
//    cout<<'\n'<<randomized_select(copy_cards,0,cards.size() - 1, 7)<<'\n';
//    for(int card:copy_cards)cout<<card<<' ';
//
//
//}

void tests(){
    int n; cin>>n;
    vector<int> numbers;
    for(int i = 0; i < n; i++) {
        int in; cin>>in;
        numbers.push_back(in);
    }
    quicksort(numbers,0,n - 1);
    for (int num: numbers) cout<<num<<' ';
}