题目
题意: 求给定区间内的不含前导零且相邻两个数字之差至少为 2 的正整数。
思路: 数位dp.这里注意一点是有前导零的情况,即只有个位数前边是0的情况,这个是可以无脑放的。
时间复杂度: O(能过)
代码:

// Problem: Windy数
// Contest: AcWing
// URL: https://www.acwing.com/problem/content/1085/
// Memory Limit: 64 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)#include<iostream>
#include<cstdio>
#include<algorithm>
#include<complex>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<list>
#include<set>
#include<queue>
#include<stack>
#define OldTomato ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define fir(i,a,b) for(int i=a;i<=b;++i)
#define mem(a,x) memset(a,x,sizeof(a))
#define p_ priority_queue
// round() 四舍五入 ceil() 向上取整 floor() 向下取整
// lower_bound(a.begin(),a.end(),tmp,greater<ll>()) 第一个小于等于的
// #define int long long //QAQ
using namespace std;
typedef complex<double> CP;
typedef pair<int,int> PII;
typedef long long ll;
// typedef __int128 it;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll inf = 1e18;
const int N = 2e5+10;
const int M = 1e6+10;
const int mod = 1e9+7;
const double eps = 1e-6;
inline int lowbit(int x){ return x&(-x);}
template<typename T>void write(T x)
{if(x<0){putchar('-');x=-x;}if(x>9){write(x/10);}putchar(x%10+'0');
}
template<typename T> void read(T &x)
{x = 0;char ch = getchar();ll f = 1;while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
int n,m,k,T;
int a[11];
int f[11][11];
int pos;
int dfs(int cur,int pre,bool limit,bool lead)
{if(cur==-1) return 1;auto &tmp=f[cur][pre];if(!limit&&!lead&&~tmp) return tmp;int up = limit?a[cur]:9;int ans = 0;for(int i=0;i<=up;++i){if(lead|| abs(i-pre)>=2)ans += dfs(cur-1,i,limit&&i==up,lead&&i==0);}if(!limit&&!lead) tmp = ans;return ans;
}
int fun(int x)
{for(pos=0;x;x/=10) a[pos++]=x%10;return dfs(pos-1,0,1,1);
}
void solve()
{int l,r;cin>>l>>r;cout<<fun(r)-fun(l-1);
}
signed main(void)
{ mem(f,-1);T = 1;// OldTomato; cin>>T;// read(T);while(T--){solve();}return 0;
}

1083. Windy数相关推荐

  1. Acwing 1083. Windy数

    Acwing 1083. Windy数 题意: Windy 定义了一种 Windy 数:不含前导零且相邻两个数字之差至少为 2 的正整数被称为 Windy 数. Windy 想知道,在 A 和 B 之 ...

  2. AcWing 1083 Windy数

    题目描述: Windy 定义了一种 Windy 数:不含前导零且相邻两个数字之差至少为 2 的正整数被称为 Windy 数. Windy 想知道,在 A 和 B 之间,包括 A 和 B,总共有多少个 ...

  3. 1083 Windy数(数位dp)

    1. 问题描述: Windy 定义了一种 Windy 数:不含前导零且相邻两个数字之差至少为 2 的正整数被称为 Windy 数.Windy 想知道,在 A 和 B 之间,包括 A 和 B,总共有多少 ...

  4. bzoj-1026 windy数

    题意: 定义一种windy数.这个数在十进制下相邻两个数字之差至少为2的正整数: 求区间[A,B]的这样的数的个数: n<=10^9: 题解: 数位乱搞. 首先求区间[A.B]等价于求[1,A- ...

  5. bzoj 1026 windy数

    题目大意: 定义一种windy数:不含前导零且相邻两个数字之差至少为2的正整数被称为windy数 求在A和B之间,包括A和B,总共有多少个windy数 思路: 一眼数位dp 具体见注释 1 #incl ...

  6. luoguP2657 [SCOI2009]windy数

    和诸位巨佬不同,蒟蒻如我,只能想到怎么统计不满足windy数条件的数 就是个爆搜 定义c[i][j][k]表示第i位且前一位为j,k表示是否满足条件 1 #include<bits/stdc++ ...

  7. bzoj 1026: [SCOI2009]windy数 数位DP算法笔记

    数位DP入门题之一 也是我所做的第一道数位DP题目 (其实很久以前就遇到过 感觉实现太难没写) 数位DP题目貌似多半是问从L到R内有多少个数满足某些限制条件 只要出题人不刻意去卡多一个$log$什么的 ...

  8. uestc 250 windy数(数位dp)

    题意:不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道,在A和B之间,包括A和B,总共有多少个windy数? 思路:数位dp #include<iostream ...

  9. 【bzoj1026】[SCOI2009]windy数 数位dp

    题目描述 windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道,在A和B之间,包括A和B,总共有多少个windy数? 输入 包含两个整数 ...

最新文章

  1. SLAM综述(1)-Lidar SLAM
  2. linux编写多进程程序实验,实验7 编写多进程程序
  3. tf.reduce_max()函数的用法详解
  4. ASP.NET MVC与RAILS3的比较
  5. 实验3.1 简单实现Intent带返回值的跳转
  6. 作者:钱卫宁(1976-),男,华东师范大学数据科学与工程研究院教授、博士生导师...
  7. intellij idea 2016.3.5 控制台取消行数限制
  8. 刷访问量新招[流量精灵]
  9. linux libodbc.so.1,关于C#:Testprintenv:加载共享库时出错:libodbc.so.1:无法打开共享对象文件...
  10. c语言有cot三角函数吗,c/c++ 实现三角函数(不使用库函数) sin/cos/tan/cot
  11. 【新技能get】让App像Web一样发布新版本
  12. 燕郊手机5G网络已全面覆盖,宽带提高至1000M!
  13. 关于香港高防IP需要关注的几个问题
  14. 文件/文件夹强制删除工具:IObit Unlocker绿色版
  15. C语言视频教程-谭浩强版-小甲鱼主讲—P13
  16. 以后我给你们上课的机会可能越来越少了
  17. 帝国cms:评论列表模板中调用热门文章或是推荐文章的js方法
  18. 原生js解决表格奇偶列显示
  19. 32位嵌入式微处理器(processor)一览
  20. Wine零知识学习2 —— 源码下载、构建与安装

热门文章

  1. 百度 谷歌 Twitter,这么多短链接服务(Short Url)到底哪家强?
  2. 梅科尔工作室-梁嘉莹-鸿蒙笔记2
  3. Spring Security定义多个过滤器链(10)
  4. revit二次开发之多线程的正确使用
  5. 【高效复习】计算机网络重要概念总结
  6. Rockchip DRM RK628 Porting Guide
  7. traffic control 之 egress 队列
  8. TypeScript学习-函数
  9. React基础(叁)———事件处理
  10. PTA IP地址转换