Moved kattis from Uni repo

This commit is contained in:
2023-12-01 13:35:13 +01:00
parent 28a6b807a3
commit aaa2c123b8
164 changed files with 3008 additions and 0 deletions

View 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));
}
}

View 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));
}
}

View 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))

Binary file not shown.