Description
decimal Representations of all natural numbers between and including M and N, (m≤n). How many zeroes would he write down?
Input
11000case-bit integers m and N, (m≤n).
Output
Case Case number and the number of zeroes written down by Jimmy.
Sample Input
5 Ten One - $ 0 - 1234567890 2345678901 0 4294967295
Sample Output
1 1 2 34 987654304 5 3825876150
Give the interval [m,n] to find out how many 0 of all the numbers in the interval.
Set Dp[i][j] indicates that when processing to bit I, it is preceded by J 0 (except for leading 0).
1 //110,101,100,011,010,001,0002 #pragmaComment (linker, "/stack:1024000000,1024000000")3#include <iostream>4#include <cstdio>5#include <cstring>6#include <cmath>7#include <math.h>8#include <algorithm>9#include <queue>Ten#include <Set> One#include <bitset> A#include <map> -#include <vector> -#include <stdlib.h> the using namespacestd; - #definell Long Long - #defineEPS 1e-10 - #defineMOD 1000000007 + #defineN 1000000 - #defineINF 1e12 + ll A, B; All dp[ -][ -]; at intdig[ -]; -ll Dfs (intLen/*the number of bits converted to a binary number*/ intFirst/*1 indicates that the current preamble is 0*/ intSta/*STA indicates a few 0 ahead*/ intUp/*up to determine the value of each bit, when 1 can only take the original value, 0 of the time to take 0~9 any value*/){ - if(len==0){//when I counted the last one, - if(first) { - return(LL)1; -}Else{ in return(LL) STA; - } to } + if(!up && dp[len][sta]!=-1&&!first) {//memory, the direct return value that was previously counted, no longer counting - returnDp[len][sta]; the } * $ intN=up?dig[len]:9;//if the value of up is 1, only Dig[len], such as a value of 123,up value of 1 that is the first bit 1, then the value of N is 2, but not 9Panax Notoginsengll res=0; - for(intI=0; i<=n;i++){ the if(first) {//if the preamble is 0 o'clock, the determination of the Sta=0,up value depends on whether n +Res+=dfs (len-1, first&&i==0,0, up&&i==n); A}Else{ the if(i==0){//Judging here is if i=0, the number of 0 in front +1 +Res+=dfs (len-1,0, sta+1, up&&i==N); -}Else{ $Res+=dfs (len-1,0, sta,up&&i==N); $ } - - } the } - if(!up &&!)First ) {Wuyidp[len][sta]=Res; the } - returnRes; Wu } - ll cal (ll num) { About intlen=0; $ if(num = =0){//if the value is 0, then only one digit 0 -Dig[++len] =0; - } - while(num) { ADig[++len] = num%Ten; +Num/=Ten; the } - returnDFS (Len,1,0,1); $ } the intMain () the { the intT; the intAc=0; -scanf"%d",&t); in while(t--){ thescanf"%lld%lld",&a,&b); thememset (dp,-1,sizeof(DP)); Aboutprintf"Case %d:",++AC); theprintf"%lld\n", Cal (b)-cal (A-1)); the the } + return 0; -}
View Code
LightOJ-1140 How many zeroes?