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

12-alstjr7437 #41

Merged
merged 3 commits into from
Mar 3, 2024
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
88 changes: 88 additions & 0 deletions alstjr7437/BFS/๋ฐฑ์กฐ์˜-ํ˜ธ์ˆ˜.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from collections import deque
import sys

dx = [0,0,-1,1]
dy = [1,-1,0,0]
r, c = map(int, input().split())

water1 = deque()
water2 = deque()
visited = [[False] * c for _ in range(r)]

swan1 = deque()
swan2 = deque()
visited2 = [[False] * c for _ in range(r)]

# 1. ์ „์ฒด ํ˜ธ์ˆ˜ ๋งŒ๋“ค๊ธฐ
river = []
for i in range(r):
river.append(list(input()))

day_count = 0

# 2. ๋ฐฑ์กฐ ์œ„์น˜ ์ฐพ๊ธฐ์™€ ๋ฌผ ์œ„์น˜ ์ฐพ๊ธฐ
swan = []
for x in range(c):
for y in range(r):
if river[y][x] == "L":
swan.append([y,x])
river[y][x] = "."
if river[y][x] == ".":
water1.append([y, x])
visited[y][x] = True

# 3. ๋ฐฑ์กฐ๋ฅผ ํ์— ์ถ”๊ฐ€
swan1.append(swan[0])
visited2[swan[0][0]][swan[0][1]] = True

# 4. ํ•˜๋ฃจ์— ํ•œ๋ฒˆ์”ฉ X ์—†์• ๊ธฐ(์–ผ์Œ ์—†์• ๊ธฐ)
def break_ice():
# print("-------")
while water1:
y, x = water1.popleft()
# print(y, x, water1, water2)
river[y][x] = "."
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if nx < 0 or nx >= c or ny < 0 or ny >= r:
continue
if not visited[ny][nx]:
if river[ny][nx] == ".":
water1.append([ny,nx])
else :
water2.append([ny,nx])
visited[ny][nx] = True

# 5. ๋ฐฑ์กฐ๊ฐ€ ๋งŒ๋‚˜๋Š”์ง€ ์ฒดํฌํ•˜๊ธฐ
def check_swan():
# print("-------")
while swan1 :
y, x = swan1.popleft()
# print(x,y,swan1, swan2)
if y == swan[1][0] and x == swan[1][1]:
print(day_count)
sys.exit()
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if nx < 0 or nx >= c or ny < 0 or ny >= r:
continue
if not visited2[ny][nx]:
if river[ny][nx] == "." and visited2[ny][nx] == False:
swan1.append([ny,nx])
else :
swan2.append([ny,nx])
visited2[ny][nx] = True
return False

# ๋งŒ๋‚ ๋•Œ๊นŒ์ง€ ๋Œ๋ฆฌ๊ธฐ
while 1:
break_ice()
water1 = water2
water2 = deque()

check_swan()
swan1 = swan2
swan2 = deque()
day_count += 1
3 changes: 2 additions & 1 deletion alstjr7437/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
| 8์ฐจ์‹œ | 2024.02.14 | DP | <a href="https://www.acmicpc.net/problem/12865">ํ‰๋ฒ”ํ•œ ๋ฐฐ๋‚ญ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/24 |
| 9์ฐจ์‹œ | 2024.02.17 | ๊ทธ๋ฆฌ๋”” | <a href="https://www.acmicpc.net/problem/2138">์ „๊ตฌ์™€ ์Šค์œ„์น˜</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/29 |
| 10์ฐจ์‹œ | 2024.02.20 | BFS/DFS | <a href="https://www.acmicpc.net/problem/11725">ํŠธ๋ฆฌ์˜ ๋ถ€๋ชจ ์ฐพ๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/33 |

| 11์ฐจ์‹œ | 2024.02.23 | ํ•ด์‹œ | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/42579">๋ฒ ์ŠคํŠธ ์•จ๋ฒ”</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/39 |
| 12์ฐจ์‹œ | 2024.02.26 | BFS | <a href="https://www.acmicpc.net/problem/3197">๋ฐฑ์กฐ์˜ ํ˜ธ์ˆ˜</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/41 |
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ def bfs():
bfs()

for i in range(2, n+1):
print(visited[i])
print(visited[i])
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
def solution(genres, plays):
answer = []
dict = {}

# ๋”•์…”๋„ˆ๋ฆฌ ๋งŒ๋“ค๊ธฐ
for i in range(len(genres)):
if genres[i] not in dict :
dict[genres[i]] = [[plays[i], i]]
else :
dict[genres[i]].append([plays[i],i])

# ๋”•์…”๋„ˆ๋ฆฌ ์•ˆ์— ์žฌ์ƒํšŒ์ˆ˜๋กœ ์žฌ์ •๋ ฌ
for genres, plays in dict.items():
dict[genres] = sorted(plays, key=lambda x: x[0], reverse=True)

# ๊ฐ ์žฅ๋ฅด ์ดํ•ฉ ๊ณ„์‚ฐ
totals = {i: sum(j[0] for j in songs) for i, songs in dict.items()}

# ์ดํ•ฉ ๊ธฐ์ค€์œผ๋กœ ๋”•์…”๋„ˆ๋ฆฌ ์ˆœ์„œ ๋ณ€๊ฒฝ
sorted_data = {k: v for k, v in sorted(dict.items(), key=lambda item: totals[item[0]], reverse=True)}


# ์ •๋‹ต ์ธ๋ฑ์Šค ์ถ”๊ฐ€ ๋ถ€๋ถ„
for i in sorted_data.values():
answer.append(i[0][1])
if len(i) != 1:
answer.append(i[1][1])


return answer
Loading