Last active
October 25, 2015 06:50
-
-
Save ZeronSix/aada7914c46019bc2848 to your computer and use it in GitHub Desktop.
Школьная олимпида
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open("input.txt", "r") as fi: | |
k, n, p, s = map(int, fi.readline().split(" ")) | |
i = 0 | |
while True: | |
if (i + 1) * k > n or (i + 1) * k * p > s: | |
break | |
else: | |
i += 1 | |
with open("output.txt", "w") as fo: | |
fo.write(i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open("input.txt", "r") as fi: | |
strings = [fi.readline() for _ in range(0, 3)] | |
max_string = "" | |
l = len(strings[0]) | |
for i in range(0, l): | |
max_char = strings[0][i] | |
for j in range(1, 3): | |
if strings[j][i] > max_char: | |
max_char = strings[j][i] | |
max_string += max_char | |
with open("output.txt", "w") as fo: | |
fo.write(max_string) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open("input.txt", "r") as fi: | |
n = int(input()) | |
split_table = {} | |
def get_split_sum(a, start_index, end): | |
l = end - start_index + 1 | |
if l <= 2: | |
return 0 | |
if (start_index + 1, end) in split_table: | |
sum1 = split_table[(start_index + 1, end)] | |
else: | |
sum1 = get_split_sum(a, start_index + 1, end) | |
if (start_index + 2, end) in split_table: | |
sum2 = split_table[(start_index + 2, end)] | |
else: | |
sum2 = get_split_sum(a, start_index + 2, end) | |
split_table[(start_index, end)] = min(a[start_index] + a[start_index + 1] + sum1, | |
a[start_index + 1] + a[start_index + 2] + sum2) | |
return split_table[(start_index, end)] | |
digits = [] | |
while n > 0: | |
digits.append(n % 10) | |
n //= 10 | |
IN_EVEN = 0 | |
IN_ODD = 1 | |
state = IN_EVEN | |
i = 0 | |
start = 0 | |
split_sum = 0 | |
while i < len(digits): | |
is_even = (digits[i] % 2 == 0) | |
if is_even: | |
if state == IN_ODD: | |
if i - start > 2: | |
split_sum += get_split_sum(digits, start, i - 1) | |
start = i | |
state = IN_EVEN | |
else: | |
if state == IN_EVEN: | |
if i - start > 2: | |
split_sum += get_split_sum(digits, start, i - 1) | |
start = i | |
state = IN_ODD | |
i += 1 | |
if i - start > 2: | |
split_sum += get_split_sum(digits, start, i - 1) | |
with open("output.txt", "w") as fo: | |
fo.write(str(split_sum)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment