Daily AtCoder # 43 in Python

Introduction

Last time

#43 Problem

** Thoughts ** I couldn't solve it during the contest. I think this problem is difficult because I can't write the code to generate the run-run numbers. I couldn't write either. According to the commentary, it seems to pay attention to the remainder divided by 10 and 9. When the remainder of dividing $ x $ by 10 is 0, the ones digit becomes 0 and the number of runruns that can be generated decreases. Similarly, when the remainder of dividing $ x $ by 9 is 0, the number of run-runs that can be generated decreases. Because, when the ones place is 0, there are only 0 and 1 run-run numbers such that the difference between adjacent numbers is 1. Even when it is 9, there are only 8 and 9. If you organize what kind of run-run number is generated for each,

x != 0 mod(10) → 10x+(x%10)-1
x != 9 mod(10) → 10x+(x%10)+1 

It will be. If you implement this

from collections import deque

k = int(input())

lun = deque([])
for i in range(1,10):
    lun.append(i)

for i in range(k):
    x = lun.popleft()
    if x % 10 != 0:
        lun.append(10*x+(x%10)-1)
    lun.append(10*x+x%10)
    if x % 10 != 9:
        lun.append(10*x+(x%10)+1)
print(x)

I'm using deque because I only access both ends of the data

Summary

I wanted to solve it in production. I am not good at calculations using remainders, so I will practice around integer problems. see you.

Recommended Posts

Daily AtCoder # 2 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Daily AtCoder # 53 in Python
Daily AtCoder # 33 in Python
Daily AtCoder # 24 in Python
Daily AtCoder # 37 in Python
Daily AtCoder # 8 in Python
Daily AtCoder # 42 in Python
Daily AtCoder # 21 in Python
Daily AtCoder # 17 in Python
Daily AtCoder # 38 in Python
Daily AtCoder # 54 in Python
Daily AtCoder # 11 in Python
Daily AtCoder # 15 in Python
Daily AtCoder # 47 in Python
Daily AtCoder # 13 in Python
Daily AtCoder # 45 in Python
Daily AtCoder # 30 in Python
Daily AtCoder # 40 in Python
Daily AtCoder # 10 in Python
Daily AtCoder # 5 in Python
Daily AtCoder # 28 in Python
Daily AtCoder # 39 in Python
Daily AtCoder # 20 in Python
Daily AtCoder # 19 in Python
Daily AtCoder # 52 in Python
Daily AtCoder # 3 in Python
Daily AtCoder # 14 in Python
Daily AtCoder # 50 in Python
Daily AtCoder # 26 in Python
Daily AtCoder # 4 in Python
Daily AtCoder # 43 in Python
Daily AtCoder # 29 in Python
Daily AtCoder # 22 in Python
Daily AtCoder # 49 in Python
Daily AtCoder # 27 in Python
Daily AtCoder # 1 in Python
Daily AtCoder # 25 in Python
Daily AtCoder # 16 in Python
Daily AtCoder # 12 in Python
Daily AtCoder # 48 in Python
Daily AtCoder # 23 in Python
Daily AtCoder # 34 in Python
Daily AtCoder # 51 in Python
Daily AtCoder # 31 in Python
Daily AtCoder # 46 in Python
Daily AtCoder # 35 in Python
Daily AtCoder # 9 in Python
Daily AtCoder # 44 in Python
Daily AtCoder # 41 in Python
Atcoder ABC164 A-C in Python
Python Input Note in AtCoder
Atcoder ABC167 A-D in Python
Atcoder ABC165 A-D in Python
Atcoder ABC166 A-E in Python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D in python
Solve Atcoder ABC169 A-D in Python
[Python] Basic knowledge used in AtCoder
Quadtree in Python --2