Skip to content

[23-03-09] dain.py #159

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

Merged
merged 5 commits into from
Mar 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
12 changes: 12 additions & 0 deletions Programmers - 고득점 Kit/[그리디] 단속카메라/dain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from collections import deque

def solution(routes):
answer = 0
routes.sort(key=lambda x: (x[1], x[0]))
routes = deque(routes)
while routes:
answer += 1
s, e = routes.popleft()
while routes and routes[0][0] <= e:
routes.popleft()
return answer
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from collections import deque

def solution(bridge_length, weight, truck_weights):
bridge = deque([0 for _ in range(bridge_length)])
truck_weights = list(reversed(truck_weights))
current_weight = 0
answer = 0
while truck_weights:
current_weight -= bridge.popleft()
answer += 1
if current_weight + truck_weights[-1] <= weight:
truck = truck_weights.pop()
else:
truck = 0
current_weight += truck
bridge.append(truck)
return answer + bridge_length
14 changes: 14 additions & 0 deletions Programmers - 고득점 Kit/[스택-큐] 주식가격/dain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def solution(prices):
answer = [0 for _ in range(len(prices))]
stack = []

for i, p in enumerate(prices):
while stack and stack[-1][0] > p:
pop_p, pop_i = stack.pop()
answer[pop_i] = i - pop_i
stack.append((p, i))

for p, i in stack:
answer[i] = len(prices) - 1 - i

return answer
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from collections import defaultdict

def solution(n, wires):
answer = n
tree = defaultdict(list)
Copy link
Collaborator

Choose a reason for hiding this comment

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

디폴트딕트 갱장히 잘 써먹으시네 매일 등장하는듯 ㅋㅋㅋㅋㅋ


for a, b in wires:
tree[a].append(b)
tree[b].append(a)

for i in range(len(wires)):
visit = [False for _ in range(n + 1)]
a, b = wires[i]

def dfs(cur):
count = 1
visit[cur] = True
for next in tree[cur]:
if not visit[next] and (cur, next) not in [(a, b), (b, a)]:
count += dfs(next)
return count

answer = min(answer, abs(dfs(a) - dfs(b)))

return answer
17 changes: 17 additions & 0 deletions Programmers - 고득점 Kit/[완전탐색] 피로도/dain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from itertools import permutations

def solution(k, dungeons):
answer = 0
index = [i for i in range(len(dungeons))]
orders = permutations(index)
for order in orders:
count = 0
hp = k
for idx in order:
if hp >= dungeons[idx][0]:
hp -= dungeons[idx][1]
count += 1
else:
break
answer = max(answer, count)
return answer