Compare commits
No commits in common. "e9a50043d5d13fac380f34c37be72a5f6d08b0fc" and "6008dcaf288b64f0616eb0143972b792f3cbd187" have entirely different histories.
e9a50043d5
...
6008dcaf28
@ -1,15 +0,0 @@
|
|||||||
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())
|
|
@ -1,18 +0,0 @@
|
|||||||
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)
|
|
@ -1,13 +0,0 @@
|
|||||||
# 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)
|
|
@ -1,41 +0,0 @@
|
|||||||
/* 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";
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
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))
|
|
@ -1,28 +0,0 @@
|
|||||||
# 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())
|
|
@ -1,9 +0,0 @@
|
|||||||
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))
|
|
@ -1,80 +0,0 @@
|
|||||||
# 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))))
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
|||||||
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)]))
|
|
@ -1,48 +0,0 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
from munkres import Munkres
|
|
||||||
|
|
||||||
m = Munkres()
|
|
||||||
|
|
||||||
n, k = map(int, input().split())
|
|
||||||
|
|
||||||
ciphering = input()
|
|
||||||
sol = input()
|
|
||||||
|
|
||||||
def from_letter(a):
|
|
||||||
if ord(a) < ord('a'):
|
|
||||||
return 26+ord(a)-ord('A')
|
|
||||||
return ord(a)-ord('a')
|
|
||||||
|
|
||||||
def to_letter(n):
|
|
||||||
if n > 25:
|
|
||||||
return chr(n-26+ord('A'))
|
|
||||||
return chr(n+ord('a'))
|
|
||||||
|
|
||||||
mat = [
|
|
||||||
[0]*k for _ in range(k)
|
|
||||||
]
|
|
||||||
|
|
||||||
for letter1, letter2 in zip(ciphering, sol):
|
|
||||||
mat[from_letter(letter1)][from_letter(letter2)] += 1
|
|
||||||
|
|
||||||
|
|
||||||
cost_matrix = []
|
|
||||||
for row in mat:
|
|
||||||
cost_row = []
|
|
||||||
for col in row:
|
|
||||||
cost_row += [sys.maxsize - col]
|
|
||||||
cost_matrix += [cost_row]
|
|
||||||
|
|
||||||
m = Munkres()
|
|
||||||
indexes = m.compute(cost_matrix)
|
|
||||||
total = 0
|
|
||||||
for row, column in indexes:
|
|
||||||
value = mat[row][column]
|
|
||||||
total += value
|
|
||||||
|
|
||||||
print(total)
|
|
||||||
|
|
||||||
for row, column in indexes:
|
|
||||||
print(to_letter(column), end='')
|
|
||||||
print()
|
|
@ -1,16 +0,0 @@
|
|||||||
import random
|
|
||||||
|
|
||||||
def to_letter(n):
|
|
||||||
if n > 25:
|
|
||||||
return chr(n-26+ord('A'))
|
|
||||||
return chr(n+ord('a'))
|
|
||||||
|
|
||||||
n, k = 500000, 30
|
|
||||||
|
|
||||||
print(n, k)
|
|
||||||
for i in range(n):
|
|
||||||
print(to_letter(random.randint(0, k-1)), end="")
|
|
||||||
print()
|
|
||||||
for i in range(n):
|
|
||||||
print(to_letter(random.randint(0, k-1)), end="")
|
|
||||||
print()
|
|
Loading…
x
Reference in New Issue
Block a user