From 7bf260628ae8c3cbb850e56cb12b95e355f366be Mon Sep 17 00:00:00 2001 From: augustin64 Date: Wed, 27 Mar 2024 14:51:39 +0100 Subject: [PATCH] Add 25-03-2024 --- 25-03-24/a.py | 14 ++++++++++++++ 25-03-24/b.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 25-03-24/a.py create mode 100644 25-03-24/b.py diff --git a/25-03-24/a.py b/25-03-24/a.py new file mode 100644 index 0000000..e648d6e --- /dev/null +++ b/25-03-24/a.py @@ -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()) \ No newline at end of file diff --git a/25-03-24/b.py b/25-03-24/b.py new file mode 100644 index 0000000..51c8b1b --- /dev/null +++ b/25-03-24/b.py @@ -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)