Add 06/05
This commit is contained in:
parent
edcf3d3bc7
commit
e9a50043d5
48
2024/05/06-05-24-Bonus/a.py
Normal file
48
2024/05/06-05-24-Bonus/a.py
Normal file
@ -0,0 +1,48 @@
|
||||
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()
|
16
2024/05/06-05-24-Bonus/a_fuzzing.py
Normal file
16
2024/05/06-05-24-Bonus/a_fuzzing.py
Normal file
@ -0,0 +1,16 @@
|
||||
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…
Reference in New Issue
Block a user