반응형
//리모컨_1107.cpp - success
#include<iostream>
using namespace std;
bool broke[10];
int possible(int c) {
if (c == 0) {
return broke[0] ? 0 : 1;
}
int len = 0;
while (c > 0) {
if (broke[c % 10]) return 0;
len += 1;
c /= 10;
}
return len;
}
int main() {
int n, m, N;
cin >> n >> m;
int key;
for (int i = 0; i < m; i++) {
cin >> key;
broke[key] = true;
}
int ans = abs(n - 100);
for (int i = 0; i <= 1000000; i++) {
int c = i;
int len = possible(c);
if (len > 0) {
int press = abs(c - n);
if (ans > len + press) {
ans = len + press;
}
}
}
cout << ans << '\n';
return 0;
}
반응형
'개발(Dev) 이야기 > Algorithm' 카테고리의 다른 글
[BOJ] BFS, DFS 구현 방법 (0) | 2020.03.22 |
---|---|
[BOJ] 카잉달력_6064.cpp (0) | 2020.03.20 |
[BOJ] N과M(6)_15655.cpp (0) | 2020.03.17 |
[BOJ] N과M(5)_15654.cpp (0) | 2020.03.17 |
[BOJ] N과M(4)_15652.cpp (0) | 2020.03.17 |