Compare commits

..

13 Commits

Author SHA1 Message Date
abraham 3a34aa916b information pc test 2026-10-21 12:34:23 +02:00
abraham 3acfa79dcd EXO 4 - optimisation F5 2026-10-21 12:07:28 +02:00
abraham 22d249dd5e information sup 2026-10-21 11:51:47 +02:00
abraham 7c09526d0a fonction 10 : O(L) 2026-10-21 11:49:58 +02:00
abraham b40a1c2081 fonction 8 : O(S x k) 2026-10-21 11:44:36 +02:00
abraham dc5f6dbbd9 EXO 4 - optimisation F3 2026-10-21 11:39:59 +02:00
abraham 1b9c2aace2 prepare le merge 2026-10-21 11:36:11 +02:00
abraham 1ada0848f4 merge 2026-10-21 11:27:32 +02:00
abraham a5882012df fusion 2026-10-21 11:27:00 +02:00
Ozvann Abraham 310c57d1ff Merge pull request 'EXO 4 - optimisation F1' (#1) from framery/2026_TD3_DEV51_Qualite_Algo:main into main
Reviewed-on: abraham/2026_TD3_DEV51_Qualite_Algo#1
2026-10-21 11:25:48 +02:00
Ozvann Abraham 97155f2688 Merge branch 'main' into main 2026-10-21 11:24:55 +02:00
abraham 1e3ac9d8d2 fonction 4 : O(n + J) 2026-10-21 11:19:08 +02:00
abraham df4e8876fb fonction 2 : O(n + C) 2026-10-21 11:10:03 +02:00
3 changed files with 87 additions and 37 deletions
+27 -5
View File
@@ -2,11 +2,13 @@
- Karl FRAMERY
- Ozvann ABRAHAM
CPU: Intel(R) Pentium(R) Silver N5030 (4) @ 3.10 GHz
# 1.Mesurer
```gcc -O2 banque.c -o banque && time ./banque```
```
gcc -O2 banque.c -o banque && time ./banque
```
```
Empreinte : ff68d260a7a58441
@@ -16,7 +18,7 @@ user 0m4,772s
sys 0m0,005s
```
Le temps d'éxecution du programme est de 4.793 seconde et l'emprunte est <ff68d260a7a58441>
Le temps d'éxecution du programme est de 4.793 seconde et l'emprunte est : [ff68d260a7a58441]
# 2.Profiler
@@ -80,7 +82,27 @@ La complexité de la fonction est de <span style="color:blue">[O(n)]</span> pour
# 4. Optimisation
- Optimisation de la fonction 1 nom du commit : "EXO 4 - optimisation F1". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 2 nom du commit : "fonction 2 : O(n + C)". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 3 nom du commit : "EXO 4 - optimisation F3". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 4 nom du commit : "fonction 4 : O(n + J)". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 5 nom du commit : "EXO 4 - optimisation F5". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 6 nom du commit : "". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 7 nom du commit : "". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 8 nom du commit : "fonction 8 : O(S x k)". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 9 nom du commit : "". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 10 nom du commit : "fonction 10 : O(L)". Emprunte : ff68d260a7a58441
Le temps minimal atteint avec les modification est de 1.651 secondes.
BIN
View File
Binary file not shown.
+60 -32
View File
@@ -88,29 +88,28 @@ void trier_par_montant(Transaction *t, int n)
/* F2 : nombre de clients ayant au moins une transaction */
int nb_clients_distincts(const Transaction *t, int n)
{
int clients_vus[NB_CLIENTS] = {0};
int nb = 0;
for (int i = 0; i < n; i++) {
int deja_vu = 0;
for (int j = 0; j < i; j++) {
if (t[j].client == t[i].client) {
deja_vu = 1;
break;
}
}
if (!deja_vu)
int client = t[i].client;
if (!clients_vus[client]) {
clients_vus[client] = 1;
nb++;
}
}
return nb;
}
/* F3 : solde total de chaque client */
/* F3 : solde total de chaque client en O(n + c) */
void total_par_client(const Transaction *t, int n, long *totaux)
{
for (int c = 0; c < NB_CLIENTS; c++) {
totaux[c] = 0;
for (int i = 0; i < n; i++)
if (t[i].client == c)
totaux[c] += t[i].montant;
}
for (int i = 0; i < n; i++) {
totaux[t[i].client] += t[i].montant;
}
}
@@ -119,10 +118,10 @@ void total_par_jour(const Transaction *t, int n, long *totaux)
{
for (int j = 0; j < NB_JOURS; j++) {
totaux[j] = 0;
for (int i = 0; i < n; i++)
if (t[i].jour == j)
totaux[j] += t[i].montant;
}
for (int i = 0; i < n; i++)
totaux[t[i].jour] += t[i].montant;
}
/* F5 : période de jours consécutifs dont la somme des soldes est maximale */
@@ -131,16 +130,20 @@ long meilleure_periode(const long *totaux, int nb_jours, int *debut, int *fin)
long meilleur = totaux[0];
*debut = 0;
*fin = 0;
for (int i = 0; i < nb_jours; i++) {
for (int j = i; j < nb_jours; j++) {
long somme = 0;
for (int k = i; k <= j; k++)
somme += totaux[k];
if (somme > meilleur) {
meilleur = somme;
*debut = i;
*fin = j;
}
long somme_courante = totaux[0];
int debut_courant = 0;
for (int j = 1; j < nb_jours; j++) {
if (somme_courante < 0) {
somme_courante = totaux[j];
debut_courant = j;
} else {
somme_courante += totaux[j];
}
if (somme_courante > meilleur) {
meilleur = somme_courante;
*debut = debut_courant;
*fin = j;
}
}
return meilleur;
@@ -172,12 +175,31 @@ static const int PIECES[] = {1, 2, 5, 10, 20, 50, 100, 200};
long nb_facons_rendre(int somme, int nb_pieces)
{
if (somme < 0 || nb_pieces < 0)
return 0;
if (somme == 0)
return 1;
if (somme < 0 || nb_pieces == 0)
if (nb_pieces == 0)
return 0;
return nb_facons_rendre(somme - PIECES[nb_pieces - 1], nb_pieces) +
nb_facons_rendre(somme, nb_pieces - 1);
if (nb_pieces > NB_PIECES)
nb_pieces = NB_PIECES;
long *combinaisons = malloc((somme + 1) * sizeof(long));
if (combinaisons == NULL)
return 0;
for (int montant = 0; montant <= somme; montant++)
combinaisons[montant] = 0;
combinaisons[0] = 1;
for (int i = 0; i < nb_pieces; i++) {
for (int montant = PIECES[i]; montant <= somme; montant++)
combinaisons[montant] += combinaisons[montant - PIECES[i]];
}
long resultat = combinaisons[somme];
free(combinaisons);
return resultat;
}
/* F9 : catégorie d'une transaction (pour les statistiques) */
@@ -217,10 +239,16 @@ int categorie(const Transaction *t)
/* F10 : ajoute une ligne à la fin du rapport */
int longueur(const char *s)
{
int n = 0;
while (s[n] != '\0')
n++;
return n;
static const char *chaine_connue = NULL;
static int n_connu = 0;
if (s != chaine_connue || s[0] == '\0') {
chaine_connue = s;
n_connu = 0;
}
while (s[n_connu] != '\0')
n_connu++;
return n_connu;
}
void ajouter_ligne(char *rapport, const char *ligne)