题解:P6921 [ICPC 2016 WF] Forever Young
今天模拟赛讲了这个题,没有场掉,有一堆大神都场或者想到一个近似正解了,我无疑是区的。
考虑说如果
那如果
具体来说,注意到当
然后枚举的数显然要
有一个容易爆炸的点就是说如果枚举的数是三位数,那么最高位的贡献最大是 (
code
int T,y,l;
inline bool check(int x,int b){
int t=0,base=1;
while(x){
if(x%b>=10){
return 0;
}
t+=(x%b)*base;
x/=b;
base*=10;
}
// cout<<b<<" "<<t<<endl;
return t>=l;
}
inline int chng(int x,int b){
return (x/100)*b*b+(x%100/10)*b+(x%10);
}
inline int solve(){
cin>>y>>l;
int b=1e6,ans=0;
while(b>=10){
if(check(y,b)){
ans=b;
break;
}
b--;
}
// cout<<ans<<endl;
for(int i=l;i<1000;i++){
int ll=1e6,rr=1e18;
if(i>=100){
rr=1e9;
}
while(ll<rr){
// cout<<ll<<" "<<rr<<endl;
int mid=(ll+rr+1)>>1;
if(chng(i,mid)<=y){
ll=mid;
}else{
rr=mid-1;
}
}
// cout<<ll<<endl;
if(chng(i,ll)==y){
ans=max(ans,ll);
}
}
return ans;
}