Windy defines a windy number.
A positive integer with a difference of at least 2 2 without a leading 0 and an adjacent two digits is called the windy number.
Windy want to know, in A ">a A and B " > b B, including A ">a A and B " > b B, how many windy are there in total?
Input
Contains two integers,aa bB.
Meet 1≤A≤B≤20000000001≤a≤b≤2000000000.
Outputsample Input
1 10
Sample Output
9
Remember what the last number was.
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <cstdlib>5#include <algorithm>6#include <cmath>7#include <queue>8#include <deque>9#include <Set>Ten#include <map> One#include <ctime> A #defineLL Long Long - #defineINF 0X7FFFFFF - #definePA pair<int,int> the #defineMKP (A, B) Make_pair (A, B) - #definePi 3.1415926535897932384626433832795028841971 - using namespacestd; - inline LL read () + { -LL x=0, f=1;CharCh=GetChar (); + while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} A while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} at returnx*F; - } - LL n,len,l,r; -LL f[ -][ One][2]; - intd[ the]; -Inline LL DFS (intNowintDatintLeadintFP) in { - if(now==1)return!Lead ; to if(!fp&&f[now][dat][lead]!=-1)returnF[now][dat][lead]; +LL ans=0, mx=fp?d[now-1]:9; - for(intI=0; i<=mx;i++) the { * if(!lead&& (i==dat-1|| i==dat| | i==dat+1))Continue; $Ans+=dfs (now-1, i,lead&&i==0&&now-1!=1, fp&&i==d[now-1]);Panax Notoginseng } - if(!FP) f[now][dat][lead]=ans; the returnans; + } A Inline ll Calc (ll x) the { + if(!x)return 1; -LL xxx=x; $len=0; $ while(XXX) - { -d[++len]=xxx%Ten; theXxx/=Ten; - }WuyiLL sum=0; theSum+=dfs (Len,0,1,0); - for(intI=1; i<=d[len];i++) WuSum+=dfs (Len,i,0, i==D[len]); - returnsum; About } $ Main () - { - while(~SCANF ("%lld%lld",&l,&R)) - { Amemset (f,-1,sizeof(f)); +printf"%lld\n", Calc (r)-calc (l1)); the } -}
UESTC
[Summer Camp--digital dp]uestc250 windy number
]