https://www.acmicpc.net/problem/1107
1107번: 리모컨
첫째 줄에 수빈이가 이동하려고 하는 채널 N (0 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 고장난 버튼의 개수 M (0 ≤ M ≤ 10)이 주어진다. 고장난 버튼이 있는 경우에는 셋째 줄에는 고장난 버튼��
www.acmicpc.net
N = int(input())
M = int(input())
if M != 0:
B = list(input().split())
else:
B = []
R = [str(i) for i in range(10) if str(i) not in B]
result = abs(N - 100)
for i in range(1000000):
tf = True
for s in str(i):
if s not in R:
tf = False
break
if tf:
result = min(result, abs(N - i)+len(str(i)))
print(result)
'알고리즘 > 백준 (Pyhthon)' 카테고리의 다른 글
[알고리즘] 백준 10974 모든 순열 / python, 순열 (0) | 2020.06.20 |
---|---|
[알고리즘] 백준 1748 수 이어 쓰기 / python (0) | 2020.06.17 |
[알고리즘] 백준 1439 뒤집기 / python, greedy (0) | 2020.06.14 |
[알고리즘] 백준 11055 가장 큰 증가 부분 수열 / python, dp (0) | 2020.06.13 |
[알고리즘] 백준 16768 Mooyo Mooyo / python, dfs, simulation (0) | 2020.06.10 |