본문 바로가기

반응형

전체 글

(133)
카카오 2022 파괴 되지 않는 건물 파이썬 (정확도만 통과) #skill = [type, r1, c1, r2, c2, degree] from multiprocessing.connection import answer_challenge def solution(board, skill): answer = 0 for arr in skill: if arr[0] == 1 : #공격 attack(board, arr) elif arr[0] == 2: #회복 heal(board, arr) for arr in board: for i in arr: if i > 0 : answer += 1 return answer def attack(board, arr): x1, y1, x2, y2 , degree = arr[1:6] for i in range(x1, x2+1)..
카카오 2022 양궁대회 (DFS) 파이썬 lionPoint = 0 apeachPoint = 0 maxGap = 0 Arr = [] lionArr = [0 for i in range(11)] def dfs(n, depth, info, start): global lionPoint, apeachPoint, maxGap if depth == n: for i in range(11): if not(lionArr[i] == 0 and info[i] == 0) : if lionArr[i] > info[i]: lionPoint += 10-i else : apeachPoint += 10-i if lionPoint > apeachPoint : gap = lionPoint - apeachPoint if gap > maxGap : Arr.clear() Arr...
카카오 2022 주차요금계산 파이썬 from math import ceil def solution(fees, records): answer = [] record_map = records_split(records=records) cars_nums = list(record_map.keys()) cars_nums.sort() for car in cars_nums: times = list(record_map.get(car)) sumTime = 0 for i in range(0, len(times), 2): if len(times) % 2 == 1 and i == len(times)-1: sumTime += (1439 - times[i]) else : sumTime += (times[i+1] - times[i]) answer.append(c..
카카오 2022 k진수에서 소수 개수 구하기 파이썬 def solution(n, k): answer = 0 numbers = convert(n, k) primeNumbers = numbers.split("0") primeNumbers = list(filter(None, primeNumbers)) primeNumbers = list(map(int, primeNumbers)) for num in primeNumbers: if num 0: converted_num.append((str)(n%k)) n //= k converted_num.reverse() return "".join(converted_num) print(solution(110011, 10))
카카오 2022 신고결과 받기 파이썬 def solution(id_list, report, k): report = set(report) report = list(report) reportList = list() #[[a, b] [c, d] [e, f] [g, h] ...] for i in report: reportList.appned(i.split()) users = [] users_cnt = [0 for _ in range(len(id_list))] for i in reportList : users.append(i[1]) temp = [] for i in range(len(id_list)): if users.count(id_list[i]) >= k : temp.append(id_list[i]) for i in reportList: ..
[다시 풀어보기] 백준 14888번 "연산자 끼워넣기" 파이썬 import sys n = int(sys.stdin.readline().rstrip()) nums = list(map(int, sys.stdin.readline().split())) a, s, m, d = map(int, sys.stdin.readline().split()) minmaxList= [] def dfs(i, num): global a, s, m, d, minmaxList if i == n: minmaxList.append(num) return if a > 0 : a -= 1 dfs(i+1, num +nums[i]) a += 1 if s > 0 : s -= 1 dfs(i+1, num - nums[i]) s += 1 if m > 0 : m -= 1 dfs(i+1, num * nums[i]..
[다시 풀어보기] 백준 9663번 "N-Queen" 파이썬 import sys n = int(sys.stdin.readline()) ans = 0 row = [0] * n def is_promising(x): for i in range(x): if (row[x] == row[i]) or (abs(row[x] - row[i]) == abs(x-i) ): return False return True def n_queens(x): global ans if x == n : ans += 1 return else : for i in range(n): row[x] = i if is_promising(x): n_queens(x+1) n_queens(0) print( ans) # 참고 : https://seongonion.tistory.com/103 자세한 풀이 🔜 ht..
백준 15652번 "N과 M (4)" 파이썬 import itertools import sys n , m = map(int, sys.stdin.readline().split()) ans_list = [] def dfs(): if len(ans_list) == m: print(" ".join(map(str, ans_list))) return for i in range(1, n+1): if not ans_list: ans_list.append(i) dfs() ans_list.pop() elif i >= ans_list[-1]: ans_list.append(i) dfs() ans_list.pop() dfs()