본문 바로가기
반응형

프로그래머스234

(Python/Lv2) 쿼드 압축 후 갯수 세기 문제 출처:https://school.programmers.co.kr/learn/courses/30/lessons/68936 풀이: def check(x, y, n, arr): # 탈출 조건 if n == 1: if arr[x][y] == 1: return [0, 1] # 1 카운트 증가 else: return[1, 0] # 0카운트 증가 left_up = check(x, y, n//2, arr) # 2사분면 체크 right_up = check(x, y+n//2, n//2, arr) # 1사분면 체크 left_down = check(x+n//2, y, n//2, arr) # 3사분면 체크 right_down = check(x+n//2, y+n//2, n//2, arr) #4사분면 체크 # 각 축소 후 압.. 2023. 5. 6.
(Python/LV0) 배열 조각하기 문제 출처:https://school.programmers.co.kr/learn/courses/30/lessons/181893 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이: def solution(arr, query): left,right = 0,0 for i in range(len(query)): if i % 2 : # 홀수일때 1 반환 left +=query[i] else: right = left +query[i] # 앞에는 짤렸으므로 s를 더해줘야함 return arr[left:right+1] 0레벨 문제이지만 정답률 제일 낮은 문제이고 투포.. 2023. 5. 3.
(Python/🥈4)백준 알고리즘 10866번: 덱 문제 출처: https://www.acmicpc.net/problem/10866 10866번: 덱 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net 풀이: import sys sys.stdin = open('/Users/song/Desktop/Python/Python/h.txt', 'r') from collections import deque N = int(input()) dq = deque() for i in range(N): x = sys.stdin.readline().rstrip().split() if x[0.. 2023. 5. 1.
(Python/🥈4)백준 알고리즘 10845번: 큐 문제출처: https://www.acmicpc.net/problem/10845 10845번: 큐 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net 풀이 import sys sys.stdin = open('/Users/song/Desktop/Python/Python/h.txt', 'r') from collections import deque n = int(sys.stdin.readline()) queue = deque() for i in range(n): x = sys.stdin.readline().split() i.. 2023. 5. 1.
(Python/LV3)가장 먼 노드 문제출처: https://school.programmers.co.kr/learn/courses/30/lessons/49189 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이: from collections import deque def solution(n, edge): dist = [1] + [0] * (n - 1) graph = [[ ] for i in range(n)] q =deque([1]) for x, y in edge: graph[x-1].append(y) graph[y-1].append(x) while q: l = len(q) for i i.. 2023. 4. 18.
(Python/LV2) 위장 문제출처: https://school.programmers.co.kr/learn/courses/30/lessons/42578 풀이 : 첫시도 dic = dict() for (key, value) in clothes: if value in dic: dic[value].append(key) else: dic[value] = [key] # dics = {value: [key] if value not in dic else dic[value] for key, value in clothes} res = 0 num = [] for i in "headgear", "eyewear", "face" : if i in dic: res += len(dic[i]) num.append(len(dic[i])) if len(num) .. 2023. 4. 15.
반응형