beautiful number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 596    Accepted Submission(s): 370

Problem Description
Let A=∑ni=1ai∗10n−i(1≤ai≤9)(n is the number of A's digits). We call A as “beautiful number” if and only if a[i]≥a[i+1] when 1≤i<n and a[i] mod a[j]=0 when 1≤i≤n,i<j≤n(Such as 931 is a "beautiful number" while 87 isn't).
Could you tell me the number of “beautiful number” in the interval [L,R](including L and R)?
 
Input
The fist line contains a single integer T(about 100), indicating the number of cases.
Each test case begins with two integers L,R(1≤L≤R≤109).
 
Output
For each case, output an integer means the number of “beautiful number”.
 
Sample Input
2
1 11
999999993 999999999
 
Sample Output
10
2
 
Source
 
 
数位DP不怎么会,,照着别人的打了一份.满足条件的数不会太多,可以考虑打表做.
数位dp:
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <math.h>
  7. using namespace std;
  8. typedef long long LL;
  9. int dp[][]; ///dp[i][j] 代表第 i 位为 j 时满足情况的个数
  10. void init(){
  11. memset(dp,,sizeof(dp));
  12. for(int i=;i<=;i++) dp[][i] = ;
  13. for(int i=;i<=;i++)
  14. for(int j=;j<=;j++) ///枚举第 i 位
  15. for(int k=;k<=j;k++) ///枚举第 i-1 位
  16. if(j%k==){
  17. dp[i][j]+=dp[i-][k];
  18. }
  19. }
  20. int solve(int num){ ///求解 num-1 以内的合法个数
  21. int len = ;
  22. int a[];
  23. int ans = ;
  24. while(num){
  25. a[len++] = num%;
  26. num/=;
  27. }
  28. a[len] = ;
  29. len--;
  30. for(int i=;i<len;i++){ ///第 1 - 最高位-1 位合法的可以全部算进去
  31. for(int j=;j<=;j++){
  32. ans+=dp[i][j];
  33. }
  34. }
  35. for(int i=;i<a[len];i++){
  36. ans+=dp[len][i];
  37. }
  38. for(int i=len-;i>=;i--){
  39. for(int j=;j<a[i];j++){
  40. if(a[i+]%j==&&a[i+]>=j){
  41. ans+=dp[i][j];
  42. }
  43. }
  44. if(a[i]==) break;
  45. if(a[i+]%a[i]!=||a[i]>a[i+]) break;
  46. }
  47. return ans;
  48. }
  49. int main()
  50. {
  51. init();
  52. int tcase;
  53. scanf("%d",&tcase);
  54. while(tcase--){
  55. int l,r;
  56. scanf("%d%d",&l,&r);
  57. printf("%d\n",solve(r+)-solve(l));
  58. }
  59. return ;
  60. }

打表:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <math.h>
  7. using namespace std;
  8. const int N = ;
  9. int main()
  10. {
  11. FILE * fp;
  12. fp = fopen("d:\\ans.txt","w");
  13. int cnt = ;
  14. for(int i=;i<=N;i++){
  15. int n = i,m=i;
  16. int a[];
  17. // memset(a,0,sizeof(a));
  18. int len = ;
  19. while(n){
  20. a[len++] = n%;
  21. n/=;
  22. }
  23. bool flag = false;
  24. for(int j=len-;j>=;j--){
  25. if(a[j]==||a[j+]==||a[j+]%a[j]!=||a[j+]<a[j]){
  26. flag = true;
  27. break;
  28. }
  29. }
  30. if(!flag){
  31. fprintf(fp,"%d,",m);
  32. cnt++;
  33. //printf("%d\n",m);
  34. }
  35. }
  36. fclose(fp);
  37. printf("%d\n",cnt);
  38. return ;
  39. }
  1. #include<cstdio>
  2. #include<cstring>
  3. #include<iostream>
  4. #include<algorithm>
  5. #include<cstdlib>
  6. #include<cmath>
  7. #include<vector>
  8. #include<queue>
  9. #include<map>
  10.  
  11. using namespace std;
  12. int a[]={
  13. ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,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,,,,,,,,,,,,,,,,,,,,,,,
  14. };
  15. int main()
  16. {
  17. int tcase;
  18. scanf("%d",&tcase);
  19. while(tcase--){
  20. int l,r;
  21. scanf("%d%d",&l,&r);
  22. int ans = ;
  23. for(int i=;i<;i++){
  24. if(a[i]>=l&&a[i]<=r) ans++;
  25. if(a[i]>r) break;
  26. }
  27. printf("%d\n",ans);
  28. }
  29. }

