Moved kattis from Uni repo
This commit is contained in:
20
kattis/problems/24_10_23/apple_delivery/main.c
Normal file
20
kattis/problems/24_10_23/apple_delivery/main.c
Normal file
@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int lastDigit(int n) {
|
||||
int result = 1;
|
||||
while (--n) {
|
||||
result *= n;
|
||||
}
|
||||
return result % 10;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
while(n--) {
|
||||
int num;
|
||||
scanf("%d", &num);
|
||||
printf("%d\n", lastDigit(num));
|
||||
}
|
||||
}
|
20
kattis/problems/24_10_23/apple_delivery/main.c.orig
Normal file
20
kattis/problems/24_10_23/apple_delivery/main.c.orig
Normal file
@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int lastDigit(int n) {
|
||||
int result = 1;
|
||||
while (--n) {
|
||||
result *= n;
|
||||
}
|
||||
return result % 10;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
while(n--) {
|
||||
int num;
|
||||
scanf("%d", &num);
|
||||
printf("%d\n", lastDigit(num));
|
||||
}
|
||||
}
|
40
kattis/problems/24_10_23/apple_delivery/main.py
Normal file
40
kattis/problems/24_10_23/apple_delivery/main.py
Normal file
@ -0,0 +1,40 @@
|
||||
def houses_within_radius(r):
|
||||
return (2*r + 1)**2
|
||||
|
||||
def apples_to_remove(n, radii):
|
||||
# Calculate total houses
|
||||
total_houses = sum([houses_within_radius(r) for r in radii])
|
||||
|
||||
# Calculate the remainder
|
||||
remainder = total_houses % 8
|
||||
|
||||
if remainder == 0:
|
||||
# No apples need to be removed
|
||||
return 0
|
||||
|
||||
# Calculate houses exactly at each radius
|
||||
houses_at_radius = [houses_within_radius(r) - houses_within_radius(r-1) for r in radii if r > 0]
|
||||
|
||||
# Sort the houses_at_radius list
|
||||
houses_at_radius.sort()
|
||||
|
||||
# Try to minimize the apples not given
|
||||
apples_not_given = 0
|
||||
for houses in houses_at_radius:
|
||||
if houses % 8 >= remainder:
|
||||
apples_not_given += (houses % 8) - remainder
|
||||
remainder = 0
|
||||
break
|
||||
else:
|
||||
apples_not_given += houses % 8
|
||||
remainder -= houses % 8
|
||||
|
||||
if remainder > 0:
|
||||
apples_not_given += 8 - remainder
|
||||
|
||||
return apples_not_given
|
||||
|
||||
# Sample Test
|
||||
n = int(input())
|
||||
radii = list(map(int, input().split()))
|
||||
print(apples_to_remove(n, radii))
|
BIN
kattis/problems/24_10_23/apple_delivery/program
Executable file
BIN
kattis/problems/24_10_23/apple_delivery/program
Executable file
Binary file not shown.
Reference in New Issue
Block a user