原题链接

题意:求[l,r]中高位%低位等于0的数字个数。(不含0)
分析:此题有三种方法。
1.暴搜,毕竟最多才10个位。
2.数位dp,预处理好整体的,再处理细节。

dp[i][j]表示第i位上的数字位j的情况数,dp[i][j]+=dp[i-1][k](j%k==0)

3.猜想这样的数字并不多,于是打表。

数位dp

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <queue> #define LL long long using namespace std; int dp[][];
int a[];
void init(){
for(int i=;i<;i++) dp[][i]=;
for(int i=;i<;i++){
for(int j=;j<;j++){
for(int k=;k<;k++){
if(j%k==) dp[i][j]+=dp[i-][k];
}
}
}
} int solve(int x){
int len=;
int ans=;
while(x){
a[++len]=x%;
x/=;
}
for(int i=;i<len;i++){///先加上len-1位的情况
for(int j=;j<;j++)
ans+=dp[i][j];
}
for(int i=;i<a[len];i++) ans+=dp[len][i]; ///len位,且小于最高位数字的情况 for(int i=len-;i>=;i--){///已最高位的数字为基准,寻找符合条件的,再加上
for(int j=a[i]-;j>;j--){
if(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 t;
cin>>t;
while(t--){
int l,r;
cin>>l>>r;
cout<<solve(r+)-solve(l)<<endl;
}
return ;
}

打表

#include<iostream>//离线处理
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
#define INF 0x0f0f0f0f
using namespace std;
int a[] = {
,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,
,,,,,,,,,,,,,,
,,,,,,,,,,,,,,
,,,,,,,,,,,,,,
,,,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,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,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,
};
int main()
{
int t;
cin >> t;
cout << a[] << endl;
while (t--)
{
int ans = ;
int l, r;
scanf("%d%d", &l, &r);
for (int i = ; i < ; i++)
{
if (a[i] >= l && a[i] <= r) ans++;
}
cout << ans << endl;
}
return ;
}

hdu 5179 beautiful number(数位dp)的更多相关文章

  1. HDU 5179 beautiful number 数位dp

    题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5179 bc(中文): http://bestcoder.hdu.edu.cn/contes ...

  2. HDU 5179 beautiful number (数位dp / 暴力打表 / dfs)

    beautiful number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. hdu 5898 odd-even number 数位DP

    传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...

  4. beautiful number 数位DP codeforces 55D

    题目链接: http://codeforces.com/problemset/problem/55/D 数位DP 题目描述: 一个数能被它每位上的数字整除(0除外),那么它就是beautiful nu ...

  5. hdu 5179 beautiful number

    beautiful number 问题描述 令 A = \sum_{i=1}^{n}a_i * {10}^{n-i}(1\leq a_i \leq 9)A=∑​i=1​n​​a​i​​∗10​n−i​ ...

  6. HDU 5787 K-wolf Number 数位DP

    K-wolf Number Problem Description   Alice thinks an integer x is a K-wolf number, if every K adjacen ...

  7. HDU 3709 Balanced Number (数位DP)

    Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

  8. hdu 5898 odd-even number(数位dp)

    Problem Description For a number,if the length of continuous odd digits is even and the length of co ...

  9. HDU 5898 odd-even number (数位DP) -2016 ICPC沈阳赛区网络赛

    题目链接 题意:一个数字,它每个数位上的奇数都形成偶数长度的段,偶数位都形成奇数长度的段他就是好的.问[L , R]的好数个数. 题解:裸的数位dp, 从高到低考虑每个数位, 状态里存下到当前位为止的 ...

随机推荐

  1. 【hihocoder 1424】 Asa's Chess Problem(有源汇上下界网络流)

    UVALive-7670 ICPC北京2016-C题 hihocoder 1424 题意 有个 \(N\times N\) 的棋盘,告诉你每个格子黑色(1)或白色(0),以及每对能相互交换的同行或同列 ...

  2. 生产者&消费者.py

    1.最简单的 --生产者消费者 send.py# !/usr/bin/env python3.5# -*- coding:utf-8 -*-# __author__ == 'LuoTianShuai' ...

  3. selenium的等待~

    既然使用了selenium,那么必然牺牲了一些速度上的优势,但由于公司网速不稳定,导致频频出现加载报错,这才意识到selenium等待的重要性. 说到等待又可以分为3类, 1.强制等待 time.sl ...

  4. Codeforces Round #516 (Div. 2)D. Labyrinth(BFS)

    题目链接:http://codeforces.com/contest/1064/problem/D 题目大意:给你一个n*m的图,图中包含两种符号,'.'表示可以行走,'*'表示障碍物不能行走,规定最 ...

  5. TCP的三次握手和四次挥手图解

     1. TCP建立连接的三次握手 (1)第一次握手:Client将标志位SYN置为1,随机产生一个值seq=J,并将该数据包发送给Server,Client进入SYN_SENT状态,等待Server确 ...

  6. BZOJ 1854: [Scoi2010]游戏(二分图匹配/并查集)

    题面: https://www.lydsy.com/JudgeOnline/problem.php?id=1854 题解: 1.二分图匹配: 首先我们发现每件装备只能在两种属性中选一种.因此,我们以每 ...

  7. js jquery css 选择器总结

    js jquery css 选择器总结 一.原始JS(Document 对象)选择器. id选择器:document.getElementById("test"); name选择器 ...

  8. Django session相关操作

    Django session 是存储在数据库中的所以要先跟数据库建立连接 本连接有Django跟数据库建立连接的操作:https://www.cnblogs.com/Niuxingyu/p/10296 ...

  9. 第十三节,使用带有全局平均池化层的CNN对CIFAR10数据集分类

    这里使用的数据集仍然是CIFAR-10,由于之前写过一篇使用AlexNet对CIFAR数据集进行分类的文章,已经详细介绍了这个数据集,当时我们是直接把这些图片的数据文件下载下来,然后使用pickle进 ...

  10. 工具类:Colletions ,Arrays(静态导入,可变参数,强循环)

    一.Collecti 专门用来操作集合的工具类,没有构造函数,全静态方法. 常用方法: static <T extends Comparable<? super T>> voi ...