Last active
September 12, 2022 08:54
-
-
Save AvailableAmphibian/a07b1c09ac397346a223ab9f64191d7a to your computer and use it in GitHub Desktop.
This file contains 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
class Rectangle: | |
def __init__(self, l, h): | |
self.bot = 0 | |
self.top = h | |
self.left = 0 | |
self.right = l | |
def get_area(self): | |
x_axis = self.right - self.left | |
y_axis = self.top - self.bot | |
return x_axis * y_axis | |
def calc_left(self, point): | |
rect = None | |
(x, _y) = point | |
if self.right < x: | |
rect = create_rect(self.bot, self.top, self.right, x) | |
else: | |
rect = create_rect(self.bot, self.top, self.left, x) | |
return rect | |
def calc_below(self, point): | |
(_x, y) = point | |
if y > self.top: | |
return self | |
return create_rect(self.bot, y, self.left, self.right) | |
def calc_right(self, point): | |
(x, _y) = point | |
return create_rect(self.bot, self.top, x, self.right) | |
def __lt__(self, other): | |
return self.get_area() < other.get_area() | |
def create_rect(bot, top, left, right): | |
rect = Rectangle(right, top) | |
rect.bot = bot | |
rect.left = left | |
return rect | |
def calc_for_point(point, left_rect, below_rect, right_rect): | |
lb = left_rect.calc_below(point) | |
lr = left_rect.calc_right(point) | |
bl = below_rect.calc_left(point) | |
bb = below_rect.calc_below(point) | |
br = below_rect.calc_right(point) | |
rl = right_rect.calc_left(point) | |
rb = right_rect.calc_below(point) | |
rr = right_rect.calc_right(point) | |
left = max(left_rect, bl, rl) | |
below = max(lb, bb, rb) | |
right = max(lr, br, rr) | |
return left, below, right | |
space_dimension = input() | |
space_dimension_arr = space_dimension.split(" ") | |
l = int(space_dimension_arr[0]) | |
h = int(space_dimension_arr[1]) | |
n = int(input()) | |
if n == 0: | |
print(Rectangle(l, h).get_area()) | |
else: | |
bot = 0 | |
left = 0 | |
top = h | |
right = l | |
points_input = input().split(" ") | |
first_point = (int(points_input[0]), int(points_input[1])) | |
points = [] | |
for i in range(0, n-1): | |
points_input = input().split(" ") | |
points.append((int(points_input[0]), int(points_input[1]))) | |
left_rect = Rectangle(0, h) | |
below_rect = Rectangle(l, h) | |
right_rect = Rectangle(l, h) | |
(left_rect, below_rect, right_rect) = calc_for_point(first_point, left_rect, below_rect, right_rect) | |
for point in points: | |
(left_rect, below_rect, right_rect) = calc_for_point(point, left_rect, below_rect, right_rect) | |
largest = max(left_rect, below_rect, right_rect) | |
print(largest.get_area()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment