Created
November 10, 2017 15:28
-
-
Save Saren-Arterius/a24f94ca43c26a1cb2d0f2d3fc4f1f45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
if __name__ == '__main__': | |
points = set() | |
for _ in range(int(input())): | |
x, y = map(int, input().split()) | |
points.add((x, y)) | |
rects = [] | |
for lt in points: | |
for rb in points: | |
if rb[0] <= lt[0] or rb[1] >= lt[1]: | |
continue | |
rt, lb = (rb[0], lt[1]), (lt[0], rb[1]) | |
if rt in points and lb in points: | |
rects.append((lt, rb, rt, lb)) | |
print(len(rects)) | |
rect_size = lambda r: (r[1][0] - r[0][0]) * (r[0][1] - r[1][1]) | |
rects.sort(key=lambda rect: rect_size(rect), reverse=True) | |
remove_rects = set() | |
for big_rect in rects: | |
if big_rect in remove_rects: | |
continue | |
for sub_rect in rects: | |
if sub_rect == big_rect: | |
continue | |
if big_rect[0][0] < sub_rect[1][0] and big_rect[1][0] > sub_rect[0][0] and big_rect[0][1] > sub_rect[1][1] and big_rect[1][1] < sub_rect[0][1]: | |
remove_rects.add(sub_rect) | |
rects = set(rects) | |
rects -= remove_rects | |
print('== Basic ^ | v Advanced ==') | |
print(len(rects)) | |
for rect in rects: | |
print(rect_size(rect)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment