[Codeforces-div.1 55D] Beautiful numbers
[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的更多相关文章
- CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)
传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ...
- Codeforces 55D. Beautiful numbers(数位DP,离散化)
Codeforces 55D. Beautiful numbers 题意 求[L,R]区间内有多少个数满足:该数能被其每一位数字都整除(如12,24,15等). 思路 一开始以为是数位DP的水题,觉得 ...
- codeforces 55D - Beautiful numbers(数位DP+离散化)
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力
C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...
- CodeForces 55D Beautiful numbers
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- CodeForces - 55D Beautiful numbers —— 数位DP
题目链接:https://vjudge.net/problem/CodeForces-55D D. Beautiful numbers time limit per test 4 seconds me ...
- CodeForces - 55D - Beautiful numbers(数位DP,离散化)
链接: https://vjudge.net/problem/CodeForces-55D 题意: Volodya is an odd boy and his taste is strange as ...
- CF 55D - Beautiful numbers(数位DP)
题意: 如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers.求区间 [a,b] 中 Beautiful numbers 的个数. 分析:先分析出,2~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 ...
随机推荐
- Mayor's posters(线段树+离散化+区间染色)
题目链接:http://poj.org/problem?id=2528 题目: 题意:将n个区间进行染色(对于同一个区间,后一次染色会覆盖上一次的染色),问最后可见的颜色有多少种. 思路:由于区间长度 ...
- Python 源码学习之内存管理 -- (转)
Python 的内存管理架构(Objects/obmalloc.c): _____ ______ ______ ________ [ int ] [ dict ] [ list ] ... [ str ...
- adb端口被占用解决
解决ADB端口占用问题 方式一5037为adb默认端口,若5037端口被占用,查看占用端口的进程PIDC:\Users\wwx229495>netstat -aon|findstr 5037 ...
- Spring cloud 实战读书笔记
基础知识 Spring cloud 版本说明 Brixton.SR5 :Brixton 的第5个Release版本 SRX:service releases 简称SRX版本,X版本号 Spring b ...
- [CTF技巧]批量连接SSH批量执行命令
https://files.cnblogs.com/files/nul1/autossh1.3.jar.zip 下载下来以后直接将后缀去除就好了. 比赛的时候可以批量写一个不死马然后你懂的. Linu ...
- Linux 内核通知链随笔【中】【转】
转自:http://blog.chinaunix.net/uid-23069658-id-4364171.html 关于内核通知链不像Netlink那样,既可以用于内核与用户空间的通信,还能用于内核不 ...
- 使用XShell通过SSH访问Google谷歌云服务器方法
1:先用Xshell创建个密钥 下一步到这里,这个名称要记得,谷歌后台要用的. 把这里的公钥复制出来,当然最好也可以备份下. 2:到谷歌后台去添加ssh,然后就能连接了. 复制刚才生成的公钥,在谷歌云 ...
- Tomcat debug模式下特别慢但是run正常处理方法
转载自:http://blog.csdn.net/builderwfy/article/details/50785749 到网上查资料发现这是由eclipse和tomcat交互时,在debug模式启动 ...
- MySQL的读写分离---主从复制、主主复制
1.复制是基于BinLog日志 存在三种日志格式:Statement:存储Sql语句,存储日志量是最小的.有可能复制不一致Row:存储event数据,存储日志量大,但是不能很直接进行读取:Mixed: ...
- HDU-4255
A Famous Grid Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...