Оновити coins.c
This commit is contained in:
58
coins.c
58
coins.c
@@ -7,8 +7,53 @@
|
||||
#define MAX_N 1024
|
||||
#define WORDS ((MAX_N / 64) + 1)
|
||||
#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
|
||||
// ==========================================
|
||||
@@ -180,5 +225,16 @@ int main() {
|
||||
end = clock();
|
||||
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);
|
||||
|
||||
//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;
|
||||
}
|
||||
Reference in New Issue
Block a user