Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- C++
- 코딩
- 자바
- java
- 코딩테스트
- 코테
- 프로그램
- 모의 주식
- Python
- 사물인터넷
- 개인프로젝트
- 자바정리
- 코딩독학
- 주가예측
- 프로그래밍
- backend
- 풀스택프레임워크
- 코스닥
- Project
- java정리
- frontend
- 이웃한 칸
- 프로그래머스
- SNS
- 빅데이터
- Reflex
- 백준
- 자바독학
- 개발자
- 개발
Archives
- Today
- Total
Creative Code
[1107번]리모컨 본문
https://www.acmicpc.net/problem/1107
1107번: 리모컨
첫째 줄에 수빈이가 이동하려고 하는 채널 N (0 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 고장난 버튼의 개수 M (0 ≤ M ≤ 10)이 주어진다. 고장난 버튼이 있는 경우에는 셋째 줄에는 고장난 버튼이
www.acmicpc.net
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
bool arr[11];
int check(int n) {
if (n == 0) {
if (arr[0]) return 0;
else return 1;
}
int len = 0;
while (n > 0) {
if (arr[n % 10]) return 0;
n /= 10;
len++;
}
return len;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x;
cin >> x;
arr[x] = true;
}
int ans = n - 100;
if (ans < 0) ans = -ans;
for (int i = 0; i <= 10000000; i++) {
int c = i;
int len = check(c);
if (len > 0) {
int press = abs(c - n);
if (ans > press + len) {
ans = press + len;
}
}
}
cout << ans;
}
'백준 문제풀이' 카테고리의 다른 글
[2166번]다각형의 면적 (0) | 2023.09.24 |
---|---|
[2096번]내려가기 (0) | 2023.09.24 |
[17214번]다항 함수의 적분 (0) | 2023.09.06 |
[16496번]큰 수 만들기 (0) | 2023.09.06 |
[7869번]두 원 (0) | 2023.09.05 |