프로그래머스 43164. 여행경로
·
백준
https://school.programmers.co.kr/learn/courses/30/lessons/43164 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krfrom collections import defaultdictdef solution(tickets): # 경로 그래프 생성 link = defaultdict(list) for ticket in tickets: link[ticket[0]].append(ticket[1]) # 각 출발지에서의 도착지들을 사전순 정렬 for key in link: link[key].sort(reverse=Tr..
백준 1600. 말이 되고픈 원숭이
·
백준
https://www.acmicpc.net/problem/1600from collections import dequeimport sysinput = sys.stdin.readlinek = int(input()) # 말처럼 이동할 수 있는 횟수w, h = map(int, input().split()) # 가로, 세로 크기arr = [list(map(int, input().split())) for _ in range(h)]# 4방향(원숭이 이동)monkey_moves = [(-1, 0), (1, 0), (0, -1), (0, 1)]# 8방향(말 이동)horse_moves = [(-2, -1), (-1, -2), (1, -2), (2, -1), (2, 1), (1, 2), (-1, 2), (-2, 1)]#..
[Python/파이썬]프로그래머스 87694. 아이템 줍기
·
프로그래머스
https://school.programmers.co.kr/learn/courses/30/lessons/87694 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krfrom collections import dequedef solution(rectangle, characterX, characterY, itemX, itemY): # 좌표 확장 board = [[-1] * 102 for _ in range(102)] for x1, y1, x2, y2 in rectangle: x1, y1, x2, y2 = x1*2, y1*2, x2*2, y2*2 for i in range..
[Python/파이썬]프로그래머스 43162. 네트워크
·
프로그래머스
https://school.programmers.co.kr/learn/courses/30/lessons/43162 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krdef solution(n, computers): def dfs(node): visited[node] = True for neighbor in range(n): if computers[node][neighbor] == 1 and not visited[neighbor]: dfs(neighbor) visited = [False] * n # 방문 여부를 기록하는..
[Python/파이썬]프로그래머스 86491. 최소직사각형
·
프로그래머스
https://school.programmers.co.kr/learn/courses/30/lessons/86491 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krdef solution(sizes): # 명함의 가로와 세로 중 더 큰 값을 가로로, 작은 값을 세로로 정렬 for i in range(len(sizes)): sizes[i] = sorted(sizes[i], reverse=True) # 각 명함의 가로와 세로 중 최댓값 찾기 max_width = max(size[0] for size in sizes) max_height = max(size[1] fo..
프로그래머스 87946. 피로도
·
프로그래머스
https://school.programmers.co.kr/learn/courses/30/lessons/87946 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krdef solution(k, dungeons): global ans ans = 0 # 최대 탐험 가능한 던전 수 = 정답 def back(visited, piro, cnt): global ans ans = max(ans, cnt) # 최댓값 갱신 for i in range(len(dungeons)): # 모든 dungeons 순회 if not visited[i] and ..