Ping Pong 20/100

Ciao a tutti, stavo cercando di risolvere Ping Pong ma non riesco a prendere piu’ di 20.
Questo e’ il codice:

#include <bits/stdc++.h>
using namespace std;

void IO(){
    ios::sync_with_stdio(0); cin.tie(0);
}


int T, a, b, partite;

bool nonValido(){
    if(a < 33) return 1;
    
    //massimo punti b
    if(b > 30 + (partite - 3) * 11){
        return 1;
    }
    
    //minimo punti b
    if(b < (partite - 3) * 11) return 1;
    


    if(a > 53) return 1;
    
    return 0;

}

int main(){
    IO();

    cin >> T;
    
    for(int t = 0; t < T; ++t){
        cin >> a >> b;
        partite = ceil(a / 11.f);

        if(nonValido()){
            cout << "-1 -1\n\n";
            continue;
        }
        int perse = partite - 3;

        if(perse == 2){
            int r1 = 0, r2 = 0;
            if((a - 33) % 2 == 0){
                r1 = (a - 33) / 2;
                r2 = r1;
            }
            else{
                r1 = (a - 33) / 2 + 1;
                r2 = r1 - 1;
            }

            cout << r1 << " " << 11 << '\n';
            cout << r2 << " " << 11 << '\n';
        }
        else if(perse == 1){
            cout << a - 33 << " " << 11 << '\n';
        }

        b = b - (partite - 3) * 11;
        int r1 = 0, r2 = 0, r3 = 0;

        if(b <= 10) {
            r1 = b;
        }
        else if(b <= 20){
            r1 = b - 10;
            r2 = b - r1;
        }
        else if(b <= 30){
            r1 = 10;
            r2 = 10;
            r3 = b - 20;
        }
        cout << 11 << " " << r1 << "\n";
        cout << 11 << " " << r2 << "\n";
        cout << 11 << " " << r3 << "\n\n";


    }


    

    return 0;
}

prova a semplificare questa operazione, se sai che le partite perse sono 2 allora fai quello che hai fatto qua sotto:

Se può essere d’aiuto, il codice sopra sbaglia questi 2 casi d’input:
2
33 49
44 27

1 Mi Piace

Ciao e grazie a tutti per l’aiuto, ho modificato il codice ma prendo sempre 20/100.
Questo e’ il nuovo codice:

#include <bits/stdc++.h>
using namespace std;

void IO(){
    ios::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}


int T, a, b, partite, moreset, r1, r2, r3;

bool nonValido(){
    if(partite > 5) return 1;
    //minimo b
    if(b < moreset * 11) 
        return 1;
    //massimo b
    if(b > 30 + moreset * 11) 
        return 1;
    

    return (a < 33 ||  a > 53);
}

int main(){
    IO();

    cin >> T;
    
    for(int t = 0; t < T; ++t){
        cin >> a >> b;
        partite = max(ceil(a / 11.f) + (a == 44), ceil(b / 11.f) + (b == 44));
        moreset = partite - 3;

        if(nonValido()){
            cout << "-1 -1\n";
            continue;
        }

        a -= 33;
        b -= moreset * 11;
        
        if(moreset == 2){
            r1 = r2 = 0;
            if(a <= 10) 
                r1 = a;
            else{
                r1 = a - 10;
                r2 = 10;
            }
            cout << r1 << ' ' << 11 << '\n';
            cout << r2 << ' ' << 11 << '\n';
        }
        else if(moreset == 1){
            cout << a << ' ' << 11 << '\n';
        }
        
        r1 = r2 = r3 = 0;

        if(b <= 10) {
            r1 = b;
        }
        else if(b <= 20){
            r1 = b - 10;
            r2 = b - r1;
        }
        else{
            r1 = 10;
            r2 = 10;
            r3 = b - 20;
        }
        
        cout << 11 << ' ' << r1 << '\n';
        cout << 11 << ' ' << r2 << '\n';
        cout << 11 << ' ' << r3 << '\n';

    }


    

    return 0;
}

Considera i punteggi min e max che ogni giocatore può totalizzare:
in 3 sets: A[33,33] - B[0,30];
in 4 sets: A[33,43] - B[11,41];
in 5 sets: A[33,53] - B[22,52];
diversamente non c’è soluzione.

2 Mi Piace