Directory
Question
I don't know why I thought about it for a long time. N <= 2 ^ 31 times out.
After the competition, I knocked on it,ProgramThe efficiency is very high. Nima only reflected that this is bitwise,Search for every 10 digits... Nima super ghost ....It should be said that the search isSpecial answer treeTo the left, expand the 0-9 subnode as much as possible. The larger the number is, the smaller the number is to the right. When a = 1 B = 999999999 is input, only 43758 queries are searched.
Reflection: I remember that when I read Liu rujia's White Book, he mentioned this situation. I will analyze it carefully in the future. Don't be afraid to do it too much. I 've done it several times...
ThisCodeMessy writing
# Include <cstdio> # include <cstring> # include <iostream> using namespace STD; int sum; void solve (INT islim, int num [], int premax, int cur, int N, int ans) {int curlim; If (islim) curlim = num [cur]; else curlim = 9; If (cur = N-1) {sum + = (curlim-premax + 1); // printf ("% d \ n", ANS, (curlim-premax + 1 ));} else {If (curlim> = premax) {for (INT pre = premax; Pre <= curlim; Pre ++) solve (islim & (pre = curlim )), num, pre, cur + 1, n, NS * 10 + pre) ;}}int getnum (int x, int num []) {int Buf [20]; int I; for (I = 0; X; I ++) {Buf [I] = x % 10; // 456 654x/= 10;} For (Int J = 0; j <I; j ++) {num [J] = Buf [i-j-1];} return I;} int main () {int A, B; // 1 <31 = 2147483648 where there is a 1, so there is no impact. int32 can also be int num [20]; while (scanf ("% d", & A, & B )! = EOF) {if (a <0) A = (1 <31)-1; if (B <0) B = (1 <31)-1; int n = getnum (a-(A = 1? 0: 1), num); solve (1, num, 0, 0, N, 0); int ans = sum; n = getnum (B, num); sum = 0; solve (1, num, 0, 0, N, 0); ans = sum-ans; if (a = 1) ans + = 1; printf ("% d \ n", ANS); sum = 0 ;}}