forked from menault/2026_TD3_DEV51_Qualite_Algo
Compare commits
6 Commits
1b9c2aace2
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a34aa916b | |||
| 3acfa79dcd | |||
| 22d249dd5e | |||
| 7c09526d0a | |||
| b40a1c2081 | |||
| dc5f6dbbd9 |
+5
-5
@@ -2,7 +2,7 @@
|
|||||||
- Karl FRAMERY
|
- Karl FRAMERY
|
||||||
- Ozvann ABRAHAM
|
- Ozvann ABRAHAM
|
||||||
|
|
||||||
|
CPU: Intel(R) Pentium(R) Silver N5030 (4) @ 3.10 GHz
|
||||||
|
|
||||||
# 1.Mesurer
|
# 1.Mesurer
|
||||||
|
|
||||||
@@ -92,17 +92,17 @@ La complexité de la fonction est de <span style="color:blue">[O(n)]</span> pour
|
|||||||
|
|
||||||
- Optimisation de la fonction 4 nom du commit : "fonction 4 : O(n + J)". 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 : "". 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 6 nom du commit : "". Emprunte : ff68d260a7a58441
|
||||||
|
|
||||||
- Optimisation de la fonction 7 nom du commit : "". Emprunte : ff68d260a7a58441
|
- Optimisation de la fonction 7 nom du commit : "". Emprunte : ff68d260a7a58441
|
||||||
|
|
||||||
- Optimisation de la fonction 8 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 9 nom du commit : "". Emprunte : ff68d260a7a58441
|
||||||
|
|
||||||
- Optimisation de la fonction 10 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.
|
||||||
|
|||||||
@@ -102,14 +102,14 @@ int nb_clients_distincts(const Transaction *t, int n)
|
|||||||
return 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)
|
void total_par_client(const Transaction *t, int n, long *totaux)
|
||||||
{
|
{
|
||||||
for (int c = 0; c < NB_CLIENTS; c++) {
|
for (int c = 0; c < NB_CLIENTS; c++) {
|
||||||
totaux[c] = 0;
|
totaux[c] = 0;
|
||||||
for (int i = 0; i < n; i++)
|
}
|
||||||
if (t[i].client == c)
|
for (int i = 0; i < n; i++) {
|
||||||
totaux[c] += t[i].montant;
|
totaux[t[i].client] += t[i].montant;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,16 +130,20 @@ long meilleure_periode(const long *totaux, int nb_jours, int *debut, int *fin)
|
|||||||
long meilleur = totaux[0];
|
long meilleur = totaux[0];
|
||||||
*debut = 0;
|
*debut = 0;
|
||||||
*fin = 0;
|
*fin = 0;
|
||||||
for (int i = 0; i < nb_jours; i++) {
|
long somme_courante = totaux[0];
|
||||||
for (int j = i; j < nb_jours; j++) {
|
int debut_courant = 0;
|
||||||
long somme = 0;
|
|
||||||
for (int k = i; k <= j; k++)
|
for (int j = 1; j < nb_jours; j++) {
|
||||||
somme += totaux[k];
|
if (somme_courante < 0) {
|
||||||
if (somme > meilleur) {
|
somme_courante = totaux[j];
|
||||||
meilleur = somme;
|
debut_courant = j;
|
||||||
*debut = i;
|
} else {
|
||||||
*fin = j;
|
somme_courante += totaux[j];
|
||||||
}
|
}
|
||||||
|
if (somme_courante > meilleur) {
|
||||||
|
meilleur = somme_courante;
|
||||||
|
*debut = debut_courant;
|
||||||
|
*fin = j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return meilleur;
|
return meilleur;
|
||||||
@@ -171,12 +175,31 @@ static const int PIECES[] = {1, 2, 5, 10, 20, 50, 100, 200};
|
|||||||
|
|
||||||
long nb_facons_rendre(int somme, int nb_pieces)
|
long nb_facons_rendre(int somme, int nb_pieces)
|
||||||
{
|
{
|
||||||
|
if (somme < 0 || nb_pieces < 0)
|
||||||
|
return 0;
|
||||||
if (somme == 0)
|
if (somme == 0)
|
||||||
return 1;
|
return 1;
|
||||||
if (somme < 0 || nb_pieces == 0)
|
if (nb_pieces == 0)
|
||||||
return 0;
|
return 0;
|
||||||
return nb_facons_rendre(somme - PIECES[nb_pieces - 1], nb_pieces) +
|
if (nb_pieces > NB_PIECES)
|
||||||
nb_facons_rendre(somme, nb_pieces - 1);
|
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) */
|
/* F9 : catégorie d'une transaction (pour les statistiques) */
|
||||||
@@ -216,10 +239,16 @@ int categorie(const Transaction *t)
|
|||||||
/* F10 : ajoute une ligne à la fin du rapport */
|
/* F10 : ajoute une ligne à la fin du rapport */
|
||||||
int longueur(const char *s)
|
int longueur(const char *s)
|
||||||
{
|
{
|
||||||
int n = 0;
|
static const char *chaine_connue = NULL;
|
||||||
while (s[n] != '\0')
|
static int n_connu = 0;
|
||||||
n++;
|
|
||||||
return n;
|
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)
|
void ajouter_ligne(char *rapport, const char *ligne)
|
||||||
|
|||||||
Reference in New Issue
Block a user