commit everything and create folders

This commit is contained in:
augustin64 2024-04-15 13:45:30 +02:00
parent dda8fdf3fa
commit 30b823c6ab
47 changed files with 530 additions and 0 deletions

38
2024/02/05-02-24/a.py Normal file
View File

@ -0,0 +1,38 @@
def score2(elems):
count = sum(elems)
total = 0
allowed = count-(count//4)
for i in range(100, -1, -1):
if allowed > elems[i]:
total += i*elems[i]
allowed -= elems[i]
else:
total += i*allowed
return total
return total
def main():
ct = int(input())
for _ in range(ct):
input()
me_ = [int(i) for i in input().split()]
other_ = [int(i) for i in input().split()]
me = [0 for i in range(101)]
other = [0 for i in range(101)]
for i in range(len(me_)):
me[me_[i]] += 1
other[other_[i]] += 1
i=0
while score2(me) < score2(other):
me[100] += 1
other[0] += 1
i+=1
print(i)
main()

19
2024/02/05-02-24/b.py Normal file
View File

@ -0,0 +1,19 @@
import bisect
def main():
n_tests = int(input())
for _ in range(n_tests):
n, m = [int(i) for i in input().split()]
ai = [int(i) for i in input().split()]
bj = [int(i) for i in input().split()]
ai.sort()
for i in range(m):
tmp = ai.pop(0)
bisect.insort(ai, bj[i])
print(sum(ai))
main()

35
2024/02/05-02-24/c.py Normal file
View File

@ -0,0 +1,35 @@
import sys
def ask(a):
print(a)
sys.stdout.flush()
return int(input())
def main():
# max distance, size of p
m, n = [int(i) for i in input().split()]
answers = []
for i in range(n):
a = ask(m)
if a == 0:
return
answers.append(a)
asked = n
ppos = 0
lower, upper = 1, m-1
while asked < 60:
curr = lower + (upper-lower)//2
a = ask(curr)
asked += 1
if a*answers[ppos%n] == 1:
upper = curr -1
elif a*answers[ppos%n] == -1:
lower = curr +1
else:
return
ppos += 1
main()

53
2024/02/05-02-24/d.py Normal file
View File

@ -0,0 +1,53 @@
from functools import cache
import bisect
import sys
base_limit = sys.getrecursionlimit()
def sc(cons):
return (cons*(cons+1))/2
def brutetop(a, b, k):
first = {}
for i in range(len(a)):
if a[i] not in first and a[i] != b[i]:
first[a[i]] = i
@cache
def brute(Q, i, cons):
if i == len(a):
return sc(cons)
if a[i] == b[i] or a[i] in Q:
return brute(Q, i+1, cons+1)
if len(Q) < k and (a[i] in first and i == first[a[i]]):
Qcop = list(Q)
bisect.insort(Qcop, a[i])
res1 = brute(Q, i+1, 0) + sc(cons)
res2 = brute(tuple(Qcop), i+1, cons+1)
return max(res1, res2)
return brute(Q, i+1, 0) + sc(cons)
return brute((), 0, 0)
def main():
ct = int(input())
ress = []
for _ in range(ct):
# len(a, b), char lim
n, k = [int(i) for i in input().split()]
a = input() # a = base string
b = input() # b = objective
sys.setrecursionlimit(max(len(a), base_limit))
print(int(brutetop(a, b, k)))
#ress.append(str(int(brutetop(a, b, k))))
#print("\n".join(ress))
main()

View File

@ -0,0 +1,14 @@
import random
from string import ascii_lowercase
def rand_letters(a):
return "".join(random.choices(ascii_lowercase[:10], k=a))
count = 5
print(count)
for i in range(count):
size = random.randint(0, 100000)
repl = random.randint(0, 10)
print(size, repl)
print(rand_letters(size))
print(rand_letters(size))

BIN
2024/02/05-02-24/sujet.pdf Normal file

Binary file not shown.

74
2024/02/12-02-24/a.py Normal file
View File

@ -0,0 +1,74 @@
def product(l):
if l == []:
return 1
return l[0]*product(l[1:])
def once():
input()
ai = [int(i) for i in input().split()]
ai_p = [a for a in ai if a > 0]
ai_n = [a for a in ai if a < 0]
contains0 = (0 in ai)
ai_p.sort(reverse=True)
ai_n.sort()
if ai_p == []: # all neg or null
if contains0:
return 0
return product(ai_n[-5:])
elif len(ai_n)+len(ai_p) < 5:
return product(ai)
elif len(ai_n)+len(ai_p) == 5:
p = product(ai_n)*product(ai_p)
if p < 0 and contains0:
return 0
return p
else:
# selected = [ai_p[0]]
i_n = 0
i_p = 1
prod = ai_p[0]
for _ in range(2):
if i_n + 2 > len(ai_n) and i_p + 2 <= len(ai_p):
prod *= ai_p[i_p]*ai_p[i_p+1]
# selected.append(ai_p[i_p])
# selected.append(ai_p[i_p+1])
i_p+=2
elif i_p + 2 > len(ai_p) and i_n + 2 <= len(ai_n):
prod *= ai_n[i_n]*ai_n[i_n+1]
# selected.append(ai_n[i_n])
# selected.append(ai_n[i_n+1])
i_n+=2
elif i_p +1 == len(ai_p) and i_n+1 == len(ai_n):
prod *= ai_p[-1]*ai_n[-1]
else:
pp = ai_p[i_p]*ai_p[i_p+1]
pn = ai_n[i_n]*ai_n[i_n+1]
if pp > pn:
prod *= pp
# selected.append(ai_p[i_p])
# selected.append(ai_p[i_p+1])
i_p += 2
else:
prod *= pn
# selected.append(ai_n[i_n])
# selected.append(ai_n[i_n+1])
i_n += 2
return prod
def main():
count = int(input())
for _ in range(count):
print(once())
main()

27
2024/02/12-02-24/b.py Normal file
View File

@ -0,0 +1,27 @@
def solve():
n = int(input())
env = input()
winners_ct = [1]
t = env[0]
ind, k = 1, 1
for i in range(1, len(env)):
new = env[i]
if new == t:
k += 1
winners_ct.append(winners_ct[-1])
else:
winners_ct.append(winners_ct[-1]+k)
k = 1
t = new
return " ".join([str(a) for a in winners_ct])
def main():
count = int(input())
for _ in range(count):
print(solve())
main()

0
2024/02/12-02-24/c.py Normal file
View File

View File

@ -0,0 +1,7 @@
import random
print(50)
for i in range(50):
size = random.randint(5, 10)
print(size)
print(" ".join([str(random.randint(-100, 100)) for _ in range(size)]))

49
2024/02/19-02-24/c.py Normal file
View File

@ -0,0 +1,49 @@
def min_new(a, m):
while m in a:
m+=1
return m
def max_new(a: set[int], m):
while m in a:
m-=1
return m
def get_minimal(a, n):
used = set(a)
if len(used) != len(a):
return [-1]
arr = []
for i in range(n//2):
m = max_new(used, a[i])
used.add(m)
if m <= 0:
return [-1]
arr.append(m)
for i in range(n//2):
for j in range(i, n//2):
if arr[j] < arr[i] and arr[i] < a[j]:
tmp = arr[j]
arr[j] = arr[i]
arr[i] = tmp
return arr
# Réécrire en c++
def main():
ct = int(input())
for i in range(ct):
n = int(input())
a = [int(b) for b in input().split()]
arr = get_minimal(a, n)
if arr == [-1]:
print(-1)
else:
print(" ".join([str(arr[i])+" "+str(a[i]) for i in range(len(arr))]))
main()

38
2024/03/11-03-24/a2.py Normal file
View File

@ -0,0 +1,38 @@
def repr(uf, i):
if uf[i] == i:
return i
uf[i] = repr(uf, uf[i])
return uf[i]
def union(uf, val, i, j):
ri = repr(uf, i)
rj = repr(uf, j)
uf[rj] = ri
val[ri] = val[rj] = min(val[ri], val[rj])
def main():
[n, k] = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
couples = [[int(i)-1 for i in input().split()] for _ in range(k)]
uf = [i for i in range(n)]
val = [a[i] for i in range(n)]
for (i, j) in couples:
ri = repr(uf, i)
rj = repr(uf, j)
if ri != rj:
union(uf, val, i, j)
mini = 0
for i in range(n):
if repr(uf, i) == i:
mini += val[i]
return mini
print(main())

46
2024/03/11-03-24/d.py Normal file
View File

@ -0,0 +1,46 @@
def main():
n, m = [int(i) for i in input().split()]
uv = [[int(i) for i in input().split()] for i in range(m)]
if m==n*(n-1)/2:
print(3)
out = []
u, v = uv[0]
for a, b in uv:
if (a, b) == (u, v):
out.append(1)
elif a==u or b==u:
out.append(2)
else:
out.append(3)
return " ".join([str(i) for i in out])
# Trouver un sommet de degré != n-1
degs = [0 for _ in range(n)]
for u, v in uv:
degs[u-1] += 1
degs[v-1] += 1
j=-1
for i in range(n):
if degs[i] < n-1:
j = i+1
break
if j==-1:
return
print(2)
out = []
for u, v in uv:
if u==j or v==j:
out.append(2)
else:
out.append(1)
return " ".join([str(i) for i in out])
for _ in range(int(input())):
print(main())

View File

@ -0,0 +1,21 @@
import random
LENGTH=1
print(LENGTH)
for _ in range(LENGTH):
n = random.randint(1, 200000)
n = 200000
print(n)
root = random.randint(1, n)
l = []
for i in range(n):
if i==root:
l.append(str(root))
else:
j = i
while i==j:
j=random.randint(1, n)
l.append(str(j))
print(" ".join(l))

36
2024/03/25-03-24/c.py Normal file
View File

@ -0,0 +1,36 @@
n = int(input())
points = [tuple(map(int, input().split())) for _ in range(n)]
p1 = points[0]
d_min = float("inf")
p_min = -2
def dist(pa, pb):
return (pb[0]-pa[0])*(pb[0]-pa[0]) + (pb[1]-pa[1])*(pb[1]-pa[1])
i2 = min((i for i in range(1, n)), key=lambda x:dist(p1, points[x]))
p2 = points[i2]
def aligned(p1, p2, p3):
# Extract coordinates of points
x1, y1 = p1
x2, y2 = p2
x3, y3 = p3
# Calculate slopes of lines formed by pairs of points
slope1 = (y2 - y1) / (x2 - x1) if x2 - x1 != 0 else float('inf')
slope2 = (y3 - y2) / (x3 - x2) if x3 - x2 != 0 else float('inf')
# Check if slopes are equal (i.e., points are aligned)
return slope1 == slope2
for i in range(1, n):
if i == i2:
continue
d = dist(p1, points[i])
if d <= d_min and not aligned(p1, p2, points[i]):
d_min = d
p_min = i
print(1, i2+1, p_min+1)

20
2024/03/25-03-24/d.py Normal file
View File

@ -0,0 +1,20 @@
from math import ceil
def main():
x, y = [int(i) for i in input().split()]
if x==y:
return x
c = ceil(x / (2*y))
if x < y:
return -1
if c > (x+y)/(2*x):
print(c, (x+y)/(2*x))
c = ceil((x+y)/(2*x))
return (x+y)/(2*c)
print(main())

15
2024/04/08-04-24/a.py Normal file
View File

@ -0,0 +1,15 @@
def main():
n, d = map(int, input().split())
a = [int(i) for i in input()]
for c in range(len(a)):
i = a[c]
if i < d:
a.insert(c, d)
return "".join([str(b) for b in a])
return "".join([str(b) for b in a])+str(d)
for _ in range(int(input())):
print(main())

30
2024/04/08-04-24/b.py Normal file
View File

@ -0,0 +1,30 @@
def main():
length = int(input())
st = input()
counts = [(0, 0) for i in range(len(st)+1)]
found = set()
cur = 0
for i in range(len(st)):
c = st[i]
if c not in found:
found.add(c)
cur += 1
counts[i+1] = (cur, counts[i][1])
found = set()
cur = 0
for i in range(len(st)-1, -1, -1):
c = st[i]
if c not in found:
found.add(c)
cur += 1
counts[i] = (counts[i][0], cur)
# print(counts)
return max([(c[0]+c[1]) for c in counts])
for _ in range(int(input())):
print(main())

8
2024/04/08-04-24/c.py Normal file
View File

@ -0,0 +1,8 @@
def main():
n = int(input())
st = input()
for _ in range(int(input())):
print(main())