일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 싸피
- 에라토스테네스의 체
- 이분 탐색
- 모던 JavaScript 튜토리얼
- 구현
- 2357
- 플로이드-워셜
- 정렬
- DP
- 누적 합
- 세그먼트 트리
- 그리디
- DFS
- BFS
- 맵
- 13164
- 브루트포스
- SSAFY
- 문자열
- 슬라이딩 윈도우
- JavaScript
- 투 포인터
- 그래프
- Python
- 애드 혹
- boj
- 해시 테이블
- 수학
- 정수론
- 트리
- Today
- Total
목록맵 (5)
흙금이네 블로그

아이디어 BFS와 브루트포스로 돌 2개를 두어 죽일 수 있는 상대 돌의 최대 개수를 구한다. 풀이 #1 (Python) import sys input = sys.stdin.readline def solution(): N, M = map(int, input().split()) board = [list(map(int, input().split())) for _ in range(N)] delta = [(-1, 0), (0, 1), (1, 0), (0, -1)] cnt_dict = dict() pos = set() res = 0 for i in range(N): for j in range(M): if board[i][j] == 2: queue = [(i, j)] board[i][j] = 1 cnt = 0 kil..

아이디어 맵을 이용해 모든 단어들이 순서에 맞게 적혀 있는지 확인한다. 풀이 #1 (Python) import sys input = sys.stdin.readline def solution(): N = int(input()) sentences = [input().split() for _ in range(N)] idx_dict = dict() for i in range(N): idx_dict[sentences[i].pop()] = i L = input().split() while L: word = L.pop() idx = idx_dict.get(word, -1) idx_dict[word] = -1 if idx >= 0: if sentences[idx]: idx_dict[sentences[idx].pop()..

아이디어 맵을 이용하여 단어를 구성하는 알파벳의 순서 패턴을 저장하고 비슷한 문자열 쌍의 개수를 구한다. 풀이 #1 (Python) import sys input = sys.stdin.readline def solution(): N = int(input()) patterns = dict() res = 0 for _ in range(N): word = input().rstrip() alpha = dict() val = 1 p = '' for c in word: if alpha.get(c, 0) == 0: alpha[c] = val val += 1 p += f'{alpha.get(c, 0)}' cnt = patterns.get(p, 0) res += cnt patterns[p] = cnt+1 print(re..

아이디어 맵을 이용해 각 클래스의 부모 클래스 정보를 저장하고, 부모 클래스를 탐색하며 형변환이 가능한지 확인한다. 풀이 #1 (Python) import sys input = sys.stdin.readline def solution(): N = int(input()) tree = dict() for _ in range(N-1): A, B = input().split() tree[A] = B A, B = input().split() a = A while a: a = tree.get(a, '') if a == B: print(1) return b = B while b: b = tree.get(b, '') if b == A: print(1) return print(0) solution() 풀이 #2 (Jav..

아이디어 #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(..