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

15 ljedd2 #174

Merged
merged 15 commits into from
Nov 22, 2024
6 changes: 6 additions & 0 deletions LJEDD2/2024-2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@
| 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) |
| 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.10.02 | 브루트포슀 | <a href="https://www.acmicpc.net/problem/11502">μ„Έ 개의 μ†Œμˆ˜ 문제</a> | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/174) |
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]
Comment on lines +16 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ†Œμˆ˜λ₯Ό ꡬ할 λ•Œ μ €λŠ” μ•„λž˜ μ½”λ“œμ²˜λŸΌ κ΅¬ν˜„ν–ˆλŠ”λ°, μ—λΌν† μŠ€ν…Œλ„€μŠ€μ˜ 체λ₯Ό μ΄μš©ν•˜λ©΄ μˆ«μžκ°€ 더 μ»€μ‘Œμ„ λ•Œλ„ μ‹œκ°„ λ³΅μž‘λ„ μΈ‘λ©΄μ—μ„œ μœ λ¦¬ν•˜κ²Œ κ΅¬ν˜„ν•  수 μžˆκ² λ„€μš”! μ œκ°€ μ‚¬μš©ν•œ 방식도 λ°±μ€€μ—μ„œλŠ” ν†΅κ³Όλ˜κΈ°λŠ” ν–ˆμ§€λ§Œ, μˆ«μžκ°€ 컀질수둝 λ‚˜λˆ—μ…ˆ 연산이 λŠ˜μ–΄λ‚˜μ„œ μ’€ λΉ„νš¨μœ¨μ μΌ κ±° κ°™λ„€μš” πŸ₯Ή

val primes = mutableListOf<Int>()

for (i in 2..1000) {
  var isPrime = true
  for (p in primes) {
    if (p * p > i) break  // 이미 κ΅¬ν•œ μ†Œμˆ˜λ‘œλ§Œ λ‚˜λˆ μ„œ 확인
    if (i % p == 0) {
      isPrime = false
      break
    }
  }
  if (isPrime) {
    primes.add(i)  // μ†Œμˆ˜λ©΄ λ¦¬μŠ€νŠΈμ— μΆ”κ°€
  }
}


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,37 @@
# 더 κ°„λ‹¨ν•œ 풀이 ... (λ¬Έμžμ—΄)
import sys
input = sys.stdin.readline

for _ in range(int(input())):
cnt = 0
s = input().rstrip()
while "[]" in s:
s = s.replace("[]", "")
cnt += 1

print(2**cnt)



# import sys

# input = sys.stdin.readline

# for _ in range(int(input())):
# s = input().rstrip() # κ΄„ν˜Έ λ¬Έμžμ—΄

# max_depth = 0 # μ΅œλŒ€ 깊이λ₯Ό μ €μž₯ν•  λ³€μˆ˜
# tree = list() # ν˜„μž¬ μ—΄λ¦° κ΄„ν˜Έλ₯Ό μ €μž₯ν•  μŠ€νƒμž„

# for i in s:
# # μ—¬λŠ” κ΄„ν˜ΈμΌ 경우 μŠ€νƒμ— μ—΄λ¦° κ΄„ν˜Έ μΆ”κ°€
# if i == '[':
# tree.append('[')
# continue
# # λ‹«λŠ” κ΄„ν˜ΈμΌ 경우
# max_depth = max(len(tree), max_depth)
# # ν˜„μž¬ κΉŠμ΄μ™€ μ΅œλŒ€ 깊이 쀑 큰 값을 μ €μž₯ν•˜κ³ 
# tree.pop() # λ§ˆμ§€λ§‰ μ—΄λ¦° κ΄„ν˜Έλ₯Ό 제거

# print(2 ** max_depth) # μŒμ„ μ΄λ£°λ•Œ 가지 생성, 가지2-.1κ°œμ”© λ‚˜λˆ κ°€μ§
# # κ²°κ΅­μ—” 2의 depth승
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)