• UVA 11038


     


    题意求[n, m]之间包含0的数字的个数
    题解:转化为求solve(n) - solve(m-1)的前缀问题
        对于求0到n的解,我们举例 n = 25789 对于8这位,让其为0对答案的贡献是 (0~257)*(0~9)
         假设是 n = 25709 那么让这位为0的答案贡献是 (0~256) * (0~9) + (257)* (0~9)


    //meek///#include<bits/stdc++.h>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include<iostream>
    using namespace std ;
    #define mem(a) memset(a,0,sizeof(a))
    #define pb push_back
    #define fi first
    #define se second
    #define MP make_pair
    typedef long long ll;
    
    const int N = (1<<9)*2;
    const int M = 1000001;
    const int inf = 0x3f3f3f3f;
    const int MOD = 1000000007;
    const double eps = 0.000001;
    
    
    
    ll n,m;
    ll solve(ll l) {
        if(l < 0 ) return 0;
        ll x = 1, r = 0;
        ll ans = 1;
        while(l >= 10) {
            ll now = l % 10;
            l /= 10;
            if(now) ans += l*x;
            else ans += (l-1)*x + r + 1;
            r = r + now*x;
            x *= 10;
        }
        return ans;
    }
    int main() {
        while(scanf("%lld%lld",&n,&m)!=EOF) {
            if(n == -1 && m == -1) break;
            printf("%lld
    ", solve(m) - solve(n-1));
        }
        return 0;
    }
    
    
    
     
     
  • 相关阅读:
    CentOS7- 配置阿里镜像源
    MySQL学习笔记
    OSI&TCP/IP模型
    加密算法学习
    golang学习笔记
    Redis学习总结整理
    TCP
    HTTP/HTTPS
    HTTP2
    MVCC
  • 原文地址:https://www.cnblogs.com/zxhl/p/5089302.html
Copyright © 2020-2023  润新知