Ajout du partiel (Aïe)
This commit is contained in:
parent
6008dcaf28
commit
edcf3d3bc7
15
2024/04/29-04-24-Partiel/a1.py
Normal file
15
2024/04/29-04-24-Partiel/a1.py
Normal file
@ -0,0 +1,15 @@
|
||||
import math
|
||||
|
||||
|
||||
def main():
|
||||
n, x, y = map(int, input().split())
|
||||
|
||||
rapp = int(y/x) # à partir de cb
|
||||
if rapp > 0:
|
||||
return math.ceil(math.log2(n)-math.log2(int(y/x)))*(x+y)+int(y/x)*x
|
||||
|
||||
return math.ceil(math.log2(n))*(x+y)
|
||||
|
||||
|
||||
for _ in range(int(input())):
|
||||
print(main())
|
18
2024/04/29-04-24-Partiel/b1.py
Normal file
18
2024/04/29-04-24-Partiel/b1.py
Normal file
@ -0,0 +1,18 @@
|
||||
R, r = map(int, input().split())
|
||||
Ri = [int(input()) for _ in range(R)]
|
||||
recettes = []
|
||||
for i in range(r):
|
||||
r_in, r_out = map(int, input().split())
|
||||
rec = [tuple(map(int, input().split())) for _ in range(r_in)]
|
||||
if r_out != 0:
|
||||
recettes.append((r_in, r_out, rec))
|
||||
|
||||
perfect = 0
|
||||
recettes.sort(key=lambda x:sum((r_[1] for r_ in x[2]))/x[0])TEMPS
|
||||
for r_in, r_out, rec in recettes: # need to use the best recipes first !
|
||||
produced = min([int(Ri[r_[0]-1]/r_[1]) for r_ in rec])
|
||||
perfect += r_out*produced
|
||||
for r_ in rec:
|
||||
Ri[r_[0]-1] -= produced*r_[1]
|
||||
|
||||
print(perfect)
|
13
2024/04/29-04-24-Partiel/c1.py
Normal file
13
2024/04/29-04-24-Partiel/c1.py
Normal file
@ -0,0 +1,13 @@
|
||||
# Accepted #
|
||||
n = int(input())
|
||||
discos = [tuple(map(int, input().split())) for _ in range(n)]
|
||||
|
||||
discos.sort(key=lambda x:(-x[1],x[0]))
|
||||
|
||||
discount = 0
|
||||
balance = 0
|
||||
for price, nxt in discos:
|
||||
balance -= price - discount
|
||||
discount += nxt
|
||||
|
||||
print(-balance)
|
41
2024/04/29-04-24-Partiel/c2.cpp
Normal file
41
2024/04/29-04-24-Partiel/c2.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/* PARTIEL TEMPS */
|
||||
// Runtime error: doit-être relative au temps d'exécution,
|
||||
// Je n'ai pas eu le temps d'optimiser plus
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
vector<pair<int, int>> discos;
|
||||
int input1, input2;
|
||||
|
||||
cin >> n;
|
||||
for (int i=0; i < n; i++) {
|
||||
cin >> input1;
|
||||
cin >> input2;
|
||||
|
||||
discos.push_back(pair<int, int>(input1, input2));
|
||||
}
|
||||
|
||||
// On trie par ordre lexicographique sur (-x[0], x[1])
|
||||
sort(
|
||||
begin(discos),
|
||||
end(discos),
|
||||
[](pair<int, int> a, pair<int, int> b) {
|
||||
return !(-a.second>-b.second || (a.second==b.second && a.first > b.first));
|
||||
}
|
||||
);
|
||||
|
||||
int discount = 1;
|
||||
int balance = 0;
|
||||
|
||||
// On calcule le discount et les achats
|
||||
for (int i=0; i < n; i++) {
|
||||
balance -= discos[i].first / discount;
|
||||
discount *= discos[i].second;
|
||||
}
|
||||
cout << (-balance) << "\n";
|
||||
}
|
14
2024/04/29-04-24-Partiel/c2.py
Normal file
14
2024/04/29-04-24-Partiel/c2.py
Normal file
@ -0,0 +1,14 @@
|
||||
n = int(input())
|
||||
discos = [tuple(map(int, input().split())) for _ in range(n)]
|
||||
|
||||
discos.sort(key=lambda x:(-x[1],x[0]))
|
||||
|
||||
print(discos)
|
||||
|
||||
discount = 1
|
||||
balance = 0
|
||||
for price, nxt in discos:
|
||||
balance -= price / discount
|
||||
discount *= nxt
|
||||
|
||||
print(-int(balance))
|
28
2024/04/29-04-24-Partiel/c3.py
Normal file
28
2024/04/29-04-24-Partiel/c3.py
Normal file
@ -0,0 +1,28 @@
|
||||
# PARTIEL BUG #
|
||||
# Mauvaise réponse sur le test 2
|
||||
# Complexité: O(k*n*log(n)), cela ne semble pas être le problème (ou pas encore)
|
||||
# l'idée est de trier à chaque fois pour trouver l'élément qui, en prenant en compte les k_-1 réductions qu'il va offrir, coûtera le moins cher
|
||||
|
||||
def find_best(k):
|
||||
return lambda x: x[0]-(k-1)*x[1]
|
||||
|
||||
def main():
|
||||
n, k = map(int, input().split())
|
||||
discos = [tuple(map(int, input().split())) for _ in range(n)]
|
||||
|
||||
balance = 0
|
||||
total_discount = 0
|
||||
for k_ in range(k, 0, -1):
|
||||
if len(discos) == 0:
|
||||
exit(1)
|
||||
# On cherche celui qui rapportera le plus (/coûtera le moins)
|
||||
discos.sort(key=find_best(k_))
|
||||
# On prend en compte combien il nous fait gagner
|
||||
balance -= discos[0][0]
|
||||
total_discount += discos[0][1]*(k_-1)
|
||||
del discos[0]
|
||||
|
||||
return -(balance+total_discount)
|
||||
|
||||
for _ in range(int(input())):
|
||||
print(main())
|
9
2024/04/29-04-24-Partiel/c3_fuzzing.py
Normal file
9
2024/04/29-04-24-Partiel/c3_fuzzing.py
Normal file
@ -0,0 +1,9 @@
|
||||
import random
|
||||
|
||||
t = random.randint(1, 20)
|
||||
print(t)
|
||||
for _ in range(t):
|
||||
n, k = random.randint(1, 2000), random.randint(1, 50)
|
||||
print(n, k)
|
||||
for _ in range(n):
|
||||
print(random.randint(1, 2000), random.randint(1, 50))
|
80
2024/04/29-04-24-Partiel/d1.py
Normal file
80
2024/04/29-04-24-Partiel/d1.py
Normal file
@ -0,0 +1,80 @@
|
||||
# PARTIEL BUG #
|
||||
""" idée de l'algo:
|
||||
1. on trouve le point du polygone (n+1) le plus proche du point actuel (n) et de l'arrivée.
|
||||
2. on le rajoute au tracé existant (1, 2, ... n+1)
|
||||
3. on regarde si on peut raccourcir le tracé existant en supprimant le point (n), sans intersection avec le polygone
|
||||
4. on répète jusqu'à atteindre l'arrivée
|
||||
|
||||
Problème: il faut aussi s'assurer qu'il ny aura pas de collision, même sans raccourcir. Exemple:
|
||||
|
||||
• c
|
||||
/|
|
||||
/ |
|
||||
/ |
|
||||
/ |
|
||||
• a | • b
|
||||
| /
|
||||
|/
|
||||
• d
|
||||
|
||||
si on est actuellement au point (a), on risque de prendre (b) sans se soucier de l'arête (c-d)
|
||||
"""
|
||||
from math import sqrt
|
||||
|
||||
|
||||
def dist(a, b) -> float:
|
||||
x1, y1 = a
|
||||
x2, y2 = b
|
||||
return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))
|
||||
|
||||
|
||||
def ccw(a, b, c):
|
||||
return (c[1]-a[1]) * (b[0]-a[0]) > (b[1]-a[1]) * (c[0]-a[0])
|
||||
|
||||
|
||||
def intersect(a, b, c, d) -> bool:
|
||||
"""
|
||||
est-ce que les segments a-b et c-d se croisent ?
|
||||
"""
|
||||
return ccw(a, c, d) != ccw(b, c, d) and ccw(a, b, c) != ccw(a, b, d)
|
||||
|
||||
def is_safe(pt1, pt2) -> bool:
|
||||
"""
|
||||
Est-ce que pt1-pt2 croise un des segments du polygone ?
|
||||
"""
|
||||
return not True in (
|
||||
intersect(pts[j], pts[(j+1)%len(pts)], pt1, pt2) for j in range(len(pts))
|
||||
)
|
||||
|
||||
n = int(input())
|
||||
x_dep, y_dep = map(int, input().split())
|
||||
x_arr, y_arr = map(int, input().split())
|
||||
xi = list(map(int, input().split()))
|
||||
yi = list(map(int, input().split()))
|
||||
pts = [(xi[i], yi[i]) for i in range(n)]
|
||||
|
||||
dep = x_dep, y_dep
|
||||
arr = x_arr, y_arr
|
||||
|
||||
|
||||
trajet = [dep]
|
||||
curr_pos = dep
|
||||
while curr_pos != arr:
|
||||
avail_pts = [
|
||||
pt for pt in pts+[arr] if is_safe(curr_pos, pt)
|
||||
] # points qui ne croisent pas
|
||||
# On trie par distance à la position actuelle et à l'arrivée
|
||||
avail_pts.sort(key=lambda x: dist(curr_pos, x)+dist(arr, x))
|
||||
|
||||
new_pos = avail_pts[0]
|
||||
if avail_pts[0] != arr:
|
||||
pts.remove(avail_pts[0]) # on peut gagner un peu de temps ?
|
||||
if len(trajet) > 1 and is_safe(trajet[-2], new_pos):
|
||||
# On peut retirer l'élément cur_pos
|
||||
del trajet[-1]
|
||||
|
||||
trajet.append(new_pos)
|
||||
curr_pos = new_pos
|
||||
|
||||
print(sum((dist(trajet[i], trajet[i+1]) for i in range(len(trajet)-1))))
|
||||
|
14
2024/04/29-04-24-Partiel/d1_fuzzing.py
Normal file
14
2024/04/29-04-24-Partiel/d1_fuzzing.py
Normal file
@ -0,0 +1,14 @@
|
||||
import random
|
||||
|
||||
def rand():
|
||||
return str(random.randint(int(10e-9), int(10e9)))
|
||||
|
||||
def rand_pt():
|
||||
return f"{rand()} {rand()}"
|
||||
|
||||
n = random.randint(1, 30)
|
||||
print(n)
|
||||
print(rand_pt())
|
||||
print(rand_pt())
|
||||
print(" ".join([rand() for _ in range(n)]))
|
||||
print(" ".join([rand() for _ in range(n)]))
|
Loading…
Reference in New Issue
Block a user