forked from menault/2026_TD3_DEV51_Qualite_Algo
F3 : solde par client en un seul parcours (O(n × C) → O(n + C))
Pour chacun des 2 000 clients, on reparcourait les 30 000 transactions (60 millions de tests). On met les totaux à zéro, puis chaque montant est ajouté directement au total de son client. Les montants de chaque client sont additionnés dans le même ordre : les totaux sont identiques. Temps (-O2) : 0,097 s → 0,087 s. Empreinte inchangée (ff68d260a7a58441). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -107,12 +107,10 @@ int nb_clients_distincts(const Transaction *t, int n)
|
||||
/* F3 : solde total de chaque client */
|
||||
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;
|
||||
for (int i = 0; i < n; i++)
|
||||
if (t[i].client == c)
|
||||
totaux[c] += t[i].montant;
|
||||
}
|
||||
for (int i = 0; i < n; i++) /* un seul parcours : chaque montant va */
|
||||
totaux[t[i].client] += t[i].montant; /* directement au total de son client */
|
||||
}
|
||||
|
||||
/* F4 : solde total de chaque jour */
|
||||
|
||||
Reference in New Issue
Block a user