From 7b7e92fecedc078947484b838e9aa2007f809484 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Sat, 7 Mar 2026 21:44:35 +0900 Subject: [PATCH] baekjoon 20260307 --- code_study/Baekjoon/python/16946.py | 69 +++++++++++++++++++++++++++++ code_study/Baekjoon/python/2783.py | 6 +++ 2 files changed, 75 insertions(+) create mode 100644 code_study/Baekjoon/python/16946.py create mode 100644 code_study/Baekjoon/python/2783.py diff --git a/code_study/Baekjoon/python/16946.py b/code_study/Baekjoon/python/16946.py new file mode 100644 index 0000000..759e37e --- /dev/null +++ b/code_study/Baekjoon/python/16946.py @@ -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))) \ No newline at end of file diff --git a/code_study/Baekjoon/python/2783.py b/code_study/Baekjoon/python/2783.py new file mode 100644 index 0000000..80b348f --- /dev/null +++ b/code_study/Baekjoon/python/2783.py @@ -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}') \ No newline at end of file