diff --git a/29-01-24/division.py b/29-01-24/division.py new file mode 100644 index 0000000..2d28dc4 --- /dev/null +++ b/29-01-24/division.py @@ -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}") \ No newline at end of file diff --git a/29-01-24/football.py b/29-01-24/football.py new file mode 100644 index 0000000..dcc734b --- /dev/null +++ b/29-01-24/football.py @@ -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() \ No newline at end of file diff --git a/29-01-24/gratitude.py b/29-01-24/gratitude.py new file mode 100644 index 0000000..5470baf --- /dev/null +++ b/29-01-24/gratitude.py @@ -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() \ No newline at end of file diff --git a/29-01-24/improve_it.py b/29-01-24/improve_it.py new file mode 100644 index 0000000..d557155 --- /dev/null +++ b/29-01-24/improve_it.py @@ -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() \ No newline at end of file diff --git a/29-01-24/king_escape.py b/29-01-24/king_escape.py new file mode 100644 index 0000000..80e51a4 --- /dev/null +++ b/29-01-24/king_escape.py @@ -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() \ No newline at end of file diff --git a/29-01-24/king_escape2.py b/29-01-24/king_escape2.py new file mode 100644 index 0000000..6759bfb --- /dev/null +++ b/29-01-24/king_escape2.py @@ -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() \ No newline at end of file diff --git a/29-01-24/lights.py b/29-01-24/lights.py new file mode 100644 index 0000000..374b472 --- /dev/null +++ b/29-01-24/lights.py @@ -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() \ No newline at end of file diff --git a/29-01-24/magic.py b/29-01-24/magic.py new file mode 100644 index 0000000..650f64a --- /dev/null +++ b/29-01-24/magic.py @@ -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() \ No newline at end of file diff --git a/29-01-24/stages.py b/29-01-24/stages.py new file mode 100644 index 0000000..9a9c48b --- /dev/null +++ b/29-01-24/stages.py @@ -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() \ No newline at end of file diff --git a/29-01-24/sujet.pdf b/29-01-24/sujet.pdf new file mode 100644 index 0000000..d346d61 Binary files /dev/null and b/29-01-24/sujet.pdf differ diff --git a/29-01-24/sum.c b/29-01-24/sum.c new file mode 100644 index 0000000..6fc50ed --- /dev/null +++ b/29-01-24/sum.c @@ -0,0 +1,29 @@ +#include +#include + +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; +} \ No newline at end of file diff --git a/29-01-24/sum.py b/29-01-24/sum.py new file mode 100644 index 0000000..92aee64 --- /dev/null +++ b/29-01-24/sum.py @@ -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") \ No newline at end of file