본문 바로가기

알고리즘 풀이79

[algorithm] 페어 - 프로그래머스: 피로도 답: 더보기 우옹 내가 이걸 풀다니>.= dungeon_dataset[key][length][0]: dungeon_datadic[key] += 1 # 입장 후 퇴장할때 hp - 소모 피로도로 유효성 점검 hp = hp - dungeon_dataset[key][length][1] else: break answer = sorted(dungeon_datadic.items(), key=lambda x: x[1], reverse=True) #내림차순 정렬 return answer[0][1] print(solution(80, [[80,20],[50,40],[30,10]])) #3 하지만 스승호님이 너무 강했따 >> 노션과 다른 사람 풀이보고 공부하기 소수찾기의 원수! 문제 분석 및 해석 문제 : https://sc.. 2023. 5. 31.
[alghorithm] 페어 - 프로그래머스: 과일 장수 답: 더보기 def solution(k, m, score): result = [] answer = 0 score = sorted(score,reverse=True) for i in range(0,len(score),m): if len(score[i:i+m]) == m : # i+m > len(score) 이렇게 비교하는 방법도 있음! result.append(score[i:i+m]) for idx,value in enumerate(result): answer += result[idx][-1] * m return answer # print(solution(3,4,[1, 2, 3, 1, 2, 3, 1])) # 8 # print(solution(4,3,[4, 1, 2, 2, 4, 4, 4, 4, 1, 2, 4.. 2023. 5. 31.
[algorithm] 페어 - 프로그래머스: 체육복 이 문제를 풀기 전에 먼저 알아두자 그리디 알고리즘! greedy algorithm은 탐욕 알고리즘 또는 욕심쟁이 알고리즘 눈 앞에 보이는 단계에서 최선의 선택을한다. = 미래를 생각하지 않고 각 단계에서 가장 최선의 선택을 하는 기법 각 단계에서 최선의 선택을 한 것이 전체적으로도 최선이길 바라는 것. 완전한 답 도출 못함: 더보기 일단 풀이 작성 1번 풀이 def solution(n, lost, reserve): # 여벌옷 + 도난 검사 for l in lost[:]: #lost의 요소 변화로 인한 오류 if l in reserve: lost.remove(l) lost.sort() reserve.sort() for l in lost[:]: #lost의 요소 변화로 인한 오류 if l - 1 in r.. 2023. 5. 19.
[algorithm] 페어 - 프로그래머스: 성격 유형 검사하기 답: 더보기 나의 길쭉한 답... result = {'R':0, 'T':0, 'F':0, 'C':0, 'J':0, "M":0, "A":0, "N":0} def solution(survey, choices): for i in range(len(survey)): a = survey[i][0] # A b = survey[i][1] # N if choices[i] 4: if choices[i] == 5: result[b] += 1 elif choices[i] == 6: resul.. 2023. 5. 18.