Skip to content

Commit

Permalink
Merge pull request #132 from IJS1016/main
Browse files Browse the repository at this point in the history
[23.3.4W]Python PS
  • Loading branch information
IJS1016 authored Apr 1, 2024
2 parents 654f905 + 96fcb3f commit 43811b1
Show file tree
Hide file tree
Showing 5 changed files with 269 additions and 0 deletions.
31 changes: 31 additions & 0 deletions 정선/python/baekjoon/13335_트럭.py
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions 정선/python/baekjoon/13458_시험감독.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions 정선/python/baekjoon/14500_테트리미노.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://www.acmicpc.net/problem/14500

104 changes: 104 additions & 0 deletions 정선/python/baekjoon/14502_연구소.py
Original file line number Diff line number Diff line change
@@ -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)
115 changes: 115 additions & 0 deletions 정선/python/programmers/퍼즐조각맞추기.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 43811b1

Please sign in to comment.