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

17 ljedd2 #185

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
10 changes: 9 additions & 1 deletion LJEDD2/2024-2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@
| 6μ°¨μ‹œ | 2024.08.03 | 완전탐색 | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/87946">ν”Όλ‘œλ„</a> | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/141) |
| 7μ°¨μ‹œ | 2024.09.01 | μœ„μƒμ •λ ¬ | <a href="https://www.acmicpc.net/problem/2252">쀄 μ„Έμš°κΈ°</a> | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/152) |
| 8μ°¨μ‹œ | 2024.09.04 | μœ„μƒμ •λ ¬ | <a href="https://www.acmicpc.net/problem/1766">λ¬Έμ œμ§‘</a> | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/154) |
| 9μ°¨μ‹œ | 2024.09.07 | μŠ€νƒ | <a href="https://www.acmicpc.net/problem/2176">μ›μˆ­μ΄ 맀달기</a> | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/156) |
| 9μ°¨μ‹œ | 2024.09.07 | μŠ€νƒ | <a href="https://www.acmicpc.net/problem/2176">μ›μˆ­μ΄ 맀달기</a> | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/156) |
| 10μ°¨μ‹œ | 2024.09.11 | μš°μ„ μˆœμœ„ 큐 | <a href="https://www.acmicpc.net/problem/1715">μΉ΄λ“œ μ •λ ¬ν•˜κΈ°</a> | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/159) |
| 11μ°¨μ‹œ | 2024.09.18 | μš°μ„ μˆœμœ„ 큐 | <a href="https://www.acmicpc.net/problem/2075">N번째 큰 수</a> | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/161) |
| 12μ°¨μ‹œ | 2024.09.21 | μš°μ„ μˆœμœ„ 큐 | <a href="https://www.acmicpc.net/problem/15903">μΉ΄λ“œ 합체 놀이</a> | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/164) |
| 13μ°¨μ‹œ | 2024.09.25 | ν”Œλ‘œμ΄λ“œ μ›Œμ…œ | <a href="https://www.acmicpc.net/problem/1058">친ꡬ</a> | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/167) |
| 14μ°¨μ‹œ | 2024.09.28 | 큐 | <a href="https://www.acmicpc.net/problem/2161">μΉ΄λ“œ1</a> | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/170) |
| 15μ°¨μ‹œ | 2024.10.02 | 브루트포슀 | <a href="https://www.acmicpc.net/problem/11502">μ„Έ 개의 μ†Œμˆ˜ 문제</a> | [#15](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/174) |
| 16μ°¨μ‹œ | 2024.10.05 | 그리디 | <a href="https://www.acmicpc.net/problem/28110">λ§ˆμ§€λ§‰ 문제</a> | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/179) |
| 17μ°¨μ‹œ | 2024.11.02 | λ„ˆλΉ„μš°μ„ νƒμƒ‰(BFS) | <a href="https://www.acmicpc.net/problem/9019">DSLR</a> | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/185) |
Empty file.
50 changes: 50 additions & 0 deletions LJEDD2/2024-2/λ„ˆλΉ„μš°μ„ νƒμƒ‰(BFS)/DSLR.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# BOJ 9019
import sys
from collections import deque
input = sys.stdin.readline

for _ in range(int(input())):
A, B = map(int,input().split())

visited = [False] * (10001)
queue = deque([(A,'')])
visited[A] = True

# μˆ˜μ‹ μ°Έκ³  https://velog.io/@hamsangjin/%EB%B0%B1%EC%A4%80-9019%EB%B2%88-DSLR-%ED%8C%8C%EC%9D%B4%EC%8D%AC
while queue:
num, order = queue.popleft()

if num == B:
print(order)
break

# D: D λŠ” n을 두 배둜 λ°”κΎΌλ‹€.
# κ²°κ³Ό 값이 9999 보닀 큰 κ²½μš°μ—λŠ” 10000 으둜 λ‚˜λˆˆ λ‚˜λ¨Έμ§€λ₯Ό μ·¨ν•œλ‹€.
# κ·Έ κ²°κ³Ό κ°’(2n mod 10000)을 λ ˆμ§€μŠ€ν„°μ— μ €μž₯
D = num * 2 % 10000
if not visited[D]:
visited[D] = True
queue.append((D, order + 'D'))

# S: S λŠ” nμ—μ„œ 1 을 λΊ€ κ²°κ³Ό n-1을 λ ˆμ§€μŠ€ν„°μ— μ €μž₯ν•œλ‹€.
# n이 0 이라면 9999 κ°€ λŒ€μ‹  λ ˆμ§€μŠ€ν„°μ— μ €μž₯
S = (num - 1) % 10000
if not visited[S]:
visited[S] = True
queue.append((S, order + 'S'))

# L: L 은 n의 각 자릿수λ₯Ό μ™ΌνŽΈμœΌλ‘œ νšŒμ „μ‹œμΌœ κ·Έ κ²°κ³Όλ₯Ό λ ˆμ§€μŠ€ν„°μ— μ €μž₯ν•œλ‹€.
# 연산이 λλ‚˜λ©΄ λ ˆμ§€μŠ€ν„°μ— μ €μž₯된 λ„€ μžλ¦Ώμˆ˜λŠ” μ™ΌνŽΈλΆ€ν„° d2, d3, d4, d1이 λœλ‹€
# 첫번째 자리λ₯Ό 끝으둜 보내버리도둝
L = num // 1000 + (num % 1000)*10
if not visited[L]:
visited[L] = True
queue.append((L, order + 'L'))

# R: R 은 n의 각 자릿수λ₯Ό 였λ₯ΈνŽΈμœΌλ‘œ νšŒμ „μ‹œμΌœ κ·Έ κ²°κ³Όλ₯Ό λ ˆμ§€μŠ€ν„°μ— μ €μž₯ν•œλ‹€.
# 이 연산이 λλ‚˜λ©΄ λ ˆμ§€μŠ€ν„°μ— μ €μž₯된 λ„€ μžλ¦Ώμˆ˜λŠ” μ™ΌνŽΈλΆ€ν„° d4, d1, d2, d3이 λœλ‹€.
# λ§ˆμ§€λ§‰ 숫자 데렀였기
R = num // 10 + (num % 10) * 1000
if not visited[R]:
visited[R] = True
queue.append((R, order + 'R'))
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys
input = sys.stdin.readline

# ν•˜λ‚˜μ˜ μ†Œμˆ˜λ₯Ό μ—¬λŸ¬ 번 더할 수 μžˆλ‹€. -> 브루트포슀 κ°€λŠ₯
# 5보닀 큰 μž„μ˜μ˜ ν™€μˆ˜λ‘œ μ„Έ μ†Œμˆ˜μ˜ 합이 λ˜λŠ”μ§€
def search(n):
for i in arr:
for j in arr:
for k in arr:
if i+j+k == n:
return i, j, k

else: # μ•ˆλ˜λ©΄ 0
return 0

# μ—λΌν† μŠ€ν…Œλ„€μŠ€μ˜ 체 - μ†Œμˆ˜ νŒλ³„
prime = [True] * 1001

for i in range(2,101):
if prime[i]:
for j in range(i*2, 1001, i):
prime[j] = False

# μ†Œμˆ˜ μ°ΎκΈ°
arr = [i for i in range(2, 1001) if prime[i] == True]

t = int(input())
for _ in range(t):
n = int(input())
print(*search(n))
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys, heapq
input = sys.stdin.readline

n = int(input())
heap = []

for _ in range(n):
for number in map(int, input().split()):

if len(heap) < n: # 비ꡐ λŒ€μƒμ΄ λͺ¨μžλž„ 경우
heapq.heappush(heap, number) #κ·ΈλŒ€λ‘œ μΆ”κ°€

else:
if number > heap[0]: # 제일 μž‘μ€κ²ƒλ³΄λ‹€ 크면
heapq.heapreplace(heap, number) #μž‘μ€κ±° λΉΌκ³  큰거 λ„£μ–΄μ€Œ

print(heap[0]) # λ§¨μ•žμ— μžˆλŠ”κ²Œ N번째둜 ν°λ†ˆ
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys
import heapq
input = sys.stdin.readline

cards = list(int(input()) for _ in range(int(input().strip()))) # 데이터 μž…λ ₯λ°›μŒ
heapq.heapify(cards) # 리슀트λ₯Ό νž™κ΅¬μ‘°λ‘œ λ°”κΏ”μ£ΌλŠ” ν•¨μˆ˜

result = 0
while len(cards) > 1 :
f = heapq.heappop(cards) # 첫번째 뭉탱이
s = heapq.heappop(cards) # λ‘λ²ˆμ§Έ 뭉탱이

result += f+s

# λ°”κΏ”μΉ˜κΈ° νšŸμˆ˜κ°€ μ΅œμ†Œκ°€ λ˜κ²Œλ”
heapq.heappush(cards, f+s)

print(result)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import heapq
n, m = map(int,input().split())

#νž™ ꡬ쑰둜 λ³€ν™˜
numbers = list(map(int,input().split()))
heapq.heapify(numbers)

for _ in range(m):

x = heapq.heappop(numbers)
y = heapq.heappop(numbers)

# x와 y λ‘˜ λ‹€ κ°’ ꡐ체
heapq.heappush(numbers, x+y)
heapq.heappush(numbers, x+y)

print(sum(numbers))
14 changes: 14 additions & 0 deletions LJEDD2/2024-2/큐/μΉ΄λ“œ1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sys
from collections import deque
input = sys.stdin.readline

n = int(input().strip())
queue = deque([i for i in range(1, n+1)])
result = []

while len(queue) > 1:
result.append(queue.popleft())
queue.append(queue.popleft())
else:
result.append(queue.popleft())
print(" ".join(map(str, result)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import sys
input = sys.stdin.readline

n = int(input())
graph = [list(input().strip()) for _ in range(n)]
visited = [[0] * n for _ in range(n)]

for k in range(n):
for i in range(n):
for j in range(n):
if i == j:
continue

# 2-친ꡬ인 경우
if graph[i][j] == 'Y' or (graph[i][k] == 'Y' and graph[k][j] == 'Y'):
visited [i][j] = 1

res = 0
for row in visited:
res = max(res,sum(row))
print(res)