Пример #1
0
int main(int argc, const char * argv[])
{
    int choice;
    bool done = false;
    while(!done)
    {
        std::cout << "===== Técnicas de Diseño ===== " << std::endl;
        std::cout << "1) Problema del camionero" << std::endl;
        std::cout << "2) División en párrafos" << std::endl;
        std::cout << "3) Subsecuencia máxima" << std::endl;
        std::cout << "4) Parejas estables" << std::endl;
        std::cout << "5) Salir" << std::endl;
        std::cout << "Elige una opción: ";
        while(!(std::cin >> choice)){
            std::cin.clear();
            std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
            std::cout << "Entrada inválida, intenta otra vez: ";
        }
        switch(choice)
        {
            case 1:{
                camionero();
                break;}
            case 2:{
                parrafos();
                break;}
            case 3:{
                subsequences();
                break;}
            case 4:{
                parejas();
                break;}
            case 5:{
                std::cout << "Adios!" << std::endl;
                done = true;
                break;}
            default:
                std::cout << "Opción inválida, elige otra" << std::endl;
                break;
        }
    }
}
Пример #2
0
int main(int argc, const char * argv[])
{
//-------------------------------------CAMIONERO CON PRISA---------------------------------------------
    std::cout<<std::endl<<"CAMIONERO CON PRISA-------------------"<<std::endl;
    std::vector<int> ruta;
    
    int gasolineras[6] = {100, 250, 120, 200, 300, 95};
    
    for (int i = 0; i<6; i++)
    {
        ruta.push_back(gasolineras[i]);
    }
    
    
    std::vector<int> paradas = camionero(400, ruta);
    for (auto i : paradas)
        std::cout<<"Se hará una parada en la "<<i<<" gasolinera."<<std::endl;

//-------------------------------------DIVISION DE PARRAFOS------------------------------------------------------
    std::cout<<std::endl<<"DIVISION DE PARRAFOS-------------------"<<std::endl;
    divisionParrafos("Do I contradict myself? I am large, I contain multitudes.");
    
//-------------------------------------SUBSEQUENCIA COMUN MAXIMA---------------------------------------------
    std::cout<<std::endl<<"SUBSECUENCIA COMUN MAXIMA--------------"<<std::endl;
    std::vector<int> S;
    std::vector<int> P;
    int t[10] = {2,4,5,3,6,7,0,2,1,3};
    int t1[8] = {4,5,6,7,0,2,1,1};
    
    for (int i = 0; i<10; i++)
    {
        S.push_back(t[i]);
    }
    
    for (int i = 0; i<8; i++)
    {
        P.push_back(t1[i]);
    }
    
    subseqMax(S, P);
    
//-------------------------------------PAREJAS ESTABLES---------------------------------------------
    std::cout<<std::endl<<"PAREJAS ESTABLES-----------------------"<<std::endl;
    int M[N][N];
    int H[N][N];
    
//    int HzeroPref[N] = {2,1,0,3};
//    int HonePref[N] = {1,3,0,2};
//    int HtwoPref[N] = {2,0,3,1};
//    int HthreePref[N] = {0, 1, 2, 3};
//    
//    int MzeroPref[N] = {0,2,1,3};
//    int MonePref[N] = {2,3,1,0};
//    int MtwoPref[N] = {1,2,3,0};
//    int MthreePref[N] = {3,1,0,2};
    int MzeroPref[N] = {1,3,2,0};
    int MonePref[N] = {2,0,3,1};
    int MtwoPref[N] = {1,2,3,0};
    int MthreePref[N] = {0,1,3,2};
    
    int HzeroPref[N] = {0,1,2,3};
    int HonePref[N] = {2,1,0,3};
    int HtwoPref[N] = {0,2,1,3};
    int HthreePref[N] = {1,3,0,2};
    
    for (int i = 0; i<N; i++)
    {
        M[0][i] = MzeroPref[i];
        M[1][i] = MonePref[i];
        M[2][i] = MtwoPref[i];
        M[3][i] = MthreePref[i];
        
        H[0][i] = HzeroPref[i];
        H[1][i] = HonePref[i];
        H[2][i] = HtwoPref[i];
        H[3][i] = HthreePref[i];
    }
    
    parejasEstables(M, H);
    
    return 0;
}