[Codeforces-div.1 55D] Beautiful numbers

试题分析

还是离散化。。。\(f_{i,j,k}\)表示i位,gcd为j,余数为k。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm> using namespace std;
#define LL long long inline LL read(){
LL x=0,f=1; char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
const LL MAXN = 100010;
const LL INF = 2147483600; LL sta[MAXN+1]={0,1,2,3,4,5,6,7,8,9,10,12,14,15,18,20,21,24,28,30,35,36,40,42,45,56,60,63,70,72,84,90,105,120,126,140,168,180,210,252,280,315,360,420,504,630,840,1260,2520},top; inline LL gcd(LL a,LL b){
return (!b?a:gcd(b,a%b));
}
inline LL LCM(LL a,LL b){
if(!a||!b) return b|a;
return a*b/gcd(a,b);
}
LL f[21][50][2600];
LL cnt; LL str[MAXN+1],num[MAXN+1]; inline LL dfs(LL i,LL j,LL k,LL g){
if(i==0) return j&&(k%sta[j]==0);
if(!g && ~f[i][j][k]) return f[i][j][k];
LL ans=0; for(LL l=0;l<=(g?str[i]:9);l++){
LL x=LCM(sta[j],l);
ans+=dfs(i-1,num[x],(k*10%2520+l)%2520,g&(str[i]==l));
} return (g?ans:f[i][j][k]=ans);
}
inline LL init(LL x){
cnt=0; while(x) str[++cnt]=x%10,x/=10;
return dfs(cnt,0,0,1);
}
LL T; int main(){
//freopen(".in","r",stdin);
memset(f,-1,sizeof(f));
T=read(); for(LL i=1;i<49;i++) num[sta[i]]=i;
while(T--){
LL L=read(),R=read(); LL ans=0;
ans+=init(R); ans-=init(L-1);
printf("%lld\n",ans);
}
return 0;
}

[Codeforces-div.1 55D] Beautiful numbers的更多相关文章

  1. CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)

    传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ...

  2. Codeforces 55D. Beautiful numbers(数位DP,离散化)

    Codeforces 55D. Beautiful numbers 题意 求[L,R]区间内有多少个数满足:该数能被其每一位数字都整除(如12,24,15等). 思路 一开始以为是数位DP的水题,觉得 ...

  3. codeforces 55D - Beautiful numbers(数位DP+离散化)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  4. Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力

    C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...

  5. CodeForces 55D Beautiful numbers

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  6. CodeForces - 55D Beautiful numbers —— 数位DP

    题目链接:https://vjudge.net/problem/CodeForces-55D D. Beautiful numbers time limit per test 4 seconds me ...

  7. CodeForces - 55D - Beautiful numbers(数位DP,离散化)

    链接: https://vjudge.net/problem/CodeForces-55D 题意: Volodya is an odd boy and his taste is strange as ...

  8. CF 55D - Beautiful numbers(数位DP)

    题意: 如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers.求区间 [a,b] 中 Beautiful numbers 的个数. 分析:先分析出,2~9 的最大的最小公 ...

  9. 【数位dp】CF 55D Beautiful numbers

    题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...

随机推荐

  1. 微信小程序滑动选择器

    实现微信小程序滑动选择效果 在wxml文件中,用一个picker标签代表选择器,bindchange是用户点击确定后触发的函数,index是picker自带的参数,用户点击确定后,bindchange ...

  2. js_判断当前页面是否有网络和网络连接超时

    2018-04-12 方法一:通过navigator.onLine属性判断,返回true为有联网状态,false为断网状态. //方法一 if(navigator.onLine) { console. ...

  3. C++之容器(关联容器)

    关联容器和顺序容器的本质区别:关联容器是通过键存取和读取元素.顺序容器通过元素在容器中的位置顺序存储和访问元素.因此,关联容器不提供front.push_front.pop_front.back.pu ...

  4. SD卡 模拟SPI总线控制流程

    SD卡为移动设备提供了安全的,大容量存储解决方法.它本身可以通过两种总线模式和MCU进行数据传输,一种是称为SD BUS的4位串行数据模式,另一种就是大家熟知的4线SPI Bus模式.一些廉价,低端的 ...

  5. TCP之Nagle算法&&延迟ACK

    1. Nagle算法: 是为了减少广域网的小分组数目,从而减小网络拥塞的出现: 该算法要求一个tcp连接上最多只能有一个未被确认的未完成的小分组,在该分组ack到达之前不能发送其他的小分组,tcp需要 ...

  6. python实战===一键刷屏

    #当按键q的时候,自动输入 “大家好!”并回车键发送!from pynput import keyboard from pynput.keyboard import Key, Controller k ...

  7. Jmeter获取当前时间、历史时间、未来时间的方式

    __time : 获取时间戳.格式化时间 操作步骤: 1.通过函数助手,生成一个_time 函数: 2.如果参数为时间戳,那公式为: ${__time(,)}  :  默认该公式精确到毫秒级别, 13 ...

  8. springboot在不同环境下进行不同的配置

    原文链接:http://www.cnblogs.com/java-zhao/p/5469183.html 不同的环境设置一个配置文件,例如:dev(开发)环境下的配置设置在application-de ...

  9. Makefile系列之二 : 命令

    一.显示命令 echo “@”字符可以控制命令是否在屏幕上显示,如 @echo 正在编译XXX模块......  输出: 正在编译XXX模块...... 如果没有“@"则输出 : echo ...

  10. Sql中把datetime转换成字符串(CONVERT)(转)

    一.回顾一下CONVERT()的语法格式: CONVERT (<data_ type>[ length ], <expression> [, style]) 二.这里注重说明一 ...