250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- openai api
- 프랑스 남부 섬
- 군대
- 24524
- 시뮬레이션
- 백준 C++
- 군대코딩
- 그린델발트 자전거
- porquerolles
- 로이커바트 숙소
- 16236 c++
- 로이커바트
- 융프라우 스위스 패스
- 코딩
- 1654
- 백준으로 c++ 공부하기
- 군인
- iles dHyeres
- C++
- 대학생
- 그린델발트 캠핑장
- 알고리즘
- 백준
- 피르스트 자전거
- auto code review
- 백준으로 C++ 공부
- C++ 공부
- 오리스프
- C++ 공부하기
- Replit
Archives
- Today
- Total
기억보다는 기록을 해볼까
리모콘 1107 (백준으로 C++ 공부하기 28일차) 본문
728x90
처음에 브루트포스로 안풀었더니 시간초과가 나와서 검색을 동원해 결국 브루트포스로 풀었다.
아래는 브루트포스로 푼게 아닌 답이다.
#include <iostream>
#include <string>
using namespace std;
int main() {
int n; cin >> n;
int m; cin >> m;
bool arr[10];
for(int i = 0; i < m; i++) {
int a; cin >> a;
arr[a] = true;
}
if(n == 100) {
cout << "0";
return 0;
}
int minNum = abs(n - 100);
int cur = n;
int plus;
while(1) {
bool no = false;
plus = cur;
string str = to_string(plus);
for(int i = 0; i < str.size(); i++) {
if(arr[str[i] - 48] == true) {
no = true;
}
}
if(no == true) {
cur++;
}
else break;
}
cur = n;
int minus;
while(1) {
bool no = false;
minus = cur;
string str = to_string(minus);
for(int i = 0; i < str.size(); i++) {
if(arr[str[i] - 48] == true) {
no = true;
}
}
if(no == true) {
cur--;
}
else break;
}
int diff = min(plus - n, n - minus);
int tmp = n;
string str = to_string(tmp);
int p = str.length() + diff;
int ans = min(p, minNum);
cout << ans;
}
728x90
'백준으로 C++ 공부하기' 카테고리의 다른 글
N과 M (2) 15650 (백준으로 c++ 공부하기 30일차) (0) | 2021.12.11 |
---|---|
좌표 압축 18870 (백준으로 C++ 공부 29일차) (0) | 2021.12.10 |
적록색약 10026 (백준으로 C++ 공부하기 27일차) (0) | 2021.12.08 |
DSLR 9019 (백준으로 C++공부하기 26일차) (0) | 2021.12.07 |
백준으로 C++ 공부 25일차 (5430) (0) | 2021.12.06 |
Comments