[BZOJ4029] [HEOI2015] pricing simulation, bzoj4029heoi2015
Link:
# Include <stdio. h> int main () {puts ("reprinted please specify the source [vmurder] Thank you"); puts ("url: blog.csdn.net/vmurder/article/details/42534857 ");}
Question:
There are several 0 And then K Post-Import 0 ) Calculate the first ratio. L Large 10 k A multiple of, and the first Ratio L Large 5*10 k .
Then compare all these numbers.
Code:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define inf 0x3f3f3f3fusing 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;}