Please ignore secret bonuses. Secret tests do NOT award bonus. Max hw grade is 30+2 bonus efficiency

Do you need help?

how to order the rectangles?

B
Benez (560 points)
0 3 7
in HW6 required by (560 points)

----ITA----

Salve a tutti, volevo chiedere se qualcuno è riuscito a svolgere l'ordinamento dei rettangoli, per ora ho fatto delle prove ma non riesco a passare 3 test.
Per eseguire questa operazione, creo un dizionario con dentro come chiave il colore, e come valori la lista di colori che intersecano quest'ultimo(la chiave).

Ho pensato di comporre una lista partendo dalla chiave che ha un valore vuoto, ovvero quello più in alto, per poi inserire altri colori (quindi le chiavi )solamente se i valori ad essi associati (quindi il valore) contengono tutti i colori già caricati nella lista.

ripeto: l'algoritmo funziona ma fallisce 3 test, che controllo mi manca o mi sfugge? è corretto dire che ogni rettangolo a un suo livello e non possono esserci 2 rettangoli allo stesso livello?

----ENG----

Hi everyone, I wanted to ask if anyone has managed to carry out the sorting of the rectangles, for now I have done some tests but I can not pass 3 tests.
To do this, I create a dictionary with the color as key, and as values the list of colors that intersect the latter (the key).

I decided to compose a list starting from the key that has an empty value, that is the highest value, and then insert other colors (therefore the keys) only if the values associated with them (therefore the value) contain all the colors already loaded in the list.

I repeat: the algorithm works but fails 3 tests, which control am I missing or escaping me? Is it correct to say that each rectangle has its own level and there cannot be 2 rectangles at the same level?

272 views

2 Answers

Francesco.Danese (2140 points)
0 1 10
by (2.1k points)
Potresti spiegare meglio come ordini i rettangoli? Non è molto chiaro potrebbe essere lì l'errore
B
Benez (560 points)
0 3 7
by (560 points)
Procedo cosi:
Ho un dizionario con chiave un colore(quindi un rettangolo) e come valori, ho delle liste di colori che intersecano le chiave..ad esempio, se prendiamo l'esempio con 5 rettangoli, il dizionario avrà:
dizionario=
{

giallo=[]

rosso=[giallo,azzuro,blu,verde]

...

}

Il mio ragionamento è il seguente:

Prendo il rettangolo che non ha sovrapposizioni e lo posiziono all'interno di una lista_finale.

Dopo di che, prendo (in un ciclo) un rettangolo/colore(chiave) fra quelli del dizionario, e controllo se fra la lista che ho associato, ci sia il colore che ho precedentemente inserito nella lista_finale e che non abbia più elementi di len(lista_finale).

se è presente, e non ci sono altri colori, allora aggiungo il rettangolo/colore(chiave) alla lista_finale.

come già detto, è un ciclo, quindi ricomincia a cercare un rettangolo/colore(chiave) che abbia nella lista associata ALMENO un colore di quelli nella lista_finale, ma che non ne abbia di non presenti in lista_finale.

So che non sono stato chiaro, ma mi è molto complicato spiegarlo senza usare codice e commenti...
se hai modo di spiegarmi un alternativa, sai lieto di confrontarla e magari capire se posso correggere il mio.
andrea.sterbini (207920 points)
750 1267 2373
by (208k points)
Please use English in this forum
b
benjamin (2490 points)
1 7 21
by (2.5k points)
Also keep in mind a rectangle can and will in a lot of tests intersecate more than one other rectangle. Not only that but two rectangles intersecate in either 0, 2 or 4 points.