#include <stdio.h>
int main()
{
puts("转载请注明出处[vmurder]谢谢");
puts("网址:blog.csdn.net/vmurder/article/details/45334857");
}
枚举后面有几个
然后把所有这些数都比较一下就好啦。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
long long ans,A,B,x;
void dfs(long long div)
{
long long C=((A-1)/div+1)*div,c=0;
if(C>B)return ;
long long D=((A-1)/(5*div)+1)*(5*div),d=0;
if(D>B)d=inf;
for(long long T=C/div;T;T/=10)c+=2;
for(long long T=D/div;T;T/=10)d+=2;
d--;
if(c<=d)
{
if(x>c)
{
x=c;
ans=C;
}
}
else {
if(x>d)
{
x=d;
ans=D;
}
}
dfs(div*10);
}
int main()
{
int i,j,k,g;
for(scanf("%d",&g);g--;)
{
cin>>A>>B;
x=inf,dfs(1);
cout<<ans<<endl;
}
return 0;
}
原文地址:http://blog.csdn.net/vmurder/article/details/45334857