[백준 1107번] 리모컨
2017. 7. 23. 21:52ㆍ알고리즘/백준
반응형
소스코드
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 32 33 34 35 36 37 38 39 | #include <iostream> using namespace std; int n, m, broke[10] = {0,}; int main() { cin >> n >> m; for (int i = 0; i < m; i++) { int a; cin >> a; broke[a] = 1; } int Min = (n - 100)<0 ? -1*(n-100) : n-100; for (int i = 0; i <= 1000000; i++) { int channel = i; int leng = 0; bool flag = false; // 채널의 자릿수를 구해서 누를수있는지 판별 누를수있으면 Min값이랑 비교 while (1) { if (broke[channel % 10]) break; else { channel /= 10; leng++; if (channel == 0) { flag = true; break; } } } if (flag) { int result = (n - i) < 0 ? -1 * (n - i) : n - i; if (result + leng < Min) Min = result + leng; } } cout << Min << '\n'; return 0; } | cs |
반응형
'알고리즘 > 백준' 카테고리의 다른 글
[백준 1963번] 소수 경로 (0) | 2017.07.24 |
---|---|
[백준 10819번] 차이를 최대로 (0) | 2017.07.23 |
[백준 5397번] 키로거 (0) | 2017.07.23 |
[백준 2467번] 용액 (0) | 2017.07.23 |
[백준 10971번] 외판원 순회 2 (0) | 2017.07.23 |