본문 바로가기

Algorithm 💡276

[프로그래머스 Lv.1] 모의고사 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(answers): answer = [] def method_1(answers): inputs = [1,2,3,4,5]*(10000//5 + 1) result = [1 for i,value in enumerate(answers) if answers[i] == inputs[i]] return sum(result) def method_2(answers): inputs = [2,1,2,3,2,4,2,5]*(10000//8 + 1) result = [1 for i,value in enumerat.. 2023. 9. 29.
[백준 17392번] 우울한 방학 17392번: 우울한 방학 1일, 5일, 8일에 약속을 순서대로 배치하면, 4일과 10일에 각각 1만큼의 우울함을 느끼게 되어, 총 2만큼의 우울함을 느끼게 된다. 이보다 덜 우울함을 느끼게 만드는 방법은 존재하지 않는다. www.acmicpc.net n, m = map(int,input().split()) h = list(map(int,input().split())) def getUnhappy(num): total = 0 for i in range(1,num+1): total += i**2 return total happy = sum(h) + len(h) unhappy = m - happy area = [0] * (n+1) index = 0 for i in range(unhappy): area[inde.. 2023. 9. 29.
[백준 1469번] 숌 사이 수열 1469번: 숌 사이 수열 첫째 줄에 X의 크기 N이 주어진다. 둘째 줄에 X에 들어가는 수가 빈칸을 사이에 두고 주어진다. X의 크기는 8보다 작거나 같은 자연수이다. X의 원소는 0보다 크거나 같고 16보다 작거나 같은 정수 www.acmicpc.net import sys sys.setrecursionlimit(10**7) n = int(input()) # X의 크기는 8보다 작거나 같은 자연수 # X의 원소는 0보다 크거나 같고 16보다 작거나 같은 정수이다. # 사전 순으로 가장 빠른 것 x = sorted(list(map(int,input().split()))) s = [-1 for _ in range(n*2)] visited = [False for _ in range(17)] def dfs(i.. 2023. 9. 29.
[프로그래머스 Lv.2] 타겟 넘버 재풀이 [프로그래머스 Lv.2] 타겟 넘버 # BFS from collections import deque def solution(numbers, target): answer = 0 queue = deque() queue.append((numbers[0],0)) queue.append((-numbers[0],0)) while queue: v, index = queue.popleft() index += 1 if index < len(numbers): queue.append((v+numbers[ind woohyun-king.tistory.com def solution(numbers, target): answer = 0 def dfs(depth,s): nonlocal answer if depth == len(numb.. 2023. 9. 28.
[프로그래머스 Lv.1] 최소직사각형 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(sizes): sizes = [sorted(x,reverse=True) for x in sizes] # [[60, 50], [70, 30], [60, 30], [80, 40]] widths = [x[0] for x in sizes] # [60, 70, 60, 80] heights = [x[1] for x in sizes] # [50, 30, 30, 40] return max(widths)*max(heights) 이번 문제는 주어진 명함들의 가로와 세로길이가 주어졌을 때, 명함을 가로나 .. 2023. 9. 28.
[SWEA 5102번] 노드의 거리 from collections import deque t = int(input()) answer = [] for _ in range(t): v, e = map(int,input().split()) graph = [[] for _ in range(v+1)] visited = [0]*(v+1) for i in range(e): start, end = map(int,input().split()) graph[start].append(end) graph[end].append(start) s, g = map(int,input().split()) def bfs(s,g): visited[s] = 0 queue = deque([s]) while queue: v = queue.popleft() for node in gra.. 2023. 9. 21.