일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
- 문자열
- 슬라이딩 윈도우
- 누적 합
- 세그먼트 트리
- 트리
- Python
- 그래프
- 정수론
- 그리디
- 수학
- 13164
- 애드 혹
- 에라토스테네스의 체
- 맵
- 이분 탐색
- boj
- 모던 JavaScript 튜토리얼
- 싸피
- 구현
- 2357
- SSAFY
- BFS
- 정렬
- DP
- 브루트포스
- 플로이드-워셜
- 해시 테이블
- 투 포인터
- JavaScript
- DFS
- Today
- Total
목록이분 탐색 (3)
흙금이네 블로그

아이디어 #1 맵을 이용하여 이동 가능한 좌표를 찾아 BFS하여 최소 이동 횟수를 구한다. 풀이 #1 (Python) 파이썬에서는 딕셔너리로 맵을 이용할 수 있다. import sys input = sys.stdin.readline def solution(): n, T = map(int, input().split()) pos = dict() for _ in range(n): x, y = map(int, input().split()) pos[(x, y)] = -1 queue = [(0, 0)] while queue: x, y = queue.pop(0) if y >= T: print(pos.get((x, y), 0)) return for nx in range(x-2, x+3): for ny in range(..

아이디어 매개 변수 탐색으로 휴게소가 없는 최대 구간의 최솟값을 구해 나간다. 풀이 휴게소가 없는 구간의 길이를 리스트 D에 저장한 후, 최대 m 길이의 구간마다 휴게소가 위치할 수 있는지 확인한다. def solution(): N, M, L = map(int, input().split()) pos = [0]+list(map(int, input().split()))+[L] pos.sort() D = [] for i in range(N+1): D.append(pos[i+1]-pos[i]) D.sort(reverse=True) s = 1 e = D[0] while s M: s = m+1 else: e = m-1 print(s) solution()

아이디어 이분 탐색으로 잘못 칠해진 칸을 모두 가릴 수 있는 가장 작은 색종이 크기를 구한다. 풀이 모든 색종이는 반드시 도화지 밑변에 맞추어 붙이므로 색종이 크기는 잘못 칠해진 칸 행의 최댓값부터 시작한다. import sys input = sys.stdin.readline def solution(): R, C = map(int, input().split()) N = int(input()) M = int(input()) wrong = [] s = 0 for _ in range(M): r, c = map(int, input().split()) wrong.append(c) if s < r: s = r wrong.sort() e = max(s, R, C) while s last: last = c+m-1 cn..