2025-01-28 12:52:19 +01:00
|
|
|
# Examen 2025
|
|
|
|
|
|
|
|
---
|
|
|
|
_**201.1 Algorithmes et Structures de données**_
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
Voici mes réponses pour l'examen 2025 d'_Algorithmes et Structures de données_ ainsi que les tests unitaires fournis.
|
|
|
|
|
|
|
|
## Exercice 1
|
|
|
|
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<td><strong>But</strong></td>
|
2025-01-28 17:28:24 +01:00
|
|
|
<td>Compter le nombre de valeurs positives différentes ayant leur opposé dans une liste</td>
|
2025-01-28 12:52:19 +01:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Input</strong></td>
|
2025-01-28 17:28:24 +01:00
|
|
|
<td>La liste des demi-touches (entiers relatifs non-nuls)</td>
|
2025-01-28 12:52:19 +01:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Output</strong></td>
|
2025-01-28 17:28:24 +01:00
|
|
|
<td>Le nombre de touches distinctes dont les valeurs positives et négatives sont dans la liste</td>
|
2025-01-28 12:52:19 +01:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Signature</strong></td>
|
|
|
|
<td>
|
|
|
|
|
|
|
|
```python
|
2025-01-28 17:28:24 +01:00
|
|
|
def countKey(
|
|
|
|
pieces: list[int]
|
|
|
|
) -> int:
|
2025-01-28 12:52:19 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
2025-01-28 14:32:19 +01:00
|
|
|
[Source](https://git.kb28.ch/HEL/AlgoDS-Examen2025/src/branch/main/src/Ex1.py)
|
2025-01-28 12:52:19 +01:00
|
|
|
/
|
|
|
|
[Tests](https://git.kb28.ch/HEL/AlgoDS-Examen2025/src/branch/main/tests/test_ex1.py)
|
|
|
|
|
|
|
|
|
|
|
|
## Exercice 2
|
|
|
|
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<td><strong>But</strong></td>
|
2025-01-28 17:28:24 +01:00
|
|
|
<td>Trouver le chemin le plus court entre deux points, en considérant que certaines routes ne sont praticables que de nuit/jour</td>
|
2025-01-28 12:52:19 +01:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Input</strong></td>
|
2025-01-28 17:28:24 +01:00
|
|
|
<td>Nœud de départ (index), nœud d'arrivée (index) et liste des routes / arêtes (nœud 1, nœud 2, restriction)</td>
|
2025-01-28 12:52:19 +01:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Output</strong></td>
|
2025-01-28 17:28:24 +01:00
|
|
|
<td>Liste des nœuds (index) à parcourir</td>
|
2025-01-28 12:52:19 +01:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Signature</strong></td>
|
|
|
|
<td>
|
|
|
|
|
|
|
|
```python
|
2025-01-28 17:28:24 +01:00
|
|
|
def findSafestPath(
|
|
|
|
start: int,
|
|
|
|
end: int,
|
|
|
|
intersections: list[tuple[int, int, int]]
|
|
|
|
) -> list[int]:
|
2025-01-28 12:52:19 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
2025-01-28 14:32:19 +01:00
|
|
|
[Source](https://git.kb28.ch/HEL/AlgoDS-Examen2025/src/branch/main/src/Ex2.py)
|
2025-01-28 12:52:19 +01:00
|
|
|
/
|
|
|
|
[Tests](https://git.kb28.ch/HEL/AlgoDS-Examen2025/src/branch/main/tests/test_ex2.py)
|
|
|
|
|
|
|
|
|
|
|
|
## Exercice 3
|
|
|
|
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<td><strong>But</strong></td>
|
2025-01-28 17:28:24 +01:00
|
|
|
<td>Trouver dans un réseau de console un sous-graphe connexe de taille donnée</td>
|
2025-01-28 12:52:19 +01:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Input</strong></td>
|
2025-01-28 17:28:24 +01:00
|
|
|
<td>Taille n du sous-graphe recherché, liste des connexions</td>
|
2025-01-28 12:52:19 +01:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Output</strong></td>
|
2025-01-28 17:28:24 +01:00
|
|
|
<td>Liste de n consoles toutes interconnectées</td>
|
2025-01-28 12:52:19 +01:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Signature</strong></td>
|
|
|
|
<td>
|
|
|
|
|
|
|
|
```python
|
2025-01-28 17:28:24 +01:00
|
|
|
def findTightlyLinkedConsoles(
|
|
|
|
n: int,
|
|
|
|
consoles: list[tuple[int, int]]
|
|
|
|
) -> list[int]:
|
2025-01-28 12:52:19 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
2025-01-28 14:32:19 +01:00
|
|
|
[Source](https://git.kb28.ch/HEL/AlgoDS-Examen2025/src/branch/main/src/Ex3.py)
|
2025-01-28 12:52:19 +01:00
|
|
|
/
|
|
|
|
[Tests](https://git.kb28.ch/HEL/AlgoDS-Examen2025/src/branch/main/tests/test_ex3.py)
|
|
|
|
|
|
|
|
|
|
|
|
## Exercice 4
|
|
|
|
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<td><strong>But</strong></td>
|
2025-01-28 17:28:24 +01:00
|
|
|
<td>Compter le nombre de séquences de N coups infligeant un total de H dégâts</td>
|
2025-01-28 12:52:19 +01:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Input</strong></td>
|
2025-01-28 17:28:24 +01:00
|
|
|
<td>Nombre N de coups dans la séquence, nombre C de coups possibles (dégâts 1 à C inclus), total H de dégâts</td>
|
2025-01-28 12:52:19 +01:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Output</strong></td>
|
2025-01-28 17:28:24 +01:00
|
|
|
<td>Nombre de séquences possibles</td>
|
2025-01-28 12:52:19 +01:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Signature</strong></td>
|
|
|
|
<td>
|
|
|
|
|
|
|
|
```python
|
2025-01-28 17:28:24 +01:00
|
|
|
def computeNbrOfDifferentSequences(
|
|
|
|
N: int,
|
|
|
|
C: int,
|
|
|
|
H: int
|
|
|
|
) -> int:
|
2025-01-28 12:52:19 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
2025-01-28 14:32:19 +01:00
|
|
|
[Source](https://git.kb28.ch/HEL/AlgoDS-Examen2025/src/branch/main/src/Ex4.py)
|
2025-01-28 12:52:19 +01:00
|
|
|
/
|
|
|
|
[Tests](https://git.kb28.ch/HEL/AlgoDS-Examen2025/src/branch/main/tests/test_ex4.py)
|
|
|
|
|
|
|
|
|
|
|
|
## Exercice 5
|
|
|
|
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<td><strong>But</strong></td>
|
2025-01-28 17:28:24 +01:00
|
|
|
<td>Trouver les placements de pièces Minitris formant un rectangle plein</td>
|
2025-01-28 12:52:19 +01:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Input</strong></td>
|
2025-01-28 17:28:24 +01:00
|
|
|
<td>Largeur de la grille, longueur de la grille, liste des pièces à poser</td>
|
2025-01-28 12:52:19 +01:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Output</strong></td>
|
2025-01-28 17:28:24 +01:00
|
|
|
<td>Liste des positions des pièces</td>
|
2025-01-28 12:52:19 +01:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Signature</strong></td>
|
|
|
|
<td>
|
|
|
|
|
|
|
|
```python
|
2025-01-28 17:28:24 +01:00
|
|
|
def playMinitrisFastAndWell(
|
|
|
|
board_width: int,
|
|
|
|
board_height: int,
|
|
|
|
pieces: list[tuple[tuple[int,int], tuple[int,int]]]
|
|
|
|
) -> list[list[int, int]]:
|
2025-01-28 12:52:19 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
2025-01-28 14:32:19 +01:00
|
|
|
[Source](https://git.kb28.ch/HEL/AlgoDS-Examen2025/src/branch/main/src/Ex5.py)
|
2025-01-28 12:52:19 +01:00
|
|
|
/
|
|
|
|
[Tests](https://git.kb28.ch/HEL/AlgoDS-Examen2025/src/branch/main/tests/test_ex5.py)
|