코테 대비 python/백준
-
1260 dfs bfs코테 대비 python/백준 2023. 3. 7. 14:57
https://www.acmicpc.net/problem/1260 1260번: DFS와 BFS 첫째 줄에 정점의 개수 N(1 ≤ N ≤ 1,000), 간선의 개수 M(1 ≤ M ≤ 10,000), 탐색을 시작할 정점의 번호 V가 주어진다. 다음 M개의 줄에는 간선이 연결하는 두 정점의 번호가 주어진다. 어떤 두 정점 사 www.acmicpc.net import sys from collections import deque input = sys.stdin.readline n,m,v = list(map(int,input().split())) adj = [[] for _ in range(n+1)] for _ in range(m): x,y = list(map(int,input().split())) adj[x].a..
-
17086 아기상어2코테 대비 python/백준 2023. 3. 7. 11:08
https://www.acmicpc.net/problem/17086 17086번: 아기 상어 2 첫째 줄에 공간의 크기 N과 M(2 ≤ N, M ≤ 50)이 주어진다. 둘째 줄부터 N개의 줄에 공간의 상태가 주어지며, 0은 빈 칸, 1은 아기 상어가 있는 칸이다. 빈 칸과 상어의 수가 각각 한 개 이상인 입력만 www.acmicpc.net from collections import deque n,m = map(int,input().split()) graph = [] for _ in range(n): graph.append(list(map(int,input().split()))) #상어 있는 곳에서 가장 가까운 상어까지 거리 구하면됨 #그 구한 거리중에서 가장 작은거 구하면됨 #상하좌우 상우 상좌 하우 하..
-
1743 음식물 피하기 bfs코테 대비 python/백준 2023. 2. 27. 18:25
https://www.acmicpc.net/problem/1743 1743번: 음식물 피하기 첫째 줄에 통로의 세로 길이 N(1 ≤ N ≤ 100)과 가로 길이 M(1 ≤ M ≤ 100) 그리고 음식물 쓰레기의 개수 K(1 ≤ K ≤ N×M)이 주어진다. 그리고 다음 K개의 줄에 음식물이 떨어진 좌표 (r, c)가 주어진다 www.acmicpc.net from collections import deque n,m,k = map(int,input().split()) #그래프 표기 graph = [[0]*m for _ in range(n)] #그래프에 칸 채우기 for _ in range(k): r,c = map(int,input().split()) graph[r-1][c-1]=1 #print(graph) #..
-
2583 영역 구하기 bfs코테 대비 python/백준 2023. 2. 27. 12:52
https://www.acmicpc.net/problem/2583 2583번: 영역 구하기 첫째 줄에 M과 N, 그리고 K가 빈칸을 사이에 두고 차례로 주어진다. M, N, K는 모두 100 이하의 자연수이다. 둘째 줄부터 K개의 줄에는 한 줄에 하나씩 직사각형의 왼쪽 아래 꼭짓점의 x, y좌표값과 오 www.acmicpc.net from collections import deque m,n,k = map(int,input().split()) #그래프 표기 graph = [[0]*n for _ in range(m)] #그래프에 칸 채우기 for _ in range(k): x1,y1,x2,y2 = map(int,input().split()) for i in range(x1,x2): #매트릭스에 맞게 좌표 다..
-
11279 최대 힙코테 대비 python/백준 2023. 2. 18. 00:25
https://www.acmicpc.net/problem/11279 11279번: 최대 힙 첫째 줄에 연산의 개수 N(1 ≤ N ≤ 100,000)이 주어진다. 다음 N개의 줄에는 연산에 대한 정보를 나타내는 정수 x가 주어진다. 만약 x가 자연수라면 배열에 x라는 값을 넣는(추가하는) 연산이고, x가 0 www.acmicpc.net # BOJ_S2_11279_최대 힙[2023-02-17] 문제 : https://www.acmicpc.net/problem/11279 ``` 1. 최대힙 구현 heappush(heap,-num) 2. heappush, heappop ``` ```python import heapq import sys input = sys.stdin.readline n = int(input()..
-
22942 데이터 체커 - 스택코테 대비 python/백준 2023. 2. 12. 08:51
https://www.acmicpc.net/problem/22942 22942번: 데이터 체커 데이터가 조건에 맞는다면 YES, 조건에 만족하지 않는다면 NO를 출력한다. www.acmicpc.net import sys input = sys.stdin.readline n = int(input().rstrip()) circles = [] for i in range(n): x, r = map(int, input().split()) circles.append((x - r, i, 0)) circles.append((x + r, i, 1)) circles.sort() stack = [] crds = set() for crd, i, flag in circles: if crd in crds: print("NO") b..
-
2504 괄호의 값 - 스택코테 대비 python/백준 2023. 2. 12. 08:31
https://www.acmicpc.net/problem/2504 2504번: 괄호의 값 4개의 기호 ‘(’, ‘)’, ‘[’, ‘]’를 이용해서 만들어지는 괄호열 중에서 올바른 괄호열이란 다음과 같이 정의된다. 한 쌍의 괄호로만 이루어진 ‘()’와 ‘[]’는 올바른 괄호열이다. 만일 X www.acmicpc.net s = list(input()) stack = [] res = 1 result = 0 # 1~4번째 과정 시작 for i in range(len(s)): if s[i]=='(': res *= 2 stack.append(s[i]) elif s[i]=='[': res *= 3 stack.append(s[i]) elif s[i]==')': if not stack or stack[-1]!='(': ..
-
10989 수 정렬하기 정렬 잡기술코테 대비 python/백준 2023. 2. 6. 20:35
https://www.acmicpc.net/problem/10989 10989번: 수 정렬하기 3 첫째 줄에 수의 개수 N(1 ≤ N ≤ 10,000,000)이 주어진다. 둘째 줄부터 N개의 줄에는 수가 주어진다. 이 수는 10,000보다 작거나 같은 자연수이다. www.acmicpc.net import sys n = int(sys.stdin.readline()) num_list = [0] * 10001 for _ in range(n): num_list[int(sys.stdin.readline())] += 1 for i in range(10001): if num_list[i] != 0: for j in range(num_list[i]): print(i) append를 사용하면 메모리 재할당문제로 효율이 ..