题解:CF2203B Beautiful Numbers
题目转化
定义
给定整数
思路
设当前数字和为
每次操作,我们可以将某一位改成更小的数字。对于非最高位,最多可减少该位本身(改成
为了用最少操作次数达到
Code
#include <bits/stdc++.h>
#define int long long
using namespace std;
int T,x;
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>T;
while(T--){
int tot=0,ans=0;
cin>>x;
vector<int>v;
while(x>=10){
int t=x%10;
v.push_back(t);
x/=10;
tot+=t;
}
tot+=x;
v.push_back(x-1);
sort(v.begin(),v.end());
for(int i=v.size()-1;i>=0;i--){
if(tot<10)break;
tot-=v[i];
ans++;
}
cout<<ans<<endl;
}
}