文章

11

粉丝

406

获赞

3

访问

79.4k

头像
动态规划,O(T)=O(lgn),20行代码
P1848 清华大学2020年机试题
发布于2022年3月3日 15:45
阅读数 5.2k

#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;

int main(){
    int n,k;
    while(~scanf("%d%d",&n,&k)){
        int fu=0,co=1,tmp=n,res=0;
        while(tmp){
            res+=(tmp%10<k)?tmp%10*fu:(tmp%10==k)?tmp%10*fu+n%co+1:tmp%10*fu+co;
            fu=10*fu+co;
            co*=10;
            tmp/=10;
        }
        printf("%d\n",res);
    }
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发