From: Skullheadx <94652084+Skullheadx@users.noreply.github.com> Date: Wed, 4 Jan 2023 04:37:00 +0000 (-0500) Subject: S4 not done X-Git-Url: http://git.skullheadx.com/index.js?a=commitdiff_plain;h=16fd322c7dd010e5104146290d570dcdd9ddca51;p=CCC.git S4 not done --- diff --git a/Main/C++/2022/S4.cpp b/Main/C++/2022/S4.cpp new file mode 100644 index 0000000..fa2faa0 --- /dev/null +++ b/Main/C++/2022/S4.cpp @@ -0,0 +1,89 @@ +#include +using namespace std; + +int main() +{ + int N, C; + cin >> N >>> C; + double r = C / (2 * pi); + vector temp, P; + int t; + for (int i = 0;i < N; i++) + { + cin >> t; + temp.push_back(t); // REMEMBER ITS starting from 0 now not 1 + P.push_back(to_coordinates(t)); + } + + int output = 0; + for subset in combinations(P.keys(), 3): + if is_good(subset): + output += 1; + + cout << output << endl; + return 0; +} +//from math import pi, cos, sin +//from itertools import permutations, combinations + + +bool in_triangle(double ax,double ay,double bx,double by,double cx,double cy) +{ + double px= r, py = r; + try: + w1 = (ax * (cy - ay) + (py - ay) * (cx - ax) - px * (cy - ay)) / ((by - ay) * (cx - ax) - (bx - ax) * (cy - ay)); + w2 = (py - ay - w1 * (by - ay)) / (cy - ay); + except: + return false; + + if (w1 >= 0 && w2 >= 0 && w1 + w2 <= 1): + return true; + return false; +} + +vector to_coordinates(int p) +{ + double angle = p / static_cast(C) * 2 * pi; + return {r * cos(angle) + r, r * sin(angle) + r}; +} + + + +bool is_opposite(int a,int b) +{ + if (abs(temp[a] - temp[b]) == C / 2): + return true; + return false; + +} + + +bool is_good(vector subset) +{ + t = {i: [] for i in subset} + for a, b, c in permutations(subset, 3): + t[a].append((a, b, c)) + + for i in subset: + + a1, b1, c1 = t[i][0] + ax1, ay1 = P[a1] + bx1, by1 = P[b1] + cx1, cy1 = P[c1] + a2, b2, c2 = t[i][1] + ax2, ay2 = P[a2] + bx2, by2 = P[b2] + cx2, cy2 = P[c2] + + if not (in_triangle(ax1, ay1, bx1, by1, cx1, cy1) or in_triangle(ax2, ay2, bx2, by2, cx2, cy2)): + return false; + + for a, b in combinations(subset, 2): + if is_opposite(a, b): + return false; + + return true; + +} + + diff --git a/Main/Python/2022/S4.py b/Main/Python/2022/S4.py index 6169efa..450a14c 100644 --- a/Main/Python/2022/S4.py +++ b/Main/Python/2022/S4.py @@ -1,5 +1,5 @@ from math import pi, cos, sin -from itertools import permutations +from itertools import permutations, combinations def in_triangle(ax, ay, bx, by, cx, cy): @@ -10,7 +10,7 @@ def in_triangle(ax, ay, bx, by, cx, cy): except: return False - if w1 > 0 and w2 > 0 and w1 + w2 < 1: + if w1 >= 0 and w2 >= 0 and w1 + w2 <= 1: return True return False @@ -24,40 +24,44 @@ def to_coordinates(p): return r * cos(angle) + r, r * sin(angle) + r -temp = {i + 1: int(val) for i, val in enumerate(input().split())} -P = {i: to_coordinates(temp[i]) for i in temp.keys()} - -seen = set() - -output = [] -for subset in permutations(P.keys(), 3): - a, b, c = subset - ax, ay = P[a] - bx, by = P[b] - cx, cy = P[c] - - if in_triangle(ax, ay, bx, by, cx, cy): - if subset not in seen: - output.append(subset) - for s in permutations(subset, 3): - seen.add(s) - - def is_opposite(a, b): if abs(temp[a] - temp[b]) == C / 2: return True return False -def is_good(i): - for a, b in permutations(i, 2): +def is_good(subset): + t = {i: [] for i in subset} + for a, b, c in permutations(subset, 3): + t[a].append((a, b, c)) + + for i in subset: + + a1, b1, c1 = t[i][0] + ax1, ay1 = P[a1] + bx1, by1 = P[b1] + cx1, cy1 = P[c1] + a2, b2, c2 = t[i][1] + ax2, ay2 = P[a2] + bx2, by2 = P[b2] + cx2, cy2 = P[c2] + + if not (in_triangle(ax1, ay1, bx1, by1, cx1, cy1) or in_triangle(ax2, ay2, bx2, by2, cx2, cy2)): + return False + + for a, b in combinations(subset, 2): if is_opposite(a, b): return False + return True -new_output = [] -for i in output: - if is_good(i): - new_output.append(i) -print(len(new_output)) +temp = {i + 1: int(val) for i, val in enumerate(input().split())} +P = {i: to_coordinates(temp[i]) for i in temp.keys()} + +output = 0 +for subset in combinations(P.keys(), 3): + if is_good(subset): + output += 1 + +print(output)