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 | 29 | 30 | 31 |
Tags
- 알고리즘
- 프로그래머스
- 완전탐색
- Kaggle
- docker
- GitHub Action
- FastAPI
- GIT
- NaverAItech
- PytorchLightning
- Kubernetes
- python
- wandb
- torchserve
- DeepLearning
- github
- Matplotlib
- 코딩테스트
- pytorch
- pep8
- rnn
- autoencoder
- 백준
- FDS
- NLP
- GCP
- 네이버AItech
- leetcode
- datascience
- vscode
Archives
- Today
- Total
Sangmun
백준 16953번 A -> B 본문
https://www.acmicpc.net/problem/16953
16953번: A → B
첫째 줄에 A, B (1 ≤ A < B ≤ 109)가 주어진다.
www.acmicpc.net
단순히 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