본문 바로가기

📂 Engineering/🔹 CS & OS18

itertools 참고용 from itertools permutations, combinations, combinations, combinations_with_replacement combinations_with_replacement combinations permutations 2022. 1. 6.
[프로그래머스] 모의고사 내 코드 def solution(answers): s1, s2, s3 = 0,0,0 n = len(answers) c = n//40+1 a1 = [1,2,3,4,5]*(8*c) a2 = [2,1,2,3,2,4,2,5]*(5*c) a3 = [3,3,1,1,2,2,4,4,5,5]*(4*c) for i in range(n): if answers[i] == a1[i]: s1 += 1 if answers[i] == a2[i]: s2 += 1 if answers[i] == a3[i]: s3 += 1 scores = [s1,s2,s3] m = max(scores) winners = [] for i in range(3): if scores[i] == m: winners.append(i+1) return winners .. 2021. 4. 25.
[프로그래머스] 완주하지 못한 선수 - 리스트 정렬, 해시 내가 짠 코드 def solution(participant, completion): if len(completion) == 0: return participant else: for c in completion: participant.remove(c) return participant[0] 나름 깔끔하다 생각했지만 for문으로 인해 효율성 점수가 0점이 나왔다... 리스트의 원소제거를 어떻게 하면 더 빨리 할 수 있을까? 어떻게 짜야 빨리 탐색할 수 있을까? 풀이방법들 1. collections 사용 from collections import Counter def solution(participant, completion): return list(Counter(participant) - Counter(co.. 2021. 4. 24.
A* 알고리즘 Heuristics 휴리스틱 함수 h(n)은 A알고리즘에게 현재 위치n에서 *목표까지의 최소비용**을 산정해 알려준다. 따라서 휴리스틱 함수를 어떻게 지정할지가 중요하다. A* Use of the Heuristic 휴리스틱은 A*알고리즘의 행동(이동)을 제어한다. 하나의 극점에서, 만약 h(n)이 0이면, g(n)만 역할을 수행하고 A*는 다익스트라 알고리즘이 된다. (다익스트라는 가장 짧은 경로를 찾는데 보증된 알고리즘) 만약 h(n) 값이 항상 n에서 goal까지 이동하는 비용보다 늘 작거나 같다면, A도 최단 경로를 찾는다고 보장할 수 있다. h(n)값이 작을수록, A가 더 많은 노드를 탐색할 것이고, 더 느리게 만들 것임. h(n)이 n에서 목표까지의 cost와 정확히 일치하는 경우, A는 최선의.. 2020. 12. 12.