301750: CF331C2. The Great Julya Calendar

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

The Great Julya Calendar

题意翻译

## 题目大意 聪明的海狸得到了一个魔数 $n$,现在可以对其进行一种操作: - 使 $n=n-k$ $(0\le k\le9)$,其中 $k$ 必须在$n$的某一位中出现。 海狸将不断进行这个操作,直至$n=0$。 选择不同的 $k$ 显然会使操作次数不同,海狸希望你能帮他算出他最少需要操作多少次才能使魔数变为$0$。 ## 输入格式 单独一行,包含了一个整数,表示魔数$n$ $(0\le n)$. - 对于前$20$分的数据,$n \le 10^6$. - 对于前$40$分的数据,$n \le 10^{12}$. - 对于$100$分的数据,$n \le 10^{18}$. ## 输出格式 输出一行,表示将魔数变为$0$所需的最少操作数。 ## 说明/提示 对于输出样例,通过以下操作顺序可以得到最少操作次数: $$ 24 \rightarrow 20 \rightarrow 18 \rightarrow 10 \rightarrow 9 \rightarrow 0 $$

题目描述

Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows: "May the Great Beaver bless you! May your chacres open and may your third eye never turn blind from beholding the Truth! Take the magic number, subtract a digit from it (the digit must occur in the number) and get a new magic number. Repeat this operation until a magic number equals zero. The Earth will stand on Three Beavers for the time, equal to the number of subtractions you perform!" Distinct subtraction sequences can obviously get you different number of operations. But the Smart Beaver is ready to face the worst and is asking you to count the minimum number of operations he needs to reduce the magic number to zero.

输入输出格式

输入格式


The single line contains the magic integer $ n $ , $ 0<=n $ . - to get 20 points, you need to solve the problem with constraints: $ n<=10^{6} $ (subproblem C1); - to get 40 points, you need to solve the problem with constraints: $ n<=10^{12} $ (subproblems C1+C2); - to get 100 points, you need to solve the problem with constraints: $ n<=10^{18} $ (subproblems C1+C2+C3).

输出格式


Print a single integer — the minimum number of subtractions that turns the magic number to a zero.

输入输出样例

输入样例 #1

24

输出样例 #1

5

说明

In the first test sample the minimum number of operations can be reached by the following sequence of subtractions: $ 24→20→18→10→9→0 $

Input

题意翻译

## 题目大意 聪明的海狸得到了一个魔数 $n$,现在可以对其进行一种操作: - 使 $n=n-k$ $(0\le k\le9)$,其中 $k$ 必须在$n$的某一位中出现。 海狸将不断进行这个操作,直至$n=0$。 选择不同的 $k$ 显然会使操作次数不同,海狸希望你能帮他算出他最少需要操作多少次才能使魔数变为$0$。 ## 输入格式 单独一行,包含了一个整数,表示魔数$n$ $(0\le n)$. - 对于前$20$分的数据,$n \le 10^6$. - 对于前$40$分的数据,$n \le 10^{12}$. - 对于$100$分的数据,$n \le 10^{18}$. ## 输出格式 输出一行,表示将魔数变为$0$所需的最少操作数。 ## 说明/提示 对于输出样例,通过以下操作顺序可以得到最少操作次数: $$ 24 \rightarrow 20 \rightarrow 18 \rightarrow 10 \rightarrow 9 \rightarrow 0 $$

加入题单

算法标签: