전체 글 473

백준 3055 탈출 파이썬

www.acmicpc.net/problem/3055 3055번: 탈출 사악한 암흑의 군주 이민혁은 드디어 마법 구슬을 손에 넣었고, 그 능력을 실험해보기 위해 근처의 티떱숲에 홍수를 일으키려고 한다. 이 숲에는 고슴도치가 한 마리 살고 있다. 고슴도치는 제 www.acmicpc.net import sys from collections import deque if __name__ == '__main__': n, m = map(int, sys.stdin.readline().rstrip().split()) t_ddup_forest = [] hedgehog_pos = [] water_pos = deque() current_pos = [[False] * m for _ in range(n)] for i in ran..

백준 아기 상어 파이썬

www.acmicpc.net/problem/16236 16236번: 아기 상어 N×N 크기의 공간에 물고기 M마리와 아기 상어 1마리가 있다. 공간은 1×1 크기의 정사각형 칸으로 나누어져 있다. 한 칸에는 물고기가 최대 1마리 존재한다. 아기 상어와 물고기는 모두 크기를 가 www.acmicpc.net import sys from collections import deque sys.setrecursionlimit(10000) if __name__ == '__main__': n = int(sys.stdin.readline().rstrip()) sea = [] eatable = False baby_shark = 9 shark_size = 2 shark_pos = [] for i in range(n): nu..

백준 구슬탈출2 파이썬

www.acmicpc.net/problem/13460 13460번: 구슬 탈출 2 첫 번째 줄에는 보드의 세로, 가로 크기를 의미하는 두 정수 N, M (3 ≤ N, M ≤ 10)이 주어진다. 다음 N개의 줄에 보드의 모양을 나타내는 길이 M의 문자열이 주어진다. 이 문자열은 '.', '#', 'O', 'R', 'B' www.acmicpc.net import sys from collections import deque sys.setrecursionlimit(10000) if __name__ == '__main__': N, M = map(int, sys.stdin.readline().rstrip().split()) ball_start_pos = {} graph = [] for i in range(N): d..

백준 2206 벽 부수고 이동하기 파이썬

www.acmicpc.net/problem/2206 2206번: 벽 부수고 이동하기 N×M의 행렬로 표현되는 맵이 있다. 맵에서 0은 이동할 수 있는 곳을 나타내고, 1은 이동할 수 없는 벽이 있는 곳을 나타낸다. 당신은 (1, 1)에서 (N, M)의 위치까지 이동하려 하는데, 이때 최단 경로 www.acmicpc.net import sys from collections import deque sys.setrecursionlimit(10000) if __name__ == '__main__': N, M = map(int, sys.stdin.readline().rstrip('\n').split()) graph = [] wall_points = [] for i in range(N): l = list(sys.s..

백준 7569 토마토 파이썬

www.acmicpc.net/problem/7569 7569번: 토마토 첫 줄에는 상자의 크기를 나타내는 두 정수 M,N과 쌓아올려지는 상자의 수를 나타내는 H가 주어진다. M은 상자의 가로 칸의 수, N은 상자의 세로 칸의 수를 나타낸다. 단, 2 ≤ M ≤ 100, 2 ≤ N ≤ 100, www.acmicpc.net import sys from collections import deque sys.setrecursionlimit(10003) if __name__ == '__main__': M, N, H = map(int, sys.stdin.readline().rstrip().split()) graph = [] well_tomato_q = deque() all_well_flag = True for i i..

백준 2468 안전 영역 파이썬

www.acmicpc.net/problem/2468 2468번: 안전 영역 재난방재청에서는 많은 비가 내리는 장마철에 대비해서 다음과 같은 일을 계획하고 있다. 먼저 어떤 지역의 높이 정보를 파악한다. 그 다음에 그 지역에 많은 비가 내렸을 때 물에 잠기지 않는 www.acmicpc.net import sys import copy sys.setrecursionlimit(10003) if __name__ == '__main__': N = int(sys.stdin.readline().rstrip()) graph = [] rains = set() for i in range(N): point = list(map(int, sys.stdin.readline().rstrip().split())) graph.appen..

백준 14502 연구소 파이썬

www.acmicpc.net/problem/14502 14502번: 연구소 인체에 치명적인 바이러스를 연구하던 연구소에서 바이러스가 유출되었다. 다행히 바이러스는 아직 퍼지지 않았고, 바이러스의 확산을 막기 위해서 연구소에 벽을 세우려고 한다. 연구소는 크 www.acmicpc.net import copy import sys import itertools from collections import deque if __name__ == '__main__': N, M = map(int, sys.stdin.readline().split()) graph = [] for _ in range(N): graph.append(list(map(int, sys.stdin.readline().split()))) all_wa..

백준 1260 DFS와 BFS

www.acmicpc.net/problem/1260 1260번: DFS와 BFS 첫째 줄에 정점의 개수 N(1 ≤ N ≤ 1,000), 간선의 개수 M(1 ≤ M ≤ 10,000), 탐색을 시작할 정점의 번호 V가 주어진다. 다음 M개의 줄에는 간선이 연결하는 두 정점의 번호가 주어진다. 어떤 두 정점 사 www.acmicpc.net from collections import deque N, M, V = map(int, input().split()) graph = [[] for _ in range(N+1)] for _ in range(M): a, b = map(int, input().split()) graph[a].append(b) graph[a].sort() graph[b].append(a) graph..

백준 1826 연료 채우기 파이썬

www.acmicpc.net/problem/1826 1826번: 연료 채우기 첫째 줄에 주유소의 개수 N(1 ≤ N ≤ 10,000)가 주어지고 두 번째 줄부터 N+1번째 줄 까지 주유소의 정보가 주어진다. 주유소의 정보는 두개의 정수 a,b로 이루어 져 있는데 a(1 ≤ a ≤ 1,000,000)는 성경 www.acmicpc.net import heapq N = int(input()) gas_stations = [] for _ in range(N): # 주유소까지의 거리, 채울수 있는 연료의 양 a, b = map(int, input().split()) heapq.heappush(gas_stations, (a, -b)) town_distance, my_gas = map(int, input().split..

백준 5545 최고의피자 파이썬

www.acmicpc.net/problem/5545 5545번: 최고의 피자 첫째 줄에 토핑의 종류의 수 N(1 ≤ N ≤ 100)이 주어진다. 둘째 줄에는 도우의 가격 A와 토핑의 가격 B가 주어진다. (1 ≤ A, B ≤ 1000) 셋째 줄에는 도우의 열량 C가 주어진다. (1 ≤ C ≤ 10000) 다음 줄 www.acmicpc.net N = int(input()) A, B = map(int, input().split()) C = int(input()) D = [] for _ in range(N): D.append(int(input())) D.sort(reverse=True) current_price = A current_calories = C max_calories = C / A for topin..