[暑假集训--数位dp]UESTC250 windy数
windy定义了一种windy数。
不含前导零且相邻两个数字之差至少为22 的正整数被称为windy数。
windy想知道,在AA 和BB 之间,包括AA 和BB ,总共有多少个windy数?
Input
包含两个整数,AA BB 。
满足 1≤A≤B≤20000000001≤A≤B≤2000000000 .
OutputSample Input
1 10
Sample Output
9
记一下上一位出现的数是啥
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL n,len,l,r;
LL f[][][];
int d[];
inline LL dfs(int now,int dat,int lead,int fp)
{
if (now==)return (!lead)||(lead&&dat==);
if (!fp&&f[now][dat][lead]!=-)return f[now][dat][lead];
LL ans=,mx=fp?d[now-]:;
for (int i=;i<=mx;i++)
{
if (!lead&&(i==dat-||i==dat||i==dat+))continue;
ans+=dfs(now-,i,lead&&i==&&now-!=,fp&&i==d[now-]);
}
if (!fp)f[now][dat][lead]=ans;
return ans;
}
inline LL calc(LL x)
{
if (!x)len=,d[len]=;
else
{
LL xxx=x;
len=;
while (xxx)
{
d[++len]=xxx%;
xxx/=;
}
}
LL sum=;
sum+=dfs(len,,,);
for (int i=;i<=d[len];i++)
sum+=dfs(len,i,,i==d[len]);
return sum;
}
int main()
{
while (~scanf("%lld%lld",&l,&r))
{
memset(f,-,sizeof(f));
printf("%lld\n",calc(r)-calc(l-));
}
}
UESTC 250
[暑假集训--数位dp]UESTC250 windy数的更多相关文章
- [暑假集训--数位dp]LightOj1205 Palindromic Numbers
A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...
- [暑假集训--数位dp]hdu3709 Balanced Number
A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. ...
- [暑假集训--数位dp]hdu3555 Bomb
The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the ti ...
- [暑假集训--数位dp]hdu3652 B-number
A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- ...
- [暑假集训--数位dp]hdu2089 不要62
杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍, ...
- 数位dp——BZOJ1026 Windy数
1026: [SCOI2009]windy数 Time Limit: 1 Sec Memory Limit: 162 MB Description windy定义了一种windy数.不含前导零且相邻 ...
- [暑假集训--数位dp]hdu5787 K-wolf Number
Alice thinks an integer x is a K-wolf number, if every K adjacent digits in decimal representation o ...
- [暑假集训--数位dp]LightOJ1140 How Many Zeroes?
Jimmy writes down the decimal representations of all natural numbers between and including m and n, ...
- [暑假集训--数位dp]LightOj1032 Fast Bit Calculations
A bit is a binary digit, taking a logical value of either 1 or 0 (also referred to as "true&quo ...
随机推荐
- 使用notepad++远程编辑Linux文档
上一篇中,我写了如何使用使用ftp服务器实现很方便的通信,这一篇我分享一个使用notepad++的一个NPPFTP插件远程编辑Linux中的文档的小技巧. 首先要确保你的Linux的ftp服务已经打开 ...
- PAT (Basic Level) Practise (中文)- 1008. 数组元素循环右移问题 (20)
一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0A1……AN-1)变换为(AN-M …… AN-1 A0 ...
- LiteIDE 错误: go build xxxxxx: no non-test Go files in xxxx
问题 c:/go/bin/go.exe build [C:/Users/Administrator/Desktop/go] go build _/C_/Users/Administrator/Desk ...
- iOS8之后,UITableViewRowAction实现滑动多个按钮
#pragma mark - View lifeCycle - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = ...
- Java微信公众号开发----关键字自动回复消息
在配置好开发者配置后,本人第一个想要实现的是自动回复消息的功能,说明以下几点: 1. url 仍然不变,还是开发配置里的url 2. 微信采用 xml 格式传输数据 3.微信服务器传给我们的参数主要有 ...
- 对象、句柄、ID之间的区别
对象是C++的概念,C++的类对象 句柄是Windows SDK的概念,指向某种资源的一种“指针”(有时候底层不一定是指针) 资源ID在MFC里仅仅是一个宏,也就是个整数. 其实,句柄是控件在数据结构 ...
- NOIP2013 乌龟棋
描述 小明过生日的时候,爸爸送给他一副乌龟棋当作礼物. 乌龟棋的棋盘是一行N个格子,每个格子上一个分数(非负整数).棋盘第1格是唯一的起点,第N格是终点,游戏要求玩家控制一个乌龟棋子从起点出发走到终点 ...
- C++ 学习笔记(二) const的加强
const 含义为只读.如果在程序中显式改变const变量那么编译会报错. C语言的const: 在C语言中const 变量是放在内存中,如果使用指针可以间接改变const变量.所以在C语言中cons ...
- 用宝塔软件在linux上自动安装php环境
1.确保是纯净系统 确保是干净的操作系统,没有安装过其它环境带的Apache/Nginx/php/MySQL,否则安装不上 2.sudo进行安装 yum install -y wget &&a ...
- Pycharm安装类库
比如安装requests 打开settings,选择Project 下面的Project Interpreter,点击pip,在弹出窗口里输入requests然后点击install 即可!