ํฐ์คํ ๋ฆฌ ๋ทฐ
๋ฐฑ์ค 1107๋ฒ ๋ฆฌ๋ชจ์ปจ ๋ฌธ์ ์ ๋๋ค
ํ์ฌ ์ฑ๋์ 100๋ฒ์ด๊ณ
๋ฆฌ๋ชจ์ปจ์๋ +, -, 0 ~ 9 ๋ฒํผ์ด ์์ต๋๋ค.
์ ์ถ๋ ฅ์ ๋๋ค.
์ด๋ ๊ฒ ๊ณ ์ฅ๋ ๋ฒํผ๊ณผ ๋ชฉํ์ฑ๋์ ์ ๋ ฅ์ผ๋ก ๋ฐ์ต๋๋ค
์ ๋ฒํผ๋ค์ ์ด์ฉํ์ฌ ์ต์ ํ์๋ก ๋ชฉํ ์ฑ๋๋ก ๊ฐ๋ ์๋ฅผ ๊ตฌํ๋ ๋ฌธ์ ์ ๋๋ค
์๊ณ ๋ฆฌ์ฆ ๋ถ๋ฅ๋ brute force ์ ๋๋ค
---------------------------------------------------------------------------------------------------------------------------------------
์ ์ ํ์ด๋ฐฉ๋ฒ์ ๋๋ค.
1. ์ซ์ ๋ฒํผ์ผ๋ก ํน์ ์ฑ๋๋ก ๊ฐ ๋ค์์ +๋๋ - ๋ก ์ด๋ํ๋ ๋ฐฉ๋ฒ
2. + ๋๋ - ๋ง์ผ๋ก ๋ชฉํ ์ฑ๋๊น์ง ๊ฐ๋ ๋ฐฉ๋ฒ
์ด๋ ๊ฒ ๋๊ฐ์ง๋ก ๋ถ๋ฅํ๊ณ ์ด ๊ฐ๋ค์ค์์ ์ต์๊ฐ์ ์ถ๋ ฅํ๋ ค๊ณ ํฉ๋๋ค
์ฒซ์งธ ๋ฐฉ๋ฒ์
๋ชฉํ ์ฑ๋์์ +1 ๋๋ -1 ํ์ฌ ํด๋น ์ฑ๋์ ์ซ์๋ค์ด ๋๋ฅผ์ ์๋ ๋ฒํผ์ผ๋ก ๊ตฌ์ฑ๋์ด์๋์ง ํ์ธํฉ๋๋ค.
ํด๋น ์ฑ๋ ์ซ์๋ค์ด ๋ชจ๋ ๋๋ฅผ์ ์๋ ๋ฒํผ์ผ ๊ฒฝ์ฐ
+1 ๋๋ -1 ํ ํ์์ ํด๋น ์ฑ๋์ ์ซ์ ์๋ฅผ ๋ํ ๊ฐ์ ๊ฐ์ ธ์ต๋๋ค.
๊ทธ๋ฌ๋ฉด ๋ ๊ฐ์ง ๊ฐ์ ๋ฐํํฉ๋๋ค. +์ผ ๊ฒฝ์ฐ, - ์ผ ๊ฒฝ์ฐ
๋๋ฒ์งธ ๋ฐฉ๋ฒ์
๋ชฉํ ์ฑ๋๊ณผ ํ์ฌ ์ฑ๋์ ์ฐจ์ด๊ฐ abs(targetNum - 100) ์ด๋ ๊ฒ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค.
์ด๋ ๊ฒ ์ด 3๊ฐ์ง(plus count, minus count, abs๊ฐ)์ ๊ฐ ๊ฐ์ฅ ์ ์ ๊ฐ์ ์ถ๋ ฅํด์ฃผ์์ต๋๋ค.
์๋๋ python ์ฝ๋์ ๋๋ค
import sys
import math
# ํด๋น ์ฑ๋์ ์ซ์๋ค์ด ๋๋ฅผ์ ์๋ ๋ฒํผ์ผ๋ก ๊ตฌ์ฑ๋์ด์๋์ง ํ์ธํ๋ ํจ์
def validation(num,ableBtns):
if num < 0: return False
numArray = list(map(int,str(num)))
isContains: bool = True
for i in numArray:
if i not in ableBtns:
isContains = False
return isContains
targetNum = int(input())
inputCnt = int(input())
if inputCnt > 0:
disableBtns = list(map(int,sys.stdin.readline().rstrip().split()))
else:
disableBtns = []
plusTargetNum: int = targetNum
minusTargetNum: int = targetNum
minusCnt = math.inf
plusCnt = math.inf
allBtns = [0,1,2,3,4,5,6,7,8,9]
ableBtns = [x for x in allBtns if x not in disableBtns]
answer = abs(targetNum - 100)
while 1:
if len(ableBtns) == 0: break
if validation(minusTargetNum, ableBtns):
minusCnt = list(map(int,str(minusTargetNum)))
minusCnt = (targetNum - minusTargetNum) + len(minusCnt)
break
elif validation(plusTargetNum, ableBtns):
plusCnt = list(map(int,str(plusTargetNum)))
plusCnt = (plusTargetNum - targetNum) + len(plusCnt)
break
minusTargetNum -= 1
plusTargetNum += 1
print(min(minusCnt,plusCnt,answer))
์ ๋์ํ๋ ๋ชจ์ต
๊ฐ์ฌํฉ๋๋ค
์ถ๊ฐ์ ์ผ๋ก ๋ฐฑ์ค์์ ์์งํ ๋ฐ๋ก ๋ชจ์์ง์ ๋๋ค.
10
9
1 2 3 4 5 6 7 8 9
๋ต:11
101
0
๋ต:1
99
10
0 1 2 3 4 5 6 7 8 9
๋ต:1
0
0
๋ต:1
500000
6
0 1 2 3 4 5
๋ต:166672
0
2
0 1
๋ต:3
1555
8
0 1 3 4 5 6 7 9
๋ต:670
944
7
2 3 4 5 6 7 9
๋ต:59
6
9
0 2 3 4 5 6 7 8 9
๋ต:6
500000
10
0 1 2 3 4 5 6 7 8 9
๋ต:499900
101
10
0 1 2 3 4 5 6 7 8 9
๋ต:1
1
9
1 2 3 4 5 6 7 8 9
๋ต:2
99999
1
9
๋ต:7
10
1
0
๋ต:2
0
3
0 1 2
๋ต:4
0
9
0 1 2 3 4 5 6 7 8
๋ต:10
0
10
0 1 2 3 4 5 6 7 8 9
๋ต:100
1
9
1 2 3 4 5 6 7 8 9
๋ต:2
1020
0
๋ต:4
10
2
0 1
๋ต:2
999
1
9
๋ต:5
9990
8
1 2 3 4 5 6 7 8
๋ต:4
123
2
2 3
๋ต:7
199
1
9
๋ต:4
9
5
9 8 7 6 5
๋ต:3
19
1
1
๋ต:3
//gkfkagkfka12๋์ด ์ถ๊ฐํด์ฃผ์ TC
5959
4
1 2 3 4
4
-----------------------------------------------
56666
0
5
-----------------------------------------------
9999
8
0 1 2 3 4 5 6 7
4
-----------------------------------------------
10
1
1
2
-----------------------------------------------
190000
3
1 2 9
101117
-----------------------------------------------
123
3
1 2 5
23
-----------------------------------------------
1
9
0 1 2 3 4 5 6 7 8
9
-----------------------------------------------
100
10
0 1 2 3 4 5 6 7 8 9
0
-----------------------------------------------
99933
2
3 9
73
-----------------------------------------------
1023
5
1 2 3 4 0
27
-----------------------------------------------
91010
2
1 0
1016
-----------------------------------------------
383399
6
1 2 3 4 5 7
216607
-----------------------------------------------
6711
2
1 2
6
-----------------------------------------------
330
4
0 1 2 3
117
-----------------------------------------------
71923
5
4 5 6 7 9
8082
-----------------------------------------------
123123
3
1 2 3
23129
-----------------------------------------------
499999
2
4 8
7
-----------------------------------------------
1111
9
1 2 3 4 5 6 7 8 9
1011
-----------------------------------------------
1111
9
0 1 2 3 4 5 6 7 8
115
-----------------------------------------------
34311
8
0 1 2 3 4 5 6 7
24316
-----------------------------------------------
49445
7
1 2 3 4 5 6 7
30560
-----------------------------------------------
933
2
1 2
3
-----------------------------------------------
1617
3
1 2 3
621
-----------------------------------------------
856
2
5 6
10
-----------------------------------------------
1023
8
1 2 3 4 5 6 7 8
27
-----------------------------------------------
10900
2
1 0
905
-----------------------------------------------
394344
3
1 2 3
5662
-----------------------------------------------
99
1
8
1
-----------------------------------------------
101
9
0 1 2 3 4 5 6 7 8
1
-----------------------------------------------
2420
6
1 2 3 4 5 6
1424
-----------------------------------------------
991
1
1
4
-----------------------------------------------
30002
3
1 3 4
8
-----------------------------------------------
1698
2
6 9
6
-----------------------------------------------
499998
3
4 8 9
8
-----------------------------------------------
1022
5
1 2 3 4 5
26
-----------------------------------------------
5
10
0 1 2 3 4 5 6 7 8 9
ans95
217
7
0 1 2 4 5 7 8
ans117
---
103
5
2 3 5 7 8
ans3
0
9
1 2 3 4 5 6 7 8 9
ans 1
0
9
1 2 3 4 5 6 7 8 0
ans 10
9
9
1 2 3 4 5 6 7 8 0
ans 1
140200
3
4 5 6
ans 207
1555
3
0 1 9
ans 670
99999
9
0 2 3 4 5 6 7 8 9
ans 11118
50000
9
0 1 2 3 4 5 6 7 8
ans 40005
139133
7
9 6 8 2 1 5 7
ans 94694
14
2
1 5
ans 6
889
9
0 2 3 4 5 6 7 8 9
ans 226
6
7
3 4 5 6 7 8 9
ans 5
88
2
8 9
ans 12
7
7
3 4 5 6 7 8 9
ans 5
0
0
ans 1
1
9
0 1 2 3 4 5 6 7 8
ans 9
1705
2
6 7
์ ๋ต : 99
1717
1
7
์ ๋ต : 22
2
8
1 2 3 4 5 6 7 8
์ ๋ต: 3
2
7
1 2 3 4 6 8 9
์ ๋ต: 3
1
8
1 2 3 4 5 6 7 8
์ ๋ต: 2
1
7
1 2 4 5 7 8 9
์ ๋ต: 2
1555
8
0 1 3 4 5 6 7 9
670
101
3
4 5 6
1
162
9
0 1 3 4 5 6 7 8 9
62
10
9
1 2 3 4 5 6 7 8 9
11
1
10
0 1 2 3 4 5 6 7 8 9
99
1
1
1
2
0
9
1 2 3 4 5 6 7 8 9
1
101
0
1
100000
9
0 1 2 3 4 5 6 7 8
6
1
10
0 1 2 3 4 5 6 7 8 9
99
1111
9
1 2 3 4 5 6 7 8 9
1011
2229
6
4 5 6 7 8 9
5
10
1
0
2
0
10
0 1 2 3 4 5 6 7 8 9
100
9
8
0 3 4 5 6 7 8 9
4
0
3
0 1 2
4
99999
9
0 2 3 4 5 6 7 8 9
๋ต : 11118
50000
9
0 1 2 3 4 5 6 7 8
๋ต : 40005
9
9
1 2 3 4 5 6 7 8 9
๋ต : 10
- Total
- Today
- Yesterday
- swift ์์ ์ฝ๊ธฐ
- focus timer ์ดํ
- ๋ ๋์ธ์ด ์ดํ
- swift queryitem encode
- swift urlsession module
- readysay
- swift ์์ ๊ฐ์ ธ์ค๊ธฐ
- rag llm pdf
- llm pdf rag
- rag ๊ธฐ๋ฐ llm ์ฑ๋ด
- swift filemanager excel
- swift ๋คํธ์ํฌ ๋ชจ๋ํ
- swift urlcomponent encode
- swift urlsession network module
- swift excel read
- filemanager excel read
- ๋ ๋์ธ์ด
- swift network module
- ์๋์ํํธ ๋ ์ด์ธ์ด
- ๊ณต๋ถ ํ์ด๋จธ ์ดํ
- rag ๊ธฐ๋ฐ llm
- swift ์๊ฐ
- swift urlsession refactoring
- chatgpt rag llm
- swift network ๊ณตํตํ
- swift filemanager get excel
- swift urlsession ๊ณตํตํ
- swift network refactoring
- swift get excel
- llm csv
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |