Оновити coins.c

This commit is contained in:
2026-03-29 22:44:38 +03:00
parent c08f97ee3f
commit 383fc06641

58
coins.c
View File

@@ -7,8 +7,53 @@
#define MAX_N 1024 #define MAX_N 1024
#define WORDS ((MAX_N / 64) + 1) #define WORDS ((MAX_N / 64) + 1)
#define ITERATIONS 10000000 #define ITERATIONS 10000000
#define NUMBER 86 #define NUMBER 999
//Artem
int main123(int n) {
int a = 0;
while (n != 0) {
if (n - 50 >= 0) {
n -= 50;
a++;
}
else {
if (n - 25 >= 0) {
n -= 25;
a++;
}
else {
if (n - 10 >= 0) {
n -= 10;
a++;
}
else {
if (n - 5 >= 0) {
n -= 5;
a++;
}
else {
if (n - 2 >= 0) {
n -= 2;
a++;
}
else {
if (n - 1 >= 0) {
n -= 1;
a++;
}
else {
break;
}
}
}
}
}
}
}
return a;
}
// ========================================== // ==========================================
// 1. TRADITIONAL DP (FOR-LOOP) APPROACH // 1. TRADITIONAL DP (FOR-LOOP) APPROACH
// ========================================== // ==========================================
@@ -180,5 +225,16 @@ int main() {
end = clock(); end = clock();
cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC; cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
printf("3. Optimized Bitwise Time: %f seconds (Answer: %d)\n", cpu_time_used, total_sum / ITERATIONS); printf("3. Optimized Bitwise Time: %f seconds (Answer: %d)\n", cpu_time_used, total_sum / ITERATIONS);
//Artem
total_sum = 0; // Reset
start = clock();
for (int i = 0; i < ITERATIONS; i++) {
total_sum += main123(n);
}
end = clock();
cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
printf("3. Artemtime: %f seconds (Answer: %d)\n", cpu_time_used, total_sum / ITERATIONS);
return 0; return 0;
} }