Codeforces-C1157 A. Reachable Numbers
题意为按照 $math_inline$f(x)$math_inline$ 对某个数进行操作,在这个过程中一共会出现多少种不同的数字。
- 不管 n 为多少,必定可以出现 1-9 中的任意一个数字
- 如果 n 大于9,则需要把结果 +1 (n本身也算一次)
- 只统计 +1 并去掉末尾 0 之后的数字有几个
例如 n 为 121 :
- 那么显然 121 算一次
- 由于 +1 的缘故 121-129 都会出现,数量为 9 - 121 % 10 = 8
- 12-19 出现了 9 - 12 % 10 = 7
- 1-9 都可以出现
- 1 + 8 + 7 + 9 = 25
Code
/**
* author: Akvicor
* created: 2019-07-19 14-33-13
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
string to_string(string s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#endif
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 17
#endif
#ifdef DEBUG
#define FAST_IO 17
#else
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#endif
#define LL long long
#define ULL unsigned long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define reep(i, n) for(int i = 0; i <= (n); ++i)
#define lop(i, a, n) for(int i = a; i < (n); ++i)
#define loop(i, a, n) for(int i = a; i <= (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define VI vector<int>
#define PII pair<int,int>
#define FI first
#define SE second
#define SZ(x) ((int)(x).size())
const double EPS = 1e-6;
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const LL LINF = 0x7f7f7f7f7f7f7f7f;
const int MAXN = (int)1e6 + 10;
const int MOD = (int)1e9 + 7;
int n;
int main(){
FAST_IO;
while(cin >> n){
int cnt = 9 + (n > 9);
while(n > 9){
cnt += 9 - (n % 10);
n /= 10;
}
cout << cnt << endl;
}
return 0;
}