• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Oct 20th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. counted = {}
2.
3.
4. def scalar(v1, v2):
5.     return v1[0] * v2[0] + v1[1] * v2[1]
6.
7.
8. def scalar_product(a, b, c):
9.     # a, b, c - координаты точек в формате (x, y)
10.     # вычислю координаты векторов
11.     # вектор a -> b
12.     k1 = tuple(sorted([coord.index(a), coord.index(b)]))
13.     if k1 in counted:
14.         Va_b = counted[k1]
15.     else:
16.         Va_b = [b[0] - a[0], b[1] - a[1]]
17.         counted[k1] = Va_b
18.     # вектор b -> c
19.
20.     k1 = tuple(sorted([coord.index(c), coord.index(b)]))
21.     if k1 in counted:
22.         Vb_c = counted[k1]
23.     else:
24.         Vb_c = [c[0] - b[0], c[1] - b[1]]
25.         counted[k1] = Vb_c
26.
27.     # вектор c -> a
28.     k1 = tuple(sorted([coord.index(a), coord.index(c)]))
29.     if tuple(k1) in counted:
30.         Vc_a = counted[tuple(k1)]
31.     else:
32.         Vc_a = [a[0] - c[0], a[1] - c[1]]
33.         counted[tuple(k1)] = Vc_a
34.
35.     return scalar(Va_b, Vb_c) * scalar(Va_b, Vc_a) * scalar(Vb_c, Vc_a) == 0
36.
37.
38. n = int(input())
39. coord = []
40. for i in range(n):
41.     coord.append(list(map(int, input().split())))
42.
43. ans = 0
44. for i in range(n):
45.     for j in range(i + 1, n):
46.         for k in range(j + 1, n):
47.             if scalar_product(coord[i], coord[j], coord[k]):
48.                 ans += 1
49.
50. print(ans)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top