baekjoon 20260307
This commit is contained in:
parent
8a019ee4f5
commit
7b7e92fece
69
code_study/Baekjoon/python/16946.py
Normal file
69
code_study/Baekjoon/python/16946.py
Normal file
@ -0,0 +1,69 @@
|
||||
from collections import deque
|
||||
import sys
|
||||
input = sys.stdin.readline
|
||||
|
||||
N, M = map(int, input().split())
|
||||
mapp = [input().rstrip() for _ in range(N)]
|
||||
res = [[0]*M for _ in range(N)]
|
||||
|
||||
area_num = [[-1]*M for _ in range(N)]
|
||||
area_size = []
|
||||
|
||||
def BFS(group, x, y) :
|
||||
qu = deque()
|
||||
qu.append((x, y))
|
||||
area_num[y][x] = group
|
||||
cnt = 1
|
||||
|
||||
while qu :
|
||||
cx, cy = qu.popleft()
|
||||
|
||||
for dx, dy in zip([1,-1,0,0], [0,0,1,-1]) :
|
||||
nx, ny = cx + dx, cy + dy
|
||||
|
||||
if 0 <= nx < M and 0 <= ny < N and mapp[ny][nx] != "1" and area_num[ny][nx] == -1 :
|
||||
qu.append((nx, ny))
|
||||
cnt += 1
|
||||
area_num[ny][nx] = group
|
||||
|
||||
area_size[group] = cnt
|
||||
|
||||
group_num = 0
|
||||
wall = []
|
||||
for y in range(N) :
|
||||
for x in range(M) :
|
||||
if mapp[y][x] == "1" :
|
||||
wall.append((x, y))
|
||||
elif area_num[y][x] == -1 :
|
||||
area_size.append(0)
|
||||
BFS(group_num, x, y)
|
||||
group_num += 1
|
||||
|
||||
for x, y in wall :
|
||||
cnt = 1
|
||||
neighbor = []
|
||||
|
||||
for dx, dy in zip([1,-1,0,0], [0,0,1,-1]) :
|
||||
nx, ny = x + dx, y + dy
|
||||
|
||||
if 0 <= nx < M and 0 <= ny < N and area_num[ny][nx] != -1 :
|
||||
area = area_num[ny][nx]
|
||||
|
||||
if len(neighbor) == 0 :
|
||||
cnt += area_size[area]
|
||||
neighbor.append(area)
|
||||
else :
|
||||
dupli_check = True
|
||||
|
||||
for n in neighbor :
|
||||
if n == area :
|
||||
dupli_check = False
|
||||
|
||||
if dupli_check :
|
||||
cnt += area_size[area]
|
||||
neighbor.append(area)
|
||||
|
||||
res[y][x] = cnt % 10
|
||||
|
||||
for row in res :
|
||||
print("".join(map(str, row)))
|
||||
6
code_study/Baekjoon/python/2783.py
Normal file
6
code_study/Baekjoon/python/2783.py
Normal file
@ -0,0 +1,6 @@
|
||||
minCostPerGram = (lambda x : x[0] / x[1])(list(map(int, input().split())))
|
||||
for _ in range(int(input())) :
|
||||
x, y = map(int, input().split())
|
||||
minCostPerGram = min(minCostPerGram, x/y)
|
||||
|
||||
print(f'{round(minCostPerGram * 1000, 2):.2f}')
|
||||
Loading…
x
Reference in New Issue
Block a user