hdu 5179(数位DP||打表)
beautiful number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 596 Accepted Submission(s): 370
Could you tell me the number of “beautiful number” in the interval [L,R](including L and R)?
Each test case begins with two integers L,R(1≤L≤R≤109).
1 11
999999993 999999999
2
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long LL;
int dp[][]; ///dp[i][j] 代表第 i 位为 j 时满足情况的个数
void init(){
memset(dp,,sizeof(dp));
for(int i=;i<=;i++) dp[][i] = ;
for(int i=;i<=;i++)
for(int j=;j<=;j++) ///枚举第 i 位
for(int k=;k<=j;k++) ///枚举第 i-1 位
if(j%k==){
dp[i][j]+=dp[i-][k];
}
}
int solve(int num){ ///求解 num-1 以内的合法个数
int len = ;
int a[];
int ans = ;
while(num){
a[len++] = num%;
num/=;
}
a[len] = ;
len--;
for(int i=;i<len;i++){ ///第 1 - 最高位-1 位合法的可以全部算进去
for(int j=;j<=;j++){
ans+=dp[i][j];
}
}
for(int i=;i<a[len];i++){
ans+=dp[len][i];
}
for(int i=len-;i>=;i--){
for(int j=;j<a[i];j++){
if(a[i+]%j==&&a[i+]>=j){
ans+=dp[i][j];
}
}
if(a[i]==) break;
if(a[i+]%a[i]!=||a[i]>a[i+]) break;
}
return ans;
}
int main()
{
init();
int tcase;
scanf("%d",&tcase);
while(tcase--){
int l,r;
scanf("%d%d",&l,&r);
printf("%d\n",solve(r+)-solve(l));
}
return ;
}
打表:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <math.h>
using namespace std;
const int N = ;
int main()
{
FILE * fp;
fp = fopen("d:\\ans.txt","w");
int cnt = ;
for(int i=;i<=N;i++){
int n = i,m=i;
int a[];
// memset(a,0,sizeof(a));
int len = ;
while(n){
a[len++] = n%;
n/=;
}
bool flag = false;
for(int j=len-;j>=;j--){
if(a[j]==||a[j+]==||a[j+]%a[j]!=||a[j+]<a[j]){
flag = true;
break;
}
}
if(!flag){
fprintf(fp,"%d,",m);
cnt++;
//printf("%d\n",m);
}
}
fclose(fp);
printf("%d\n",cnt);
return ;
}
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<queue>
#include<map> using namespace std;
int a[]={
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
};
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--){
int l,r;
scanf("%d%d",&l,&r);
int ans = ;
for(int i=;i<;i++){
if(a[i]>=l&&a[i]<=r) ans++;
if(a[i]>r) break;
}
printf("%d\n",ans);
}
}
hdu 5179(数位DP||打表)的更多相关文章
- hdu 4507 数位dp(求和,求平方和)
http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...
- hdu 4352 数位dp + 状态压缩
XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 4588 Count The Carries 数位DP || 打表找规律
2013年南京邀请赛的铜牌题...做的非常是伤心.另外有两个不太好想到的地方.. ..a 能够等于零,另外a到b的累加和比較大.大约在2^70左右. 首先说一下解题思路. 首先统计出每一位的1的个数, ...
- HDU 5808[数位dp]
/* 题意: 给你l和r,范围9e18,求l到r闭区间有多少个数字满足,连续的奇数的个数都为偶数,连续的偶数的个数都为奇数. 例如33433符合要求,44不符合要求.不能含有前导零. 思路: 队友说是 ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6156 数位DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:如题. 解法:数位DP,暴力枚举进制之后,就转化成了求L,R区间的回文数的个数,这个直接做 ...
- hdu:2089 ( 数位dp入门+模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 数位dp的模板题,统计一个区间内不含62的数字个数和不含4的数字个数,直接拿数位dp的板子敲就行 ...
- HDU 4352 XHXJ's LIS HDU(数位DP)
HDU 4352 XHXJ's LIS HDU 题目大意 给你L到R区间,和一个数字K,然后让你求L到R区间之内满足最长上升子序列长度为K的数字有多少个 solution 简洁明了的题意总是让人无从下 ...
- hdu 3709 数位dp
数位dp,有了进一步的了解,模板也可以优化一下了 题意:找出区间内平衡数的个数,所谓的平衡数,就是以这个数字的某一位为支点,另外两边的数字大小乘以力矩之和相等,即为平衡数例如4139,以3为支点4*2 ...
- HDU 2089 数位dp入门
开始学习数位dp...一道昨天看过代码思想的题今天打了近两个小时..最后还是看了别人的代码找bug...(丢丢) 传说院赛要取消 ? ... 这么菜不出去丢人也好吧~ #include<stdi ...
随机推荐
- OpenCV漫水填充算法示例代码
#include<cv.h> #include<highgui.h> int main(int argc, char** argv) { IplImage* img = cvL ...
- CFS 调度器
CFS调度器的原理明白了但是有个地方,搜遍了整个网络也没找到一个合理的解释: if (delta > ideal_runtime) resched_task(rq_of(cfs_rq)-> ...
- Struts2-part1
作者:禅楼望月(http://www.cnblogs.com/yaoyinglong) 1. Struts2应用的开发步骤: ① 在web.xml中配置核心的Filter来拦截用户的请求. <w ...
- Oracle解决索引碎片功能
我们开始时向一个空的带索引的表中插入大量数据后,是不会产生碎片问题的,但是,数据库经过很长一段时间的增删改查后,难免会出现碎片问题,影响数据库的性能,Oracle对于这一问题有自己的解决方案. 下面介 ...
- [Leetcode] spiral matrix ii 螺旋矩阵
Given an integer n, generate a square matrix filled with elements from 1 to n 2 in spiral order. For ...
- shell监控进程是否存在
1.直接给代码:我这个是两个程序.多半要写成函数 [root@java1 src]# cat checkprocess.sh #!/bin/bashcheckprocess(){ps -ef|grep ...
- PushState+Ajax 完美实现无刷新
转载自:http://lazynight.me/1897.html 折腾一下PJAX,利用HTML5的新API,实现历史记录的完美导入. 不知道你用没用过Github,里边的目录跳转就是用html5的 ...
- Linux Top 命令参数解析
转载自:http://www.jb51.net/LINUXjishu/34604.html TOP是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如果在前台执行该命令,它将独占前台,直到用户 ...
- linux+GraphicsMagick 安装
转摘自:http://blog.csdn.net/fhqsse220/article/details/12995763 GraphicsMagick 安装 下载软件:download:ftp://ft ...
- js错误处理
导致程序无法继续执行的异常状态称为错误. js中一旦发生错误,就会自动创建一个Error类型对象 js中有6中错误类型: SyntaxError 语法错误 ReferenceError 引用错误,找不 ...