# n, m, k = map(int, input().split())# ls = []# for i in range(m):# v = []# for j in range(n):# v.append(0)# ls.append(v)# for i in range(k):# x1, y1, x2, y2 = map(int, input().split())# for j in range(x1, x2):# for k in range(y1, y2):# ls[j][k] = 1# lsp = []# for i in range(m+2):# v = []# for j in range(n+2):# v.append(0)# lsp.append(v)#### for i in range(m+2):# for j in range(n+2):# if i == 0 or i == m+1 or j == 0 or j == n+1:# lsp[i][j] = 1# else:# lsp[i][j] = ls[i-1][j-1]## ls = lsp# for i in range(m+2):# for j in range(n+2):# print(ls[i][j], end=' ')# print()## cnt = []## def find(x, y, z):# global m,n,ls, cnt# if ls[x][y] == 0:# ls[x][y] = 1# cnt[z] += 1# find(x + 1, y, z)# find(x, y + 1, z)# find(x - 1, y, z)# find(x, y - 1, z)### c = 0### for i in range(m+2):# for j in range(n+2):# if ls[i][j] == 0:# cnt.append(0)# find(i, j, c)# c += 1## print(c)# lss = []# for i in range(c):# lss.append(cnt[i])## lss.sort()# for i in range(c):# print(lss[i], end=' ')# import sys# limit_number = 1500000# sys.setrecursionlimit(limit_number)## n, m, k = map(int, input().split())# ls = []# r = 0# for i in range(m):# v = []# for j in range(n):# v.append(-1)# ls.append(v)# for i in range(k):# x1, y1, x2, y2 = map(int, input().split())# if i == 0:# r = x1# for j in range(x1, x2):# for k in range(y1, y2):# ls[j][k] = -2# lsp = []# for i in range(m+2):# v = []# for j in range(n+2):# v.append(-1)# lsp.append(v)#### for i in range(m+2):# for j in range(n+2):# if i == 0 or i == m+1 or j == 0 or j == n+1:# lsp[i][j] = -2# else:# lsp[i][j] = ls[i-1][j-1]## ls = lsp### cnt = []## def find(x, y, z):# global m,n,ls, cnt# if ls[x][y] == -1:# ls[x][y] = cnt[z]# cnt[z] += 1# find(x + 1, y, z)# find(x, y + 1, z)# find(x - 1, y, z)# find(x, y - 1, z)#### c = 0### for i in range(m+2):# for j in range(n+2):# if ls[i][j] == -1:# cnt.append(0)# find(i, j, c)# c += 1## # for i in range(m+2):# # for j in range(n+2):# # print(ls[i][j], end=' ')# # print()## print(c)# lss = []# for i in range(c):# lss.append(cnt[i])## lss.sort()# for i in range(c):# print(lss[i], end=' ')class solve: def __init__(self): self.box = [] self.m, self.n = map(int, input().split()) for i in range(self.n): s = input().split() self.box.append(s) for i in range(self.n): for j in range(self.m): self.box[i][j] = int(self.box[i][j]) self.queue = [] for i in range(self.m*self.n+1): self.queue.append([-1, -1, -1]) self.start = 0 self.end = 0 self.to_be_end = True for i in range(self.n): for j in range(self.m): if self.box[i][j] == 1: self.queue[self.end][0] = i self.queue[self.end][1] = j self.queue[self.end][2] = -1 self.end += 1 self.box[i][j] = 0 if self.end == 0: self.to_be_end = False def find(self): x = self.queue[self.start][0] y = self.queue[self.start][1] z = self.queue[self.start][2] self.box[x][y] = 1 print(self.box) self.start += 1 if 0 <= x + 1 < self.n and 0 <= y < self.m and self.box[x + 1][y] == 0: self.queue[self.end][0] = x + 1 self.queue[self.end][1] = y self.queue[self.end][2] = z + 1 self.end += 1 if 0 <= x < self.n and 0 <= y + 1 < self.m and self.box[x][y + 1] == 0: self.queue[self.end][0] = x self.queue[self.end][1] = y + 1 self.queue[self.end][2] = z + 1 self.end += 1 if 0 <= x - 1 < self.n and 0 <= y < self.m and self.box[x - 1][y] == 0: self.queue[self.end][0] = x - 1 self.queue[self.end][1] = y self.queue[self.end][2] = z + 1 self.end += 1 if 0 <= x < self.n and 0 <= y - 1 < self.m and self.box[x][y - 1] == 0: self.queue[self.end][0] = x self.queue[self.end][1] = y - 1 self.queue[self.end][2] = z + 1 self.end += 1u = solve()while True: u.find() if u.to_be_end == True: print(u.queue) break
top of page
실제 작동 상태를 확인하려면 라이브 사이트로 이동하세요.
24.01.28.
24.01.28.
댓글 0개
좋아요
댓글(0)
bottom of page