Add 29-01-2024

This commit is contained in:
augustin64 2024-01-30 15:04:05 +01:00
parent 37e4348b8d
commit a3729938ec
12 changed files with 236 additions and 0 deletions

14
29-01-24/division.py Normal file
View File

@ -0,0 +1,14 @@
count = input()
for i in range(int(count)):
line = int(input())
if line >= 1900:
div=1
elif line >= 1600:
div=2
elif line >= 1400:
div=3
else:
div=4
print(f"Division {div}")

15
29-01-24/football.py Normal file
View File

@ -0,0 +1,15 @@
def main():
nb = input()
team = "0"
count = 0
for i in nb:
if i != team:
team = i
count = 0
count += 1
if count >= 7:
print("YES")
return
print("NO")
main()

23
29-01-24/gratitude.py Normal file
View File

@ -0,0 +1,23 @@
def main():
N, K = [int(i) for i in input().split()]
things = [input() for _ in range(3*N)]
occ = {}
for i in range(len(things)):
t = things[i]
if t not in occ:
occ[t] = (0, i)
occ[t] = (occ[t][0]+1, i)
# nb d'apparition, date de première apparition, texte
data = [(occ[i][0], occ[i][1], i) for i in occ.keys()]
data.sort(key=lambda x: (x[0], x[1]), reverse=True)
cursor = 0
while cursor < K and cursor < len(data):
print(data[cursor][2])
cursor += 1
main()

20
29-01-24/improve_it.py Normal file
View File

@ -0,0 +1,20 @@
def main():
N, M = [int(i) for i in input().split()]
values = [[int(i) for i in input().split()] for _ in range(N)]
values.append([0, 0])
# best buy without sell at month 0
bests = {0: values[0][0]}
for i in range(len(values)):
for j in range(i-M, i):
if j in bests.keys():
if i not in bests.keys():
bests[i] = bests[j] - values[j][i-j] + values[i][0]
else:
bests[i] = min(bests[j] - values[j][i-j]+ values[i][0], bests[i])
print(bests[N])
main()

48
29-01-24/king_escape.py Normal file
View File

@ -0,0 +1,48 @@
import heapq
def is_blocked(d, ax, ay):
dx, dy = d
if dx == ax or dy == ay:
return True
if abs(dx-ax) == abs(dy-ay):
return True
return False
def valid(v, n):
return v[0] > 0 and v[1] > 0 and v[0] <= n and v[1] <= n
def dist(v, cx, cy):
return abs(v[0]-cx)**2+abs(v[1]-cy)**2
def main():
n = int(input())
ax, ay = [int(i) for i in input().split()] # queen
bx, by = [int(i) for i in input().split()] # king
cx, cy = [int(i) for i in input().split()] # dest
views = {(bx, by): 0}
queue = [(dist((bx, by), cx, cy), (bx, by))]
while queue:
prior, elem = heapq.heappop(queue)
if elem == (cx, cy):
print("YES")
return
voisins = []
for i in range(-1, 2):
for j in range(-1, 2):
v = (elem[0]+i, elem[1]+j)
if valid(v, n) and v not in views.keys():
voisins.append(v)
views.append(v)
for v in voisins:
if not is_blocked(v, ax, ay):
heapq.heappush(queue, (dist(v, cx, cy), v))
print("NO")
main()

16
29-01-24/king_escape2.py Normal file
View File

@ -0,0 +1,16 @@
def main():
n = int(input())
ax, ay = [int(i) for i in input().split()] # queen
bx, by = [int(i) for i in input().split()] # king
cx, cy = [int(i) for i in input().split()] # dest
if (bx > ax and ax > cx) or (cx > ax and ax > bx):
print("NO")
return
if (by > ay and ay > cy) or (cy > ay and ay > by):
print("NO")
return
print("YES")
main()

20
29-01-24/lights.py Normal file
View File

@ -0,0 +1,20 @@
def main():
N = int(input())
K = int(input())
ilist = [int(input()) for _ in range(K)]
nb = 0
lights = [True for _ in range(N+1)]
for j in range(K):
l = 1
i = ilist[j]
while i*l <= N:
lights[i*l] = not lights[i*l]
l+=1
nb = max(nb, len([0 for a in lights if not a]))
print(nb)
main()

17
29-01-24/magic.py Normal file
View File

@ -0,0 +1,17 @@
def main():
nb = input("")
poss = ["144", "14", "1"]
while nb != "":
ok = False
for i in poss:
if nb.startswith(i):
nb = nb[len(i):]
ok = True
break
if not ok:
print("NO")
return
print("YES")
main()

25
29-01-24/stages.py Normal file
View File

@ -0,0 +1,25 @@
def weight(c):
return ord(c)-ord('a')+1
def main():
n, k, = [int(i) for i in input().split()]
string = [i for i in input()]
string.sort(key=weight)
total_weight = 0
last_weight = -1
curr = 0
for i in string:
if curr == k:
break
if weight(i) > last_weight+1:
total_weight += weight(i)
last_weight = weight(i)
curr += 1
if curr == k:
print(total_weight)
else:
print(-1)
main()

BIN
29-01-24/sujet.pdf Normal file

Binary file not shown.

29
29-01-24/sum.c Normal file
View File

@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
int max(int a, int b) {
return a > b ? a : b;
}
int is_sum(int a, int b, int c) {
return a+b+c == max(a, max(b, c))*2;
}
int main() {
int count;
scanf("%d", &count);
int a, b, c;
for (int i=0; i < count; i++) {
scanf("%d %d %d", &a, &b, &c);
if (is_sum(a, b, c)) {
printf("YES\n");
} else {
printf("NO\n");
}
}
return 0;
}

9
29-01-24/sum.py Normal file
View File

@ -0,0 +1,9 @@
count = input("")
for i in range(int(count)):
line = input("").split()
numbers = [int(i) for i in line]
numbers.sort()
if numbers[2] == numbers[0]+numbers[1]:
print("YES")
else:
print("NO")