Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Matplotlib
- 완전탐색
- leetcode
- pytorch
- autoencoder
- NaverAItech
- 네이버AItech
- datascience
- 프로그래머스
- torchserve
- Kubernetes
- 코딩테스트
- 백준
- wandb
- DeepLearning
- NLP
- python
- FastAPI
- GCP
- pep8
- docker
- 알고리즘
- FDS
- PytorchLightning
- rnn
- GIT
- github
- vscode
- GitHub Action
- Kaggle
Archives
- Today
- Total
Sangmun
백준 16953번 A -> B 본문
https://www.acmicpc.net/problem/16953
단순히 BFS로 해결이 가능한 문제이다.
import sys
from collections import deque
input = sys.stdin.readline
A, B = map(int,input().split())
que = deque()
que.append((0,A))
result = 0
while que:
cnt, number = que.popleft()
if number >= B:
result = cnt
break
if int(str(number) + '1') <= B:
que.append((cnt+1,int(str(number) + '1')))
if number * 2 <= B:
que.append((cnt+1, number *2))
if result == 0:
print(-1)
else:
print(result + 1)
'알고리즘 > 백준' 카테고리의 다른 글
백준 15686번 치킨 배달 (0) | 2022.12.12 |
---|---|
백준 14938번 서강그라운드 (0) | 2022.12.10 |
백준 1094번 막대기 (0) | 2022.12.07 |
n-queen (0) | 2022.11.29 |
백준 1647번 도시분할 계획 (0) | 2022.11.20 |
Comments