hdu 5179(数位DP||打表)的更多相关文章

  1. hdu 4507 数位dp(求和,求平方和)

    http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...

  2. hdu 4352 数位dp + 状态压缩

    XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. HDU 4588 Count The Carries 数位DP || 打表找规律

    2013年南京邀请赛的铜牌题...做的非常是伤心.另外有两个不太好想到的地方.. ..a 能够等于零,另外a到b的累加和比較大.大约在2^70左右. 首先说一下解题思路. 首先统计出每一位的1的个数, ...

  4. HDU 5808[数位dp]

    /* 题意: 给你l和r,范围9e18,求l到r闭区间有多少个数字满足,连续的奇数的个数都为偶数,连续的偶数的个数都为奇数. 例如33433符合要求,44不符合要求.不能含有前导零. 思路: 队友说是 ...

  5. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6156 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:如题. 解法:数位DP,暴力枚举进制之后,就转化成了求L,R区间的回文数的个数,这个直接做 ...

  6. hdu:2089 ( 数位dp入门+模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 数位dp的模板题,统计一个区间内不含62的数字个数和不含4的数字个数,直接拿数位dp的板子敲就行 ...

  7. HDU 4352 XHXJ's LIS HDU(数位DP)

    HDU 4352 XHXJ's LIS HDU 题目大意 给你L到R区间,和一个数字K,然后让你求L到R区间之内满足最长上升子序列长度为K的数字有多少个 solution 简洁明了的题意总是让人无从下 ...

  8. hdu 3709 数位dp

    数位dp,有了进一步的了解,模板也可以优化一下了 题意:找出区间内平衡数的个数,所谓的平衡数,就是以这个数字的某一位为支点,另外两边的数字大小乘以力矩之和相等,即为平衡数例如4139,以3为支点4*2 ...

  9. HDU 2089 数位dp入门

    开始学习数位dp...一道昨天看过代码思想的题今天打了近两个小时..最后还是看了别人的代码找bug...(丢丢) 传说院赛要取消 ? ... 这么菜不出去丢人也好吧~ #include<stdi ...

随机推荐

  1. PAT 1086 就不告诉你

    https://pintia.cn/problem-sets/994805260223102976/problems/1038429065476579328 做作业的时候,邻座的小盆友问你:“五乘以七 ...

  2. 虚拟机CentOS7.2 1611 Minimal最小化安装后桥接固定ip

    ip addr show 或者 ip addr 或者 ip a vim /etc/sysconfig/network-scripts/ifcfg-ens33 根据 然后重启网卡 service net ...

  3. elasticsearch this is not a http port

    访问的是elastic search的tcp端口,需换成http端口. elastic search默认tcp端口9300,http端口9200 如果浏览器中访问http://localhost:92 ...

  4. ASP.NET MVC如何使用输出缓存

    通过这篇文章你将学习到在MVC中如何使用输出缓存,业务逻辑我就不多介绍了,主要是Outputcache的基本使用.至于数据缓存还是等我的下一篇文章吧,一步一步来不急的.   输出缓存的使用方法是在Co ...

  5. 算法(12)Best Time to Buy and Sell Stock II

    题目:最大收益 [1,2,3,9,2,3] 思路:这道题竟然是easy的?! 最终的解法非常简单,只要把单个波峰减去波谷就可以了,比如在上面的例子中[1-2-3-9][2-3]这就是单个波峰波谷!为什 ...

  6. Struts2值栈

    一.前言 很多事儿啊,就是“成也萧何败也萧何”,细想一些事儿心中有感,当然,感慨和本文毛关系都没有~想起之前有篇Struts2中值栈的博客还未完工,就着心中的波澜,狂咽一把~ 二.正文 博文基于:st ...

  7. Beats数据采集

    Beats数据采集 Beats是elastic公司的一款轻量级数据采集产品,它包含了几个子产品: packetbeat(用于监控网络流量). filebeat(用于监听日志数据,可以替代logstas ...

  8. c# 以多个字符串分隔字符串数据 分组 分隔 split 正则分组

    string str="aaa[##]ccc[##]ddd[##]bb" Regex regex=new Regex("[##]");//以 [##] 分割 s ...

  9. [bzoj] 2038 小Z的袜子(hose) || 莫队

    原题 给出一个序列,求给定[l,r]内有任意取两个数,有多大概率是一样的 简单的莫队,每次+-当前区间里有的这个颜色的袜子的个数,最后除以(r-l+1)*(r-l)/2即可. 记得约分. #inclu ...

  10. NOI2018 D1T1 [NOI2018]归程 解题报告

    P4768 [NOI2018]归程 题目描述 本题的故事发生在魔力之都,在这里我们将为你介绍一些必要的设定. 魔力之都可以抽象成一个 \(n\) 个节点.\(m\) 条边的无向连通图(节点的编号从 \ ...