Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
T = int(input())
|
|
||||||
32
zeta_python/completed/1107.py
Normal file
32
zeta_python/completed/1107.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
class RemoteController:
|
||||||
|
"""
|
||||||
|
start at number 100
|
||||||
|
action:
|
||||||
|
press number not broken
|
||||||
|
press ++
|
||||||
|
press --
|
||||||
|
|
||||||
|
example(5457 with broken 6 7 8):
|
||||||
|
5 4 5 5 + +
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, broken: list[int]):
|
||||||
|
self.broken = broken
|
||||||
|
|
||||||
|
def solve(self, target: int) -> int:
|
||||||
|
"""return: number of press buttons to reach target number"""
|
||||||
|
mins = abs(target - 100)
|
||||||
|
for i in range(0, 1000000 + 1):
|
||||||
|
nums = list(map(int, str(i)))
|
||||||
|
if all(False if s in self.broken else True for s in nums):
|
||||||
|
mins = min(abs(target - i) + len(nums), mins)
|
||||||
|
|
||||||
|
return mins
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
N = int(input())
|
||||||
|
M = int(input())
|
||||||
|
broken = list(map(int, input().split())) if M != 0 else []
|
||||||
|
solver = RemoteController(broken)
|
||||||
|
print(solver.solve(N))
|
||||||
40
zeta_python/completed/13002.py
Normal file
40
zeta_python/completed/13002.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
input = sys.stdin.readline
|
||||||
|
|
||||||
|
|
||||||
|
class HappyCow:
|
||||||
|
def __init__(self, N: int, H: list[int]):
|
||||||
|
self.__N: int = N
|
||||||
|
self.__happiness: list[int] = H
|
||||||
|
self.__total: list[int] = [[0] * (self.__N + 2) for _ in range(self.__N + 2)]
|
||||||
|
|
||||||
|
for i in range(1, self.__N + 1):
|
||||||
|
day = i
|
||||||
|
self.__total[i][self.__N] = (
|
||||||
|
self.__total[i - 1][self.__N] + day * self.__happiness[i - 1]
|
||||||
|
)
|
||||||
|
self.__total[0][self.__N - i] = (
|
||||||
|
self.__total[0][self.__N - i + 1] + day * self.__happiness[self.__N - i]
|
||||||
|
)
|
||||||
|
|
||||||
|
for i in range(1, self.__N):
|
||||||
|
for j in range(self.__N - 1, i - 1, -1):
|
||||||
|
self.__total[i][j] = max(
|
||||||
|
[
|
||||||
|
self.__total[i - 1][j]
|
||||||
|
+ self.__happiness[i - 1] * (self.__N - j + i),
|
||||||
|
self.__total[i][j + 1]
|
||||||
|
+ self.__happiness[j] * (self.__N - j + i),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
def solve(self) -> int:
|
||||||
|
return max([self.__total[i][i] for i in range(self.__N)])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
N = int(input())
|
||||||
|
H = list(map(int, input().split()))
|
||||||
|
solver = HappyCow(N, H)
|
||||||
|
print(solver.solve())
|
||||||
40
zeta_python/completed/1823.py
Normal file
40
zeta_python/completed/1823.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
input = sys.stdin.readline
|
||||||
|
|
||||||
|
|
||||||
|
class HappyCow:
|
||||||
|
def __init__(self, N: int, H: list[int]):
|
||||||
|
self.__N: int = N
|
||||||
|
self.__happiness: list[int] = H
|
||||||
|
self.__total: list[int] = [[0] * (self.__N + 2) for _ in range(self.__N + 2)]
|
||||||
|
|
||||||
|
for i in range(1, self.__N + 1):
|
||||||
|
day = i
|
||||||
|
self.__total[i][self.__N] = (
|
||||||
|
self.__total[i - 1][self.__N] + day * self.__happiness[i - 1]
|
||||||
|
)
|
||||||
|
self.__total[0][self.__N - i] = (
|
||||||
|
self.__total[0][self.__N - i + 1] + day * self.__happiness[self.__N - i]
|
||||||
|
)
|
||||||
|
|
||||||
|
for i in range(1, self.__N):
|
||||||
|
for j in range(self.__N - 1, i - 1, -1):
|
||||||
|
self.__total[i][j] = max(
|
||||||
|
[
|
||||||
|
self.__total[i - 1][j]
|
||||||
|
+ self.__happiness[i - 1] * (self.__N - j + i),
|
||||||
|
self.__total[i][j + 1]
|
||||||
|
+ self.__happiness[j] * (self.__N - j + i),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
def solve(self) -> int:
|
||||||
|
return max([self.__total[i][i] for i in range(self.__N)])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
N = int(input())
|
||||||
|
H = [int(input()) for _ in range(N)]
|
||||||
|
solver = HappyCow(N, H)
|
||||||
|
print(solver.solve())
|
||||||
72
zeta_python/completed/2162.py
Normal file
72
zeta_python/completed/2162.py
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
import sys
|
||||||
|
from collections import Counter
|
||||||
|
|
||||||
|
input = sys.stdin.readline
|
||||||
|
|
||||||
|
|
||||||
|
def ccw(p1, p2, p3):
|
||||||
|
# fmt: off
|
||||||
|
s = (p1[0] * p2[1] + p2[0] * p3[1] + p3[0] * p1[1]) \
|
||||||
|
- (p1[1] * p2[0] + p2[1] * p3[0] + p3[1] * p1[0])
|
||||||
|
# fmt: on
|
||||||
|
if s > 0:
|
||||||
|
return 1
|
||||||
|
elif s == 0:
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
return -1
|
||||||
|
|
||||||
|
|
||||||
|
class LinesGroup:
|
||||||
|
def __init__(self, N: int, lines: list):
|
||||||
|
self.__lines = lines
|
||||||
|
self.__parents = [i for i in range(N)]
|
||||||
|
for i in range(N):
|
||||||
|
for j in range(i + 1, N):
|
||||||
|
if self.intersect(i, j):
|
||||||
|
self.merge(i, j)
|
||||||
|
self.__roots = [self.root(i) for i in range(N)]
|
||||||
|
self.__counters: Counter = Counter(self.__roots)
|
||||||
|
|
||||||
|
def intersect(self, a: int, b: int) -> bool:
|
||||||
|
a: tuple[int] = self.__lines[a]
|
||||||
|
b: tuple[int] = self.__lines[b]
|
||||||
|
p1, p2 = (a[0], a[1]), (a[2], a[3])
|
||||||
|
p3, p4 = (b[0], b[1]), (b[2], b[3])
|
||||||
|
p1p2 = ccw(p1, p2, p3) * ccw(p1, p2, p4)
|
||||||
|
p3p4 = ccw(p3, p4, p1) * ccw(p3, p4, p2)
|
||||||
|
if p1p2 == 0 and p3p4 == 0:
|
||||||
|
if p1 > p2:
|
||||||
|
p1, p2 = p2, p1
|
||||||
|
if p3 > p4:
|
||||||
|
p3, p4 = p4, p3
|
||||||
|
return p3 <= p2 and p1 <= p4
|
||||||
|
return p1p2 <= 0 and p3p4 <= 0
|
||||||
|
|
||||||
|
def merge(self, a, b):
|
||||||
|
rb, ra = self.root(b), self.root(a)
|
||||||
|
if ra < rb:
|
||||||
|
self.__parents[rb] = ra
|
||||||
|
else:
|
||||||
|
self.__parents[ra] = rb
|
||||||
|
|
||||||
|
def root(self, e) -> int:
|
||||||
|
node = e
|
||||||
|
while node != self.__parents[node]:
|
||||||
|
node = self.__parents[node]
|
||||||
|
return node
|
||||||
|
|
||||||
|
@property
|
||||||
|
def num_groups(self):
|
||||||
|
return len(self.__counters)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def num_max(self):
|
||||||
|
return self.__counters.most_common(1)[0][1]
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
N = int(input())
|
||||||
|
groups = LinesGroup(N, [tuple(map(int, input().split())) for _ in range(N)])
|
||||||
|
print(groups.num_groups)
|
||||||
|
print(groups.num_max)
|
||||||
9
zeta_python/completed/30802.py
Normal file
9
zeta_python/completed/30802.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import math
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
N = int(input())
|
||||||
|
S = list(map(int, input().split()))
|
||||||
|
T, P = map(int, input().split())
|
||||||
|
|
||||||
|
print(sum(math.ceil(s / T) for s in S))
|
||||||
|
print(N // P, N % P)
|
||||||
Reference in New Issue
Block a user