标签:ons type iostream str cst 处理 res algorithm cstring
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int N = 35;
ll n;
ll f[N][30];
void init() {
//处理一位的数字
for (int i = 0; i <= 9; i ++ )
f[1][i] = 1;
//处理两位数及以上的的数字
for (int i = 1; i < N; i ++ )
//最高位
for (int j = 0; j <= 9; j ++ ) {
//次高位
for (int k = 0; k <= 9; k ++ ) {
if (j == 4 && k == 9)
continue;
f[i][j] += f[i - 1][k];
}
}
}
ll dp(ll n) {
if (!n)
return 1;
vector<int> nums;
while (n)
nums.push_back(n % 10), n /= 10;
ll res = 0;
ll last = 0;//存上一位多少
for (int i = nums.size() - 1; i >= 0; i -- ) {
ll x = nums[i];
for (int j = 0; j < x; j ++ ) {
if (last == 4 && j == 9)
continue;
//从0到第i位一共i+1位
res += f[i + 1][j];
}
if (last == 4 && x == 9)
break;
last = x;
if (!i)
res ++ ;
}
return res;
}
int main()
{
ll t;
cin>>t;
init();
while(t--)
{
cin>>n;
cout<<n-dp(n)+1<<endl;
}
return 0;
}
标签:ons type iostream str cst 处理 res algorithm cstring
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12497562.html