브루트포스
14236906 | zl0siwon0lz | 1107 | 맞았습니다!! | 1988 | 44 | C++14 / 수정 | 1528 |
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#include <bits/stdc++.h>
using namespace std;
int len = 0, n, channel, reslen=0;
int arr[11] = { 0, };
int check(int chan, int chklen) {
int div = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < chklen; j++) {
if (chan /div % 10 == arr[i]) {
return 1;
}
else {
div *= 10;
}
}
div = 1;
}
return 2;
}
int findlen(int chan) {
int len = 0;
if (chan == 0)
len = 1;
while (chan > 0) {
chan /= 10;
len++;
}
return len;
}
int main() {
int res = INT_MAX, tmp = 0, tmpres = INT_MAX;
scanf("%d", &channel);
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", &arr[i]);
int pluschan = channel;
int minuschan = channel;
len = findlen(channel);
while (1) {
reslen = findlen(pluschan);
if (check(pluschan, reslen) == 2) {
tmpres = pluschan - channel;
tmpres += reslen;
tmp = 1;
}
else
pluschan++;
reslen = findlen(minuschan);
if (check(minuschan, reslen) == 2 && minuschan >= 0) {
res = channel - minuschan;
res = min(res + reslen, tmpres);
break;
}
else
minuschan--;
if (tmp == 1) {
res = tmpres;
break;
}
if (abs(channel - 100) < pluschan - channel && abs(channel - 100) < channel - minuschan) {
res = abs(channel - 100);
break;
}
}
printf("%d", min(abs(channel - 100), res));
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'Algorithm > Design Paradigm' 카테고리의 다른 글
[BOJ] 1436번 영화감독 숌 (0) | 2019.07.25 |
---|---|
[BOJ] 1018번 체스판 다시 칠하기 (0) | 2019.07.25 |
[BOJ] 7568번 덩치 (0) | 2019.07.25 |
[BOJ] 2231번 분해합 (0) | 2019.07.25 |
[BOJ] 2798번 블랙잭 (0) | 2019.07.25 |