
题意求最大的
,满足
出现了n次
从网上找了个板子,是求中
出现的次数,这里叫它
复杂度
因为我们要找最大的
我们先算一下
如果
自然x就是我们想要的结果
如果
我们就可以直接把赋值成
因为他们之间的数肯定是大于我们想要的结果的
如果
我们假设x是一个位数,并且他的所有位数都是
在这样的情况下我们只需要重新让即可
因为在最坏的情况下所有的位数都是
我们要想让至少要它减去
个数
应该大概可能是没啥毛病吧
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll count(ll n,ll x)
{
ll cnt=0,k;
for(ll i=1;k=n/i;i*=10)
{
cnt+=(k/10)*i;
ll cur=k%10;
if(cur>x)
{
cnt+=i;
}
else if(cur==x)
{
cnt+=n-k*i+1;
}
}
return cnt;
}
int num(ll n)
{
int ans=0;
while(n)
{
ans++;
n/=10;
}
return ans;
}
int main()
{
ll n;
int t;
scanf("%d",&t);
ll d;
ll x;
while(t--)
{
scanf("%lld%lld",&d,&n);
while(1)
{
x=count(n,d);
if(x==n)
{
printf("%lld\n",x);
break;
}
else if(x<n)
{
n=x;
}
else
{
n=n-max((x-n)/num(x),1LL);
}
}
}
return 0;
} 
京公网安备 11010502036488号