Codeforces 204 A. Pride 做题记录

  原题链接:https://codeforces.com/problemset/problem/204/A

  一开始还很若智地宕机了一下,想清楚了就很明白。很显然在不考虑首尾的情况下,题目要求的数字会以$10$为间隔出现。那么就区间除以$10$然后特判一下首尾就行。

  这题貌似有DP的tag但是不是很DP捏。

#include <bits/stdc++.h>
using namespace std;

long long l,r,ans;

inline long long get_first(long long x){
    while (x){
        if (x/10==0)
            return x;
        x/=10;
    }
}

int main(){
    cin>>l>>r;
    if (r<10){
        printf("%lld",r-l+1);
        return 0;
    }
    else if (l<10)
        ans+=(10-l),l=10;
    ans+=((r-(r%10))-(l-(l%10)+10))/10;
    if (get_first(l)>=(l%10))
        ans++;
    if (get_first(r)<=(r%10))
        ans++;
    printf("%lld",ans);
    return 0;
}

 

posted @ 2023-01-01 20:31  wegret  阅读(26)  评论(0)    收藏  举报