sfondo
Prendi in considerazione un torneo round robin, in cui ogni concorrente gioca una partita contro ogni altro concorrente. Non ci sono pareggi, quindi ogni partita ha un vincitore e un perdente. Un concorrente A è un re del torneo, se per ogni altro concorrente B , sia A sfiora B , o A sfiora altro concorrente C che a sua volta battuta B . Si può dimostrare che ogni torneo ha almeno un re (anche se possono essercene diversi). In questa sfida, il tuo compito è trovare i re di un determinato torneo.
Ingresso e uscita
Il tuo contributo è una N × N
matrice booleana T
e, facoltativamente, il numero N ≥ 2
di concorrenti. Ogni voce T[i][j]
rappresenta il risultato del gioco tra concorrenti i
e j
, con valore 1 che rappresenta una vittoria per i
e 0 una vittoria per j
. Si noti che T[i][j] == 1-T[j][i]
se i != j
. La diagonale di è T
composta da 0 secondi.
Il tuo risultato sarà l'elenco dei re del torneo che T
rappresenta, usando l'indicizzazione basata su 0 o 1. L'ordine dei re è irrilevante, ma non dovrebbero esserci duplicati.
Sia l'input che l'output possono essere presi in qualsiasi formato ragionevole.
Regole e punteggio
È possibile scrivere un programma completo o una funzione. Vince il conteggio di byte più basso e non sono consentite scappatoie standard .
Casi test
Questi casi di test utilizzano l'indicizzazione basata su 0. Per l'indicizzazione basata su 1, incrementare ciascun valore di output.
2 [[0,0],[1,0]] -> [1]
3 [[0,1,0],[0,0,0],[1,1,0]] -> [2]
3 [[0,1,0],[0,0,1],[1,0,0]] -> [0,1,2]
4 [[0,1,1,1],[0,0,1,0],[0,0,0,0],[0,1,1,0]] -> [0]
4 [[0,1,1,0],[0,0,1,0],[0,0,0,1],[1,1,0,0]] -> [0,2,3]
5 [[0,1,0,0,1],[0,0,0,0,1],[1,1,0,0,0],[1,1,1,0,1],[0,0,1,0,0]] -> [3]
5 [[0,1,0,1,0],[0,0,1,1,1],[1,0,0,0,0],[0,0,1,0,1],[1,0,1,0,0]] -> [0,1,4]
5 [[0,0,0,0,0],[1,0,1,1,0],[1,0,0,0,1],[1,0,1,0,1],[1,1,0,0,0]] -> [1,3,4]
6 [[0,0,0,0,0,0],[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