题意:输入l, r输出所有[l, r]内的首位和个位相同的数字的个数
题解:数位dp可以写,有一种更简单的方法,只要把前l-1位看作一个整体,可以取[1, x/10)任意数,个位补充就可以
#include <bits/stdc++.h> #define maxn 101000 #define INF 0x3f3f3f3f typedef long long ll; using namespace std; ll num; ll solve(ll x){ if(x<10) return x; ll t = x; while(x){ num = x%10; x /= 10; } return 8+t/10+(t%10>=num?1:0); } int main(){ ll l, r; //cout<<solve(47)<<endl; cin>>l>>r; cout<<solve(r)-solve(l-1)<<endl; return 0; }