[Programmers] Level 2. 광물 캐기
·
코딩테스트/Python
🔗 Problem Link 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr❔Thinking주어진 다이아몬드, 철, 돌 곡괭이로 주어진 광물을 최대한 캘때, 가장 적은 피로도가 쌓이는 방법을 찾는다.곡괭이가 적은 경우 광물이 남을 수 있고, 광물이 적을 경우 곡괭이가 남을 수 있다.💻Solution1. 모든 경우 확인 (시간초과)from itertools import permutationsdef solution(picks, minerals): total_cost = 10e9 # 곡괭이 선택하기 need_pick = len(minerals) // 5 + 1 total_pick = [..
[Beakjoon] 4195. 친구 네트워크
·
코딩테스트/Python
🔗 Problem Linkhttps://www.acmicpc.net/problem/4195❔Thinking친구 관계가 주어지면, 해당 친구 네트워크에 속한 인원 수를 반환한다.친구 네트워크는, root가 같은 사람들을 뜻한다.💻Solutionimport sysinput = sys.stdin.readlinedef find_parent(x, parent): if x != parent[x]: parent[x] = find_parent(parent[x], parent) return parent[x]def union(a, b, parent, size): a = find_parent(a, parent) b = find_parent(b, parent) if a != b: ..
[Programmers] Level 2. 퍼즐 게임
·
코딩테스트/Python
🔗 Problem Link 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr❔Thinking난이도(diffs)와 풀이시간(times)이 정해진 퍼즐을 모두 해결할 수 있는 숙련도(level)의 최솟값을 찾아야 한다.현재의 숙련도보다 어려운 퍼즐일 경우, 총 풀이시간에 현재 풀이시간과 이전 풀이시간을 난이도-숙련도 만큼 곱한다.💻Solutiondef solution(diffs, times, limit): n = len(diffs) left, right = 1, max(diffs) while left = diffs[i]: tmp_time += times[i] ..
[Programmers] Level 2. 디펜스 게임
·
코딩테스트/Python
🔗 Problem Link 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr❔Thinkingenemy에 담긴 적들을 라운드마다 차례대로 제거할때, 가장 많은 라운드 버틸 방법을 생각한다.'무적권'은 k개 만큼 쓸 수 있고, 쓰는 라운드에 따라 결과가 달라질 수 있다.n=10, k=1일 경우, [10,3,7]을 1라운드만에 끝나거나 3라운드 모두를 버틸 수 있다.💻Solutionimport heapqdef solution(n: int, k: int, enemy: list) -> int: max_heap = [] # 지금까지 만난 적을 저장할 최대 힙 for round_num, e in enu..
[Beakjoon] 20040. 사이클 게임
·
코딩테스트/Python
🔗 Problem Linkhttps://www.acmicpc.net/problem/20040❔Thinking방향이 없는 그래프에서 사이클이 형성되었는지 확인하고, 그 순간을 출력한다.사이클이 없다면 0을 출력한다.💻Solutionimport sysinput = sys.stdin.readlineN, M = map(int, input().split())roots = [i for i in range(N)]def find_root(x): if x != roots[x]: roots[x] = find_root(roots[x]) return roots[x]def union(a, b, roots): a = find_root(a) b = find_root(b) roots[max..
[Beakjoon] 1213. 펠린드롬 만들기
·
코딩테스트/Python
🔗 Problem Linkhttps://www.acmicpc.net/problem/1213❔Thinking주어진 문자열을 사전순으로 앞서는 '펠린드롬' 문자열을 만들어 반환한다.똑바로해도, 거꾸로해도 같아야 하기 때문에, 배열 세개로 해결한다. (left, mid, right)만약 가운데 오는 문자열이 2개 이상일 경우, 펠린드롬 문자열을 만들 수 없다. (ex - AAABBB)💻Solutionname = list(input())name.sort()char_set = set()left, mid, right = [], [], []for char in name: if char not in char_set: char_set.add(char) tmp = name.count(ch..