-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/kdongsu5509/Haedal_Algorith…
- Loading branch information
Showing
26 changed files
with
618 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
bucket = [] | ||
answer = 0 | ||
def solution(board,moves): | ||
lanes = [[]for _ in range(len(board[0]))] | ||
|
||
for i in range(len(board) -1, -1, -1): | ||
for j in range(len(board[0])): | ||
if board[i][j]: | ||
lanes[j].append(board[i][j]) | ||
|
||
for m in moves: | ||
if lanes[m -1]: | ||
doll = lanes[m -1].pop() | ||
|
||
if bucket and bucket[-1] == doll: | ||
bucket.pop() | ||
answer += 2 | ||
else: | ||
bucket.append(doll) | ||
return answer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
def solution(n, k, cmd): | ||
deleted = [ ] | ||
|
||
up = [i - 1 for i in range(n + 2)] | ||
|
||
down = [i + 1 for i in range(n + 1)] | ||
|
||
k += 1 | ||
|
||
for cmd_i in cmd: | ||
if cmd_i.startswith("C"): | ||
deleted.append(k) | ||
up[down[k]] = up[k] | ||
down[up[k]] = down[k] | ||
k = up[k] if n < down[k] else down[k] | ||
|
||
elif cmd_i.startswith("Z"): | ||
restore = deleted.pop( ) | ||
down[up[restore]] = restore | ||
up[down[restore]] = restore | ||
|
||
else: | ||
action, num = cmd_i.split( ) | ||
if action == "U": | ||
for _ in range(int(num)): | ||
k = up[k] | ||
else: | ||
for _ in range(int(num)): | ||
k = down[k] | ||
|
||
answer = ["O"] * n | ||
for i in deleted: | ||
answer[i - 1] = "X" | ||
return "".join(answer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from collections import deque | ||
|
||
def solution(N, K): | ||
que = deque(range(1, N+1)) | ||
|
||
while len(que)>1: | ||
for _ in range(K -1): | ||
que.append(que.popleft()) | ||
|
||
que.popleft() | ||
return que[0] | ||
|
||
print(solution(5,2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from collections import deque | ||
|
||
def solution(progresses, speeds): | ||
answer = [] | ||
days = deque() | ||
|
||
for i in range(len(progresses)): | ||
remain = 100 - progresses[i] | ||
day = (remain + speeds[i] - 1) // speeds[i] | ||
days.append(day) | ||
|
||
while days: | ||
current_day = days.popleft() | ||
count = 1 | ||
while days and days[0] <= current_day: | ||
count += 1 | ||
days.popleft() | ||
answer.append(count) | ||
|
||
return answer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
arr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
for x in range(10) : | ||
for i in range(len(progresses)) : | ||
if (progresses[i] < 100) : | ||
progresses[i] += speeds[i] | ||
result[i] += 1 | ||
k) | ||
print(lst) | ||
print(stack) | ||
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
def solution(want, number, discount) : | ||
dic = {} | ||
|
||
# 정현이가 원하는 제품과 개수를 dictionary에 저장 | ||
for i in range(len(want)) : | ||
dic[want[i]] = number[i] | ||
|
||
# 할인 상품과 원하는 제품 비교 | ||
cnt = 0 # 원하는 제품을 모두 할인받을 수 있는 회원 등록 날짜 수 | ||
for j in range(len(discount) - 9) : # 10일 순회할 수 있을 만큼만 discount 순회 | ||
tenDays = {} | ||
|
||
for k in range(j, j + 10) : # 특정 날짜(k)부터 10일간 discount 물품 순회 | ||
if discount[k] in dic : # 할인 품목이 정현이가 원하는 제품 목록에 있으면 | ||
tenDays[discount[k]] = tenDays.get(discount[k], 0) + 1 # 10일동안 할인받는 물품들의 개수를 tenDays 딕셔너리에 저장 | ||
# tenDays에 이미 있으면 해당 값(value) + 1, 없으면 기본값(default value) + 1 | ||
if tenDays == dic : | ||
cnt += 1 # 10일 연속으로 원하는 제품을 개수만큼 할인받을 수 있다면 cnt++ | ||
break # 책과 다름. 조금 수정함.. | ||
|
||
|
||
return cnt | ||
|
||
|
||
|
||
|
||
|
||
#TEST 코드입니다. 주석을 풀어서 확인해보세요 | ||
print(solution(["banana", "apple", "rice", "pork", "pot"], [3, 2, 2, 2, 1], ["chicken", "apple", "apple", "banana", "rice", "apple", "pork", "banana", "pork", "rice", "pot", "banana", "apple", "banana"])) | ||
print(solution(["apple"], [10], ["banana", "banana", "banana", "banana", "banana", "banana", "banana", "banana", "banana", "banana"])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
def solution(id_list, report, k) : | ||
reported_user = {} | ||
count = {} | ||
|
||
for r in report : | ||
user_id, reported_id = r.split() | ||
if reported_id not in reported_user : | ||
reported_user[reported_id] = set() | ||
reported_user[reported_id].add(user_id) | ||
|
||
for reported_id, user_id_lst in reported_user.items() : | ||
if len(user_id_lst) >= k : | ||
for uid in user_id_lst : | ||
if uid not in count : | ||
count[uid] = 1 | ||
else : | ||
count[uid] += 1 | ||
|
||
answer = [] | ||
for i in range(len(id_list)) : | ||
if id_list[i] not in count : | ||
answer.append(0) | ||
else : | ||
answer.append(count[id_list[i]]) | ||
|
||
return answer | ||
|
||
|
||
#TEST 코드입니다. 주석을 풀어서 확인해보세요 | ||
print(solution(["muzi", "frodo", "apeach", "neo"], ["muzi frodo", "apeach frodo", "frodo neo", "muzi neo", "apeach muzi"], 2)) | ||
print(solution(["con", "ryan"], ["ryan con", "ryan con", "ryan con", "ryan con"], 3)) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
# def solution(id_list, report, k) : | ||
# id_dict = dict.fromkeys(id_list, 0) # 해당 아이디가 신고당한 횟수 기록 | ||
# report_dict = {} # 신고자 - 피신고자(리스트 형태) 기록 | ||
# mail_dict = dict.fromkeys(id_list, 0) # 신고자가 받을 메일 개수 기록 | ||
|
||
# for names in report : | ||
# idx = names.split() | ||
|
||
# if report_dict.get(idx[0]) == None : | ||
# report_dict[idx[0]] = list() | ||
|
||
# if idx[1] not in report_dict[idx[0]] : | ||
# report_dict[idx[0]].append(idx[1]) | ||
# id_dict[idx[1]] += 1 | ||
|
||
|
||
# rpt = 0; rpte = 0 | ||
|
||
# while(1) : | ||
# name = id_list[rpt] | ||
|
||
# if report_dict.get(id_dict[name]) == None : | ||
# rpt += 1 | ||
# continue | ||
# elif report_dict[id_dict[name]][rpte] >= 2 : | ||
# mail_dict[rpt] += 1 | ||
|
||
# if report_dict[id_dict[name]][rpte+1] == None : | ||
# rpt = 0 | ||
# rpte = 0 | ||
# else : | ||
# rpte += 1 | ||
|
||
# result = list(mail_dict.values()) | ||
|
||
# print(id_dict) | ||
# print(report_dict) | ||
|
||
# return result | ||
|
||
|
||
# #TEST 코드입니다. 주석을 풀어서 확인해보세요 | ||
# print(solution(["muzi", "frodo", "apeach", "neo"], ["muzi frodo", "apeach frodo", "frodo neo", "muzi neo", "apeach muzi"], 2)) | ||
# print(solution(["con", "ryan"], ["ryan con", "ryan con", "ryan con", "ryan con"], 3)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from itertools import combinations | ||
from collections import Counter | ||
|
||
def solution(orders, course) : | ||
answer = [] | ||
|
||
for c in course : | ||
menu = [] | ||
for order in orders : | ||
comb = combinations( | ||
sorted(order), c | ||
) | ||
menu += comb | ||
counter = Counter(menu) | ||
if ( | ||
len(counter) != 0 and max(counter.values()) != 1 | ||
) : | ||
for m, cnt in counter.items() : | ||
if cnt == max(counter.values()) : | ||
answer.append("".join(m)) | ||
|
||
return sorted(answer) | ||
|
||
|
||
#TEST 코드입니다. 주석을 풀어서 확인해보세요 | ||
print(solution(["ABCFG", "AC", "CDE", "ACDE", "BCFG", "ACDEH"], [2, 3, 4])) | ||
print(solution(["ABCDE", "AB", "CD", "ADE", "XYZ", "XYZ", "ACD"], [2, 3, 5])) | ||
print(solution(["XYZ", "XWY", "WXA"], [2, 3, 4])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
d(idx[1]) | ||
id_dict[idx[1]] += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from collections import deque | ||
|
||
def solution(info, edges) : | ||
def build_tree(info, edges) : # 트리 구축 함수 | ||
tree = [[] for _ in range(len(info))] | ||
for edge in edges : | ||
tree[edge[0]].append(edge[1]) | ||
return tree | ||
|
||
tree = build_tree(info, edges) # 트리 생성 | ||
max_sheep = 0 # 최대 양의 수를 저장할 변수 초기화 | ||
|
||
# BFS를 위한 큐 생성 및 초기 상태 설정 | ||
q = deque([(0, 1, 0, set())]) # (현재 위치, 양의 수, 늑대의 수, 방문한 노드 집합) | ||
|
||
# BFS 시작 | ||
while q : | ||
current, sheep_count, wolf_count, visited = q.popleft() # 큐에서 상태 가져오기 | ||
max_sheep = max(max_sheep, sheep_count) # 최대 양의 수 업데이트 | ||
visited.update(tree[current]) # 방문한 노드 집합에 현재 노드의 이웃 노드 추가 | ||
|
||
for next_node in visited : # 인접한 노드들에 대해 탐색 | ||
if info[next_node] : # 늑대의 경우 | ||
if sheep_count != wolf_count + 1 : | ||
q.append( | ||
(next_node, sheep_count, wolf_count + 1, visited - {next_node}) | ||
) | ||
else : # 양의 경우 | ||
q.append( | ||
(next_node, sheep_count + 1, wolf_count, visited - {next_node}) | ||
) | ||
|
||
return max_sheep | ||
|
||
|
||
#TEST 코드입니다. 주석을 풀어서 확인해보세요 | ||
print(solution([0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1], [[0, 1], [1, 2], [1, 4], [0, 8], [8, 7], [9, 10], [9, 11], [4, 3], [6, 5], [4, 6], [8, 9]])) | ||
print(solution([0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0], [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [6, 9], [9, 10]])) |
Oops, something went wrong.