본문 바로가기
반응형

알고리즘65

[파이썬][프로그래머스] 완전탐색 피로도 from itertools import permutations def solution(k, dungeons): answer = -1 dungeonsList = list(permutations(dungeons, len(dungeons))) maxResult = 0 for dungeonList in dungeonsList: useFatigue = 0 Result = 0 for dungeon in dungeonList: if (k-useFatigue-dungeon[0]) >= 0: useFatigue += dungeon[1] Result += 1 if maxResult 2022. 11. 29.
[파이썬][프로그래머스] 완전탐색 카펫 def solution(brown, yellow): answer = [] # 가로 * 세로 = brown + yellow areas = findRowCol(brown + yellow) # (가로 + 세로) * 2 - 4 = brown for area in areas: if ((area[0] + area[1]) * 2 - 4) == brown: return area return answer def findRowCol(data): answer = [] for i in range(data//2 + 1): if i in (0, 1, 2): pass else: if data % i == 0: if i 2022. 11. 28.
[파이썬][프로그래머스] 완전탐색 소수찾기 from itertools import permutations def solution(numbers): answer = 0 answer_list = {} checkList = [] for i in range(len(numbers) + 1): test = list(permutations(numbers, i)) for j in range(len(test)): temp = list(test[j]) temp1 = ''.join(i for i in temp) if temp1 != '': if int(temp1) != 0: answer_list[int(temp1)] = int(temp1) checkList = answer_list.keys() answer = checkPrime(checkList) return an.. 2022. 11. 27.
[파이썬][프로그래머스] 완전탐색 모의고사 def solution(answers): one_answer = [1,2,3,4,5] two_answer = [2,1,2,3,2,4,2,5] three_answer = [3,3,1,1,2,2,4,4,5,5] one_coin = 0 two_coin = 0 three_coin = 0 # one one_count = 0 for answer in answers: if answer == one_answer[one_count % len(one_answer)]: one_coin += 1 one_count += 1 # two two_count = 0 for answer in answers: if answer == two_answer[two_count % len(two_answer)]: two_coin += 1 two_.. 2022. 11. 25.
반응형