hdu 5179 beautiful number
beautiful number
令 A = \sum_{i=1}^{n}a_i * {10}^{n-i}(1\leq a_i \leq 9)A=∑i=1nai∗10n−i(1≤ai≤9)(nn为AA的位数)。若AA为“漂亮的数”当且仅当对于任意1 \leq i < n1≤i<n满足a[i] \geq a[i+1]a[i]≥a[i+1]且对于任意1 \leq i \leq n,i < j \leq n1≤i≤n,i<j≤n,满足a[i]a[i] mod a[j]=0a[j]=0(例如931是一个“漂亮的数”而87不是),求在区间[L,R][L,R](包含L和R)里“漂亮的数”的个数。
第一行包含一个正整数TT(大约100),表示数据的组数。
接下来TT行,每行两个数$L,R(1 \leq L \leq R \leq {10}^{9})$。
对于每组数据输出一个正整数表示“漂亮的数”的个数。
2
1 11
999999993 999999999
10
2
由于题目要求各数位从高到低值递减而且还要满足后面必为前面约数的条件,所以从1到1e9里面的数不会很多,可以直接打表过,打表代码太长就不贴了
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int dp[][];
int a[];
int dfs(int len,int pre,int flag,int d)
{
if(len==-) return ;
if(!flag&&dp[len][pre]!=-) return dp[len][pre];
int end=flag?a[len]:;
int ans=;
for(int i=;i<=end;i++)
{
if(d==||(i<=pre&&i!=&&pre%i==))
ans+=dfs(len-,i,flag&&i==end,d||i);
}
if(!flag)
dp[len][pre]=ans;
return ans;
}
int cacu(int x)
{
int top=;
while(x)
{
a[top++]=x%;
x/=;
}
return dfs(top-,,,);
}
int main()
{
memset(dp,-,sizeof(dp));
int T;
for(scanf("%d",&T);T;T--)
{
int l,r;
scanf("%d%d",&l,&r);
printf("%d\n",cacu(r)-cacu(l-));
}
return ;
}
hdu 5179 beautiful number的更多相关文章
- HDU 5179 beautiful number (数位dp / 暴力打表 / dfs)
beautiful number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 5179 beautiful number 数位dp
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5179 bc(中文): http://bestcoder.hdu.edu.cn/contes ...
- hdu 5179 beautiful number(数位dp)
原题链接 题意:求[l,r]中高位%低位等于0的数字个数.(不含0)分析:此题有三种方法.1.暴搜,毕竟最多才10个位.2.数位dp,预处理好整体的,再处理细节. dp[i][j]表示第i位上的数字位 ...
- hdu 5179 beautiful number(构造,,,,)
题意: 一个如果称作是漂亮数,当且仅当满足: 每一位上的数字是[1,9],从高到时低数字大小降序,且有di%dj=0(i<j) 例:931 给一个区间[L,R],问这个区间里有多少个漂亮数. 1 ...
- 【HDOJ】5179 beautiful number
DFS. /* 5179 */ #include <iostream> #include <algorithm> #include <map> #include & ...
- hdu 5898 odd-even number 数位DP
传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...
- hdu 2665 Kth number
划分树 /* HDU 2665 Kth number 划分树 */ #include<stdio.h> #include<iostream> #include<strin ...
- Codeforces 55D Beautiful Number
Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...
- hdu 4670 Cube number on a tree(点分治)
Cube number on a tree Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/ ...
随机推荐
- 【树剖求LCA】树剖知识点
不太优美但是有注释的版本: #include<cstdio> #include<iostream> using namespace std; struct edge{ int ...
- J - 玩游戏
小A和小B玩游戏,初始的时候小A给小B一组包含n个数的数组.他们按如下的规则进行: 每次小B得到一组数,他把这组数的和加到自己的分数里面(他的初始分数是0),然后他把这组数还给小A. 如果小A得到的这 ...
- ios集合
Foundation framework中用于收集cocoa对象(NSObject对象)的三种集合分别是: NSArray 用于对象有序集合(数组) NSSet 用于对象无序集合 (集合) NSDic ...
- 华为FusionSphere概述——计算资源、存储资源、网络资源的虚拟化,同时对这些虚拟资源进行集中调度和管理
华为FusionSphere概述 FusionSphere是华为自主知识产权的云操作系统,集虚拟化平台和云管理特性于一身,让云计算平台建设和使用更加简捷,专门满足企业和运营商客户云计算的需求.华为云操 ...
- codeforces 764D
脑洞 很早以前没有补掉的题目 四色问题肯定使有解的,然后就是怎么构造.注意到边长是奇数,那么我们就可以分类,按左上角坐标的奇偶性分类,正好对应四种颜色.因为当两个矩形左上角横纵坐标奇偶性不同时,那么肯 ...
- hibernate中id中的 precision 和 scale 作用
转自:https://www.cnblogs.com/IT-Monkey/p/4077570.html <hibernate-mapping> <class name=&qu ...
- [Swift通天遁地]五、高级扩展-(5)获取互补色、渐变色、以及图片主题颜色
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Python多线程、多进程
1.from multiprocessing import Process ; from threading import Thread 2.进程之间的数据传输 ,一般会使用到pipes, qu ...
- python中的深拷贝和浅拷贝(面试题)
一.浅拷贝 定义:浅拷贝只是对另外一个变量的内存地址的拷贝,这两个变量指向同一个内存地址的变量值. 浅拷贝的特点: 公用一个值: 这两个变量的内存地址一样: 对其中一个变量的值改变,另外一个变量的值也 ...
- Jquery音频播放插件下载地址(有Html、JS、CSS、音频)
有详细的html文件.全部JS代码文件.Css样式文件.测试音频资料 音频播放插件下载链接(百度云): http://pan.baidu.com/s/1pKC904F 提取码评论留邮箱发送,谢谢!