Corrige Nsi 2022
Corrige Nsi 2022
Corrige Nsi 2022
I-1. I-3.
i
.......................................................................... k
...........................................................................
score( j, coups[ b[0] ])
..........................................................................
proba( 3 - j , a[ba] )
...........................................................................
ba = k
[i] ...........................................................................
..........................................................................
p
...........................................................................
b.append(i)
.......................................................................... i
...........................................................................
alea( len(b) )
.......................................................................... b
...........................................................................
I-2. Etats possibles
Etat 0 Etat 1 Etat 2 pour Léa
probas de gagner
0,6 0,05 0,3 0,4 0,05 0,3 pour l'adversaire
I-4. def proba_rec(j, etat, nb):
a = etats_suiv(3-j, etat) etat
...........................................................................
if nb <= 1 or len(a) == 0 :
return proba(j,
else:
)
i
...........................................................................
nb - 1
p = 0.0
for i in range(0, len(a)) : ...........................................................................
pa = proba_rec(3-j, a[ ], )
if pa > p : p = pa
...........................................................................
return 1-p
...........................................................................
def emma(j, coups):
(b, p) = (0, 0.0) i
...........................................................................
for i in range(0, len(coups)) :
pc = proba_rec(j, coups[ ], 3)
if pc > p :
( i , pc )
...........................................................................
b
(b, p) =
return ...........................................................................
1/2
'F1' ,'G4'
II-1. [_____ 'F2' ,_____
_____ ,_____ 'G7' ,'F3' 'G2' ,_____
_____ ,_____ 'G3','G6' 'G1' ,_____
_____ ,_____ 'G8' ,_____]
'G5'
'F2' ,'F3'
II-2. [_____ 'G5' ,_____
_____ ,_____ 'G1' ,'F4' 'G7' ,_____
_____ ,_____ 'F1' ,'G3' 'G2' ,_____
_____ ,_____ 'G4 ,_____]
'G6'
etu[0]
II-3. def fille(etu):
return == 'F' .....................................................................
i
II-4. def suivante(etus, i):
if i >= len(etus) or fille(etus[i]): .....................................................................
return
return suivante(etus, ) i+1
.....................................................................
II-5. def forcer_parite(etus):
etus = etus.copy()
(classt, nbf) = ([], 0)
etus[0]
.....................................................................
idxf = suivante(etus, 0)
while etus:
if fille( ):
0
.....................................................................
classt.append(etus.pop(0))
nbf = nbf + 1 len( classt ) + 1
0.5 * ( ....................................................... )
idxf = suivante(etus, )
len( etus )
elif nbf < and idxf < :
classt.append(etus.pop( )) .....................................................................
nbf = nbf + 1
idxf = suivante(etus,
else:
)
idxf
.....................................................................
classt.append(etus.pop(0))
idxf = idxf - 1
return classt
idxf
.....................................................................
II-6. affectation[ i ]
..................................................................... i , etu
...............................................................................
etu
..................................................................... 0
...............................................................................
classts[ sport ]
..................................................................... elimine
...............................................................................
II-8. def mariages_stables(prefs, classts, quotas):
prefs = prefs.copy()
affectation = { sport: [] for sport in classts.keys() }
for in :
affectation_etudiant( , , , , quotas)
return affectation
xxx
........................................................................ affectation
.................................................................................
prefs
........................................................................ prefs
.................................................................................
xxx
........................................................................ classts
.................................................................................
2/2