Add 25-03-2024
This commit is contained in:
parent
3fc540bebe
commit
7bf260628a
14
25-03-24/a.py
Normal file
14
25-03-24/a.py
Normal 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
36
25-03-24/b.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user