Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[23-10-08] kyuhyun #328

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Baekjoon - 문제풀이/불!/kyuhyun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from collections import deque

n, m = map(int, input().split())
map = []
ans = 'IMPOSSIBLE'

for i in range(n):
map.append(list(input()))
if 'J' in map[i]:
q = deque([(0, i, map[i].index('J'))])

for i in range(n):
for j in range(m):
if map[i][j] == 'F':
q.append((-1, i, j))

dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]

while q:
time, x, y = q.popleft()

# 지훈이 탈출
if time > -1 and map[x][y] != 'F':
if x == 0 or y == 0 or x == n - 1 or y == m - 1:
ans = time + 1
break

for i in range(4):
nx = x + dx[i]
ny = y + dy[i]

if 0 <= nx < n and 0 <= ny < m and map[nx][ny] != '#':
# 지훈이 이동
if time > -1 and map[nx][ny] == '.':
map[nx][ny] = '*'
q.append((time + 1, nx, ny))
# 불 퍼뜨리기
elif time == -1 and map[nx][ny] != 'F':
map[nx][ny] = 'F'
q.append((-1, nx, ny))

print(ans)
29 changes: 29 additions & 0 deletions Baekjoon - 문제풀이/스타트와 링크/kyuhyun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from itertools import combinations, permutations
n = int(input())

sal = []
people = []
result = 99999

for i in range(n):
sal.append(list(map(int, input().split(" "))))
people.append(i)

for team_s in combinations(people, n//2):

team_l = []
total_stark = 0
total_link = 0

for i in range(n):
if i not in team_s:
team_l.append(i)

for power_s in permutations(team_s, 2):
total_stark += sal[power_s[0]][power_s[1]]

for power_l in permutations(team_l, 2):
total_link += sal[power_l[0]][power_l[1]]

result = min(result, abs(total_stark - total_link))
print(result)
32 changes: 32 additions & 0 deletions Baekjoon - 문제풀이/치킨 배달/kyuhyun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from itertools import combinations

n, m = map(int, input().split(" "))

city = []

for _ in range(n) :
tmp = list(map(int, input().split(" ")))
city.append(tmp)

res = 99999
home = []
chick = []

for i in range(n):
for j in range(n):
if city[i][j] == 1:
home.append([i, j])
continue
if city[i][j] == 2:
chick.append([i, j])

for c in combinations(chick, m):
total_chick = 0
for h in home:
len_chick = 999
for i in range(m):
len_chick = min(len_chick, abs(c[i][0]-h[0]) + abs(c[i][1]-h[1]))
total_chick += len_chick
res = min(total_chick, res)
print(res)

46 changes: 46 additions & 0 deletions Baekjoon - 문제풀이/토마토/kyuhyun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from collections import deque
m, n = map(int, input().split(" "))

tomato = []
q = deque()
flag = 0

for _ in range(n) :
tmp = list(map(int, input().split(" ")))
tomato.append(tmp)

dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]

def bfs():
global res
while q:
time, y, x = q.popleft()
res = time

for i in range(4):
nx = x + dx[i]
ny = y + dy[i]

if nx < 0 or nx >= m or ny < 0 or ny >= n:
continue
if tomato[ny][nx] == 1 or tomato[ny][nx] == -1:
continue
q.append([time + 1, ny, nx])
tomato[ny][nx] = 1

for i in range(n):
for j in range(m):
if tomato[i][j] == 1:
q.append([0, i, j])
bfs()
for i in range(n):
if 0 in tomato[i]:
flag = 1
break

if flag == 1:
print(-1)
else:
print(res)