uva 10703 - Free spots Solution in Python
while True:
w, h, n = [int(x) for x in input().strip().split()]
if w == 0 and h == 0 and n == 0:
break
ls = []
for i in range(h):
ls.insert(i, [0] * w)
result = w * h
for i in range(n):
x1, y1, x2, y2 = [int(x) for x in input().strip().split()]
if x1 > x2:
x1, x2 = x2, x1
if y1 > y2:
y1, y2 = y2, y1
x1 -= 1
y1 -= 1
for j in range(y1, y2):
for k in range(x1, x2):
if ls[j][k] == 0:
result -= 1
ls[j][k] = 1
if result == 0:
print("There is no empty spots.")
elif result == 1:
print("There is one empty spot.")
else:
print(f"There are {result} empty spots.")
input()
Comments
Post a Comment