From c416b00ea7ba71dce8688772d3a598f9868b5113 Mon Sep 17 00:00:00 2001 From: IJS1016 Date: Sat, 30 Mar 2024 22:33:17 +0900 Subject: [PATCH 1/2] [23.3.4W]Python PS --- .../13335_\355\212\270\353\237\255.py" | 31 ++++++ ...34\355\227\230\352\260\220\353\217\205.py" | 17 +++ ...70\353\246\254\353\257\270\353\205\270.py" | 2 + ...2_\354\227\260\352\265\254\354\206\214.py" | 104 ++++++++++++++++++ 4 files changed, 154 insertions(+) create mode 100644 "\354\240\225\354\204\240/python/baekjoon/13335_\355\212\270\353\237\255.py" create mode 100644 "\354\240\225\354\204\240/python/baekjoon/13458_\354\213\234\355\227\230\352\260\220\353\217\205.py" create mode 100644 "\354\240\225\354\204\240/python/baekjoon/14500_\355\205\214\355\212\270\353\246\254\353\257\270\353\205\270.py" create mode 100644 "\354\240\225\354\204\240/python/baekjoon/14502_\354\227\260\352\265\254\354\206\214.py" diff --git "a/\354\240\225\354\204\240/python/baekjoon/13335_\355\212\270\353\237\255.py" "b/\354\240\225\354\204\240/python/baekjoon/13335_\355\212\270\353\237\255.py" new file mode 100644 index 0000000..83d6f7b --- /dev/null +++ "b/\354\240\225\354\204\240/python/baekjoon/13335_\355\212\270\353\237\255.py" @@ -0,0 +1,31 @@ +""" +4 2 10 +7 4 5 6 +""" + +N, W, L = list(map(int, input().split(" "))) +trucks = list(map(int, input().split(" "))) + +road = [0] * W + +idx = 0 +now_w = 0 +time = 0 + +while idx < N : + now_w -= road.pop(0) + + if now_w + trucks[idx] <= L : + road.append(trucks[idx]) + now_w += trucks[idx] + idx += 1 + else : + road.append(0) + + time += 1 + + # print(now_w) + # print(" ".join(map(str, road))) + # input() + +print(time + W) \ No newline at end of file diff --git "a/\354\240\225\354\204\240/python/baekjoon/13458_\354\213\234\355\227\230\352\260\220\353\217\205.py" "b/\354\240\225\354\204\240/python/baekjoon/13458_\354\213\234\355\227\230\352\260\220\353\217\205.py" new file mode 100644 index 0000000..7f0db0f --- /dev/null +++ "b/\354\240\225\354\204\240/python/baekjoon/13458_\354\213\234\355\227\230\352\260\220\353\217\205.py" @@ -0,0 +1,17 @@ +# 마이너스 시 나눗셈 되면 마이너스 나오는 것 주의하기 +import math + +N = input() +A = list(map(int, input().split())) +B, C = map(int, input().split()) + +result = 0 + +for a in A : + # print(math.ceil((a - B) / C) + 1) + if (a - B) >= 0 : + result += math.ceil((a - B) / C) + 1 + else : + result += 1 + +print(result) \ No newline at end of file diff --git "a/\354\240\225\354\204\240/python/baekjoon/14500_\355\205\214\355\212\270\353\246\254\353\257\270\353\205\270.py" "b/\354\240\225\354\204\240/python/baekjoon/14500_\355\205\214\355\212\270\353\246\254\353\257\270\353\205\270.py" new file mode 100644 index 0000000..2bd46a8 --- /dev/null +++ "b/\354\240\225\354\204\240/python/baekjoon/14500_\355\205\214\355\212\270\353\246\254\353\257\270\353\205\270.py" @@ -0,0 +1,2 @@ +# https://www.acmicpc.net/problem/14500 + diff --git "a/\354\240\225\354\204\240/python/baekjoon/14502_\354\227\260\352\265\254\354\206\214.py" "b/\354\240\225\354\204\240/python/baekjoon/14502_\354\227\260\352\265\254\354\206\214.py" new file mode 100644 index 0000000..4fda7b6 --- /dev/null +++ "b/\354\240\225\354\204\240/python/baekjoon/14502_\354\227\260\352\265\254\354\206\214.py" @@ -0,0 +1,104 @@ +import copy +from itertools import combinations + +DBG = False + +# 굳이 필요 없는 코드 -> 벽 주변이 아닌 경우에도 확인이 필요 +# def find_wall_candidate(mmap) : +# mmap = copy.deepcopy(mmap) +# directions = [[-1, 0], [1, 0], [0, -1], [0, 1], [-1, -1], [1, -1], [-1, 1], [1, 1]] # 상하좌우 대각선 + +# wall_loc_candidates = [] + +# for wall in wall_loc : +# for direction in directions : +# wc_y = wall[0] + direction[0] +# wc_x = wall[1] + direction[1] + +# if 0 <= wc_y < N and 0 <= wc_x < M and mmap[wc_y][wc_x] == 0 : +# wall_loc_candidates.append([wc_y, wc_x]) +# mmap[wc_y][wc_x] = 1 + +# # 벽에 붙어서 제외할 수 있는 케이스 추가 +# for wc_y in [0, 1, -1, -2] : +# for wc_x in range(M) : +# if mmap[wc_y][wc_x] == 0 : +# wall_loc_candidates.append([wc_y, wc_x]) +# mmap[wc_y][wc_x] = 1 + +# for wc_y in range(N) : +# for wc_x in [0, 1, -1, -2] : +# if mmap[wc_y][wc_x] == 0 : +# wall_loc_candidates.append([wc_y, wc_x]) +# mmap[wc_y][wc_x] = 1 + +# return wall_loc_candidates + +def print_mmap(mmap) : + for line in mmap : + print(" ".join(map(str, line))) + +def find_save_space(mmap, wall_candidate, virus_loc) : + mmap = copy.deepcopy(mmap) + virus_loc = copy.deepcopy(virus_loc) + + for wy, wx in wall_candidate : + mmap[wy][wx] = 3 + + save_space_size = 0 + + while len(virus_loc) > 0 : + vy, vx = virus_loc.pop(0) + for dy, dx in [[-1, 0], [1, 0], [0, -1], [0, 1]] : + ny, nx = vy+dy, vx+dx + if 0 <= ny < N and 0 <= nx < M and mmap[ny][nx] == 0 : + mmap[ny][nx] = 2 + virus_loc.append([ny, nx]) + + for line in mmap : + save_space_size += line.count(0) + + if DBG : + print("##################") + print(wall_candidate) + print_mmap(mmap) + + return save_space_size + +N, M = map(int, input().split()) # 세로, 가로 + +mmap = [] +wall_loc = [] # location of wall +virus_loc = [] +empty_loc = [] + +for y in range(N) : + line = list(map(int, input().split())) + + for x, v in enumerate(line) : + if v == 0 : + empty_loc.append([y, x]) + if v == 1 : + wall_loc.append([y, x]) + if v == 2 : + virus_loc.append([y, x]) + + mmap.append(line) + +# wall_loc_candidates = find_wall_candidate(mmap) +# wall_candidates = combinations(wall_loc_candidates, 3) + +wall_candidates = combinations(empty_loc, 3) + +max_save_space_size = 0 +for wall_candidate in wall_candidates : + save_space_size = find_save_space(mmap, wall_candidate, virus_loc) + + if max_save_space_size < save_space_size : + max_save_space_size = save_space_size + + if DBG : + print(save_space_size) + input() + +print(max_save_space_size) \ No newline at end of file From 96fcb3f1d2713ccdb91507a66f2e148e0f4469b4 Mon Sep 17 00:00:00 2001 From: IJS1016 Date: Sat, 30 Mar 2024 22:34:31 +0900 Subject: [PATCH 2/2] [23.3.4W]Python PS --- ...01\353\247\236\354\266\224\352\270\260.py" | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 "\354\240\225\354\204\240/python/programmers/\355\215\274\354\246\220\354\241\260\352\260\201\353\247\236\354\266\224\352\270\260.py" diff --git "a/\354\240\225\354\204\240/python/programmers/\355\215\274\354\246\220\354\241\260\352\260\201\353\247\236\354\266\224\352\270\260.py" "b/\354\240\225\354\204\240/python/programmers/\355\215\274\354\246\220\354\241\260\352\260\201\353\247\236\354\266\224\352\270\260.py" new file mode 100644 index 0000000..1f0a98a --- /dev/null +++ "b/\354\240\225\354\204\240/python/programmers/\355\215\274\354\246\220\354\241\260\352\260\201\353\247\236\354\266\224\352\270\260.py" @@ -0,0 +1,115 @@ +# https://school.programmers.co.kr/learn/courses/30/lessons/84021 +import copy +# 정렬하거나, 맞춰주는건 영향이 없으면 최종단에서 처리 +# list min 사용법 정확히 알기, list 모양은 변하지 않음, 앞에서 원소의 최소 기준으로 작은 것 return +# for문 첫단, 끝단 처리 잘 정리해서 코드 짜기 +# 2차원 리스트 정렬, part.sort(key=lambda x : (x[0], x[1])) -> 그럼 굳이 리스트 정렬 안 쓰고, + +def rotate_part(part) : + length = max(max(part)) + + rotated_part = copy.deepcopy(part) + rotated_parts = [] + + for i in range(4) : + rotated_part = [[p[1], length - p[0] - 1] for p in rotated_part] + rotated_parts.append(rotated_part) + return rotated_parts + +def abs_list(list1, list2) : + return abs(list1[0] - list2[0]) + abs(list1[1] - list2[1]) + +def compare_part(part1, part2) : + part1 = sort_n_shift_part(part1) + part2 = sort_n_shift_part(part2) + + result = 0 + for idx in range(len(part1)) : + result += abs_list(part1[idx], part2[idx]) + + return True if result == 0 else False + +def compare_part_with_rotate(part1, part2): + rotated_parts2 = rotate_part(part2) + for r_part2 in rotated_parts2 : + if compare_part(part1, r_part2) : + return True + return False + +def get_match_size(empty_parts, puzzle_parts) : + match_size = 0 + matched = [False] * len(empty_parts) + for p_part in puzzle_parts : + for idx, e_part in enumerate(empty_parts) : + if not matched[idx] and len(p_part) == len(e_part) : + # print(p_part, e_part) + if compare_part_with_rotate(p_part, e_part) : + # print(compare_part_with_rotate(p_part, e_part)) + matched[idx] = True + match_size += len(p_part) + break + return match_size + + +def sort_n_shift_part(part) : + # 2차원 정렬(외우기), https://kingofbackend.tistory.com/98 + part.sort(key=lambda x : (x[0], x[1])) + min_0, min_1 = 50, 50 + for p_0, p_1 in part : + if min_0 > p_0 : + min_0 = p_0 + if min_1 > p_1 : + min_1 = p_1 + + for element in part : + element[0] = element[0]-min_0 + element[1] = element[1]-min_1 + + return part + +def find_parts(board, value) : # empty : 0, table_part : 1 + locs = [] + # 빈 공간 모두 찾기 + for y_idx, line in enumerate(board) : + for x_idx, v in enumerate(line) : + if v == value : + locs.append([y_idx, x_idx]) + + # 이어진 것끼리 합쳐주기 + visited = [False] * len(locs) + visited[0] = True + queue = [locs[0]] + + tmp_part = [] + result_parts = [] + + while (False in visited) or len(queue) != 0 : + loc = queue.pop(0) + tmp_part.append(loc) + + for idx, el in enumerate(locs) : + if visited[idx] : + continue + if abs_list(el, loc) == 1 : + queue.append(el) + visited[idx] = True + + + if len(queue) == 0 : + result_parts.append(tmp_part) + tmp_part = [] + try : + v_idx = visited.index(False) + queue = [locs[v_idx]] # vistied False + visited[v_idx] = True + except : + queue = [] # vistied False + + return result_parts + + +def solution(game_board, table): + empty_parts = find_parts(game_board, 0) + puzzle_parts = find_parts(table, 1) + + return get_match_size(empty_parts, puzzle_parts) \ No newline at end of file