题意:http://acm.uestc.edu.cn/#/problem/show/250

windy定义了一种windy数。

不含前导零且相邻两个数字之差至少为2 的正整数被称为windy数。

windy想知道,在A 和B 之间,包括A 和B ,总共有多少个windy数?

Input

包含两个整数,B 。

满足 1AB20000000001≤A≤B≤2000000000 .

OutputSample Input

1 10

Sample Output

9
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<vector>
#include<math.h>
#include<string>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define N 106
#define Lson rood<<1
#define Rson rood<<1|1
LL dp[40][12][3],d[60];
LL dfs(int now,int up,int falg,int fp)
{
    if(now==1) return (!falg)||(falg&&!up);
    if(!fp&&dp[now][up][falg]!=-1) return dp[now][up][falg];
    LL ans=0;
    int ma=fp?d[now-1]:9;
    for(int i=0;i<=ma;i++)
    {
        if(!falg&&abs(i-up)<2) continue;
        ans+=dfs(now-1,i,falg&&i==0&&now-1!=1,fp&&i==ma);
    }
    if(!fp&&dp[now][up][falg]==-1) dp[now][up][falg]=ans;
    return ans;
}
LL calc(LL x)
{
    if(x==0) return 1;
    LL xxx=x;
    int len=0;
    while(xxx)     
    {
        d[++len]=xxx%10;
        xxx/=10;
    }  
    LL sum=0;
    for(int i=0;i<=d[len];i++)
        sum+=dfs(len,i,i==0,i==d[len]);
    return sum;
}
int main()
{
    LL l,r;
    memset(dp,-1,sizeof(dp));
    while(scanf("%lld%lld",&l,&r)!=EOF)
        printf("%lld\n",calc(r)-calc(l-1));
    return 0;
}

 

posted on 2017-11-02 08:49  云胡不喜。  阅读(202)  评论(0编辑  收藏  举报