Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
from collections import Counter
from itertools import combinations
def HowManySquares(xx, yy):
"""
:param xx: отсортированые x-координаты вертикалей
:param yy: отсортированые y-координаты горизонталей
"""
ww = Counter(b - a for a, b in combinations(xx, 2))
hh = Counter(b - a for a, b in combinations(yy, 2))
return sum(c * hh[w] for w, c in ww.items())
print(HowManySquares([0, 2, 3, 4, 5, 6], [0, 2, 3, 4, 6])) # 31
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question