728x90
https://www.acmicpc.net/problem/1862
1862번: 미터계
첫째 줄에 미터계에 표시된 거리가 주어진다. 단, 이 거리는 정수이고, 1 이상 999,999,999 이하이다.
www.acmicpc.net
# 시간초과
- 1부터 직접 계산
n = int(input())
data = [0]
result = 0
for i in range(1, n+1):
result += 1
for j in range(len(str(result))):
if str(result)[j] == '4':
result += 10 ** (len(str(result))-j-1)
data.append(result)
print(data.index(n))
# 찾아봄
n = int(input())
result = 0
for i in range(len(str(n))):
d = n%10
n = n//10
if d > 4:
result += (d-1) * (9**i)
else:
result += d * (9**i)
print(result)
- 9진법..?
반응형
'전.py' 카테고리의 다른 글
[python] 백준 11399 ATM (0) | 2022.04.05 |
---|---|
[python] 백준 4375 1 (0) | 2022.03.31 |
[python] 그래프 이론 (0) | 2022.03.10 |
[python] 미래도시 (최단 경로) (0) | 2022.03.07 |
[python] 전보 (최단 경로) (0) | 2022.03.07 |