*문제 출처는 백준에 있습니다.
문제 제목: 리모컨 / 1107번 (골드 4단계)
문제 사이트: https://www.acmicpc.net/problem/1107
문제 설명

나의 풀이
def solution(channel, usable_buttons):
min_clicks = abs(channel - 100) # 초기값: +,- 버튼만 사용
for num in range(1000000): # 0부터 999999까지 전체 탐색
str_num = str(num)
for ch in str_num:
if int(ch) not in usable_buttons:
break
else:
# 이 숫자는 리모컨으로 누를 수 있음
press_count = len(str_num) + abs(channel - num)
min_clicks = min(min_clicks, press_count)
return min_clicks
def main():
channel = int(input())
breakdown = int(input())
# usable_button = 누를 수 있는 번호
# broken_buttons = 부서진 번호
if breakdown:
broken_buttons = list(map(int, input().split()))
usable_buttons = [i for i in range(10) if i not in broken_buttons]
else:
usable_buttons = list(range(10))
print(solution(channel, usable_buttons))
if __name__=="__main__":
main()

※ 알아야 할 것
완전탐색을 이용해서 문제를 해결하셔야 합니다!
'Coding Test > 백준-Python' 카테고리의 다른 글
| 백준 / 킥다운 / 1195번 / Python (0) | 2025.06.02 |
|---|---|
| 백준 / 스택 수열 / 1874번 / Python (0) | 2025.06.02 |
| 백준 / 네트워크 연결 / 1922번 / Python (0) | 2025.05.27 |
| 백준 / 가장 긴 감소하는 부분 수열 / 11722번 / Python (0) | 2025.05.27 |
| 백준 / 연산자 끼워넣기 (2) / 15658번 / Python (0) | 2025.05.25 |