Good evening. It is an irregular project that started suddenly. The plan is to just post the problem that I wrote in the middle of the night. I am sleepy.
#1 Problem
** Thoughts ** Since the constraints are small, I prepared a W * H list and actually performed the operation. Element 1 is the white square and 0 is the black square. There are 4 ways to operate, so press if
w, h, n = map(int,input().split())
xy = [list(map(int,input().split())) for _ in range(n)]
def view(now): #This function was written to visualize whether the processing is done well, so you can delete it.
    s = ''
    now = list(reversed(now))
    for i in range(h):
        for j in range(w):
            s += str(now[i][j])
        else:
            s += '\n'
    return s
mapp = [[1]*(w)] * (h) #Original figure
for i in range(n):
    if xy[i][2] == 1 or xy[i][2] == 2:
        for j in range(h):
            if xy[i][2] == 1:
                mapp[j][:xy[i][0]] = [0]*xy[i][0]
            elif xy[i][2] == 2:
                mapp[j][xy[i][0]:] = [0]*(w-xy[i][0])
    elif xy[i][2] == 3:
        for s in range(xy[i][1]):
            mapp[s] = [0] * w
    elif xy[i][2] == 4:
        for s in range(xy[i][1],h):
            mapp[s] = [0] * w
    #print(view(mapp))
ans = 0
for i in range(h):
    ans += mapp[i].count(1)
print(ans)
sleepy. And don't solve this problem at night. good night.
Recommended Posts