Add 25-03-2024

This commit is contained in:
augustin64 2024-03-27 14:51:39 +01:00
parent 3fc540bebe
commit 7bf260628a
2 changed files with 50 additions and 0 deletions

14
25-03-24/a.py Normal file
View File

@ -0,0 +1,14 @@
def main():
w, d, h = [int(i) for i in input().split()]
a, b, f, g = [int(i) for i in input().split()]
return h+min([
abs(f-a)+b+g,
abs(f-a)+(d-b)+(d-g),
abs(b-g)+f+a,
abs(b-g)+(w-f)+(w-a)
])
for _ in range(int(input())):
print(main())

36
25-03-24/b.py Normal file
View File

@ -0,0 +1,36 @@
n = int(input())
points = [[int(i) for i in input().split()] for _ in range(n+1)]
left = [
((-1, 0), (0, -1)),
((0, -1), (1, 0)),
((1, 0), (0, 1)),
((0, 1), (-1, 0))
]
right = [(p2, p1) for p1, p2 in left]
dangerous_turns = 0
def signe(n):
if n == 0: return 0
if n > 0: return 1
return -1
def normalized(x1, y1, x2, y2, x3, y3):
return ((signe(x2-x1), signe(y2-y1)), (signe(x3-x2), signe(y3-y2)))
def danger(initial_turn, p1, p2, p3):
norm = normalized(*p1, *p2, *p3)
if (initial_turn and norm in left) or (not initial_turn and norm in right):
return False
return True
initial_turn = normalized(*points[-2], *points[0], *points[1]) in left
#print("initial:", normalized(*points[-2], *points[0], *points[1]), initial_turn)
for i in range(1, n):
if danger(initial_turn, points[i-1], points[i], points[i+1]):
dangerous_turns += 1
print(dangerous_turns)