※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 25871번 문제인 Historical TV Remote Control이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/25871
25871번: Historical TV Remote Control
As Dr. Orooji is getting older, he is becoming more attached to older items and has difficulty letting go of them (he claims they have historical value). For example, he still has the first table he got for the programming team! The situation is the same a
www.acmicpc.net
0부터 999까지의 채널을 각각 살펴보면서 (1)해당 채널이 현재 사용가능한 숫자 버튼으로 만들 수 있는지 확인 후 (2) 만들 수 있다면 채널업 버튼과 채널다운 버튼을 최소 몇번 눌러야 해당 채널에서 원하는 채널로 이동할 수 있는지를 구하자. 이 값의 최솟값이 문제의 답이 된다.
살펴볼 후보가 1000가지로 매우 적으므로, 위와 같은 완전탐색으로 충분히 문제를 해결할 수 있다.
아래는 제출한 소스코드이다.
#include <iostream>
#include <string>
using namespace std;
bool broken[128];
int ans = 1000000007;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N; cin >> N;
while (N--) {
char x; cin >> x;
broken[x] = 1;
}
cin >> N;
for (int i = 0; i < 1000; i++) {
string s = to_string(i);
bool pass = 0;
for (auto& l : s) {
if (broken[l]) pass = 1;
}
if (pass) continue;
ans = min(ans, abs(N - i));
}
cout << ans;
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 25915 // C++] 연세여 사랑한다 (0) | 2022.11.08 |
---|---|
[BOJ 25935 // C++] Lemonade Stand (0) | 2022.11.08 |
[BOJ 25904 // C++] 안녕 클레오파트라 세상에서 제일가는 포테이토칩 (0) | 2022.11.08 |
[BOJ 25841 // C++] Digit Count (0) | 2022.11.08 |
[BOJ 25840 // C++] Sharing Birthdays (0) | 2022.11.08 |