codeforces 55d//Beautiful numbers// Codeforces Beta Round #51
题意:一个数能整除它所有的位上的数字(除了0),统计这样数的个数。
注意离散化,为了速度更快需存入数组查找。
不要每次memset,记录下已有的长度下符合条件的个数。
数位dp肯定是从高位到低位。
记录数字已经有多大,还有lcm,递归传下去。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
const double EPS=1e-;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
lon dp[][][],index[];//
vector<lon> ls; lon gcd(lon x,lon y)
{
if(x<y)swap(x,y);
for(;;)
{
lon rem=x%y;
if(rem==)return y;
x=y;
y=rem;
}
} lon lcm(lon x,lon y)
{
return x*y/gcd(x,y);
} void getid()
{
for(lon i=;i<ls.size();++i)
{
index[ls[i]]=i;
}
} void lsh()
{
for(lon i=;i<pow(,);++i)
{
lon cur=;
for(lon j=;j<;++j)
{
if(i&(<<j))cur=lcm(cur,j+);
}
ls.push_back(cur);
}
sort(ls.begin(),ls.end());
ls.erase(unique(ls.begin(),ls.end()),ls.end());
getid();
} lon dfs(lon pos,lon cur,lon prelcm,lon limit,string &str)
{
if(pos==str.size())return cur%prelcm==;
if(!limit&&dp[str.size()-pos-][cur][index[prelcm]]!=-)return dp[str.size()-pos-][cur][index[prelcm]];
lon res=;
lon up=limit?str[pos]-'':;
for(lon i=;i<=up;++i)
{
lon curlcm=prelcm;
if(i)curlcm=lcm(i,curlcm);
res+=dfs(pos+,(cur*+i)%,curlcm,limit&&str[pos]-''==i,str);
}
if(!limit)dp[str.size()-pos-][cur][index[prelcm]]=res;
return res;
} lon work(string &str)
{
return dfs(,,,,str);
} bool chk(string &str)
{
lon num=,curlcm=;
for(lon i=;i<str.size();++i)
{
num=(num*+str[i]-'')%;
if(str[i]!='')curlcm=lcm(curlcm,str[i]-'');
}
return num%curlcm==;
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon casenum;
cin>>casenum;
lsh();
memset(dp,-,sizeof(dp));
for(lon time=;time<=casenum;++time)
{
string ll,rr;
cin>>ll>>rr;
lon res=work(rr)-work(ll);
if(chk(ll))++res;
cout<<res<<endl;
}
return ;
}
codeforces 55d//Beautiful numbers// Codeforces Beta Round #51的更多相关文章
- 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 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 ...
- CodeForces 55D Beautiful numbers(数位dp+数学)
题目链接:http://codeforces.com/problemset/problem/55/D 题意:一个美丽数就是可以被它的每一位的数字整除的数. 给定一个区间,求美丽数的个数. 显然这是一道 ...
- CodeForces 55D Beautiful numbers (SPOJ JZPEXT 数位DP)
题意 求[X,Y]区间内能被其各位数(除0)均整除的数的个数. CF 55D 有些时候因为问题的一些"整体性"而导致在按位统计的过程中不能顺便计算出某些量,所以只能在枚举到最后一位 ...
- CodeForces 55D Beautiful numbers(数位dp)
数位dp,三个状态,dp[i][j][k],i状态表示位数,j状态表示各个位上数的最小公倍数,k状态表示余数 其中j共有48种状态,最大的是2520,所以状态k最多有2520个状态. #include ...
随机推荐
- javashop组件开发指南
javashop组件开发指南 1. 概念解释 组件:可以理解为是插件,功能点的一个集合. 插件:是指具体的某个功能. 插件桩:是负责调用插件. 事件:是要决定什么时候执行插件 一个组件是由多 ...
- eclipse里error报错Target runtime com.genuitec.runtime.generic.jee60 is not defined.
eclipse里error报错Target runtime com.genuitec.runtime.generic.jee60 is not defined. eclipse里error报错解决办法 ...
- PHP读取sphinx 搜索返回结果完整实战实例
PHP读取sphinx 搜索返回结果完整实战实例 网上搜索N久都没有一个正在读取返回sphinx结果的实例,都是到了matches那里就直接var_dump或者print_r了,没有读取到字段的例子, ...
- Linux中Postfix邮件安装配置(二)
本套邮件系统的搭建,从如何发邮件到收邮件到认证到虚拟用户虚拟域以及反病毒和反垃圾邮件等都有详细的介绍.在搭建过程中必须的参数解释以及原理都有告诉,这样才能更好地理解邮件系统. 卸载自带postfix ...
- 怎么归档老日志的shell脚本
本脚本来自有学习阿铭的博文学习:工作中,需要用到日志切割logrotate,按照各自的需要切割.定义保留日志.提示:本文中的S全部都$符,不要问为什么,马云爸爸的社区就这样. #用途:日志切割归档.按 ...
- 开启你的kali linux DIY之旅
更新源 首先 是kali2016.2更新源的问题,网上找了好久,都不是很满意.后来把kali 2016.2安装到实体机中才发现,里面自带了更新源.下面我把这个官方自带更新源分享出来(速度蛮快的) de ...
- CentOS7安装redis5.0
下载好redis5.0后解压在/tmp目录 cd /tmp/redis-/ make make过程中可能出现make[1]: *** [adlist.o] 错误 127,这是因为CentOS7默认没有 ...
- Tomcat分windows版和linux版
Tomcat分windows版和linux版 官方下载链接:http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.37/bin/ windows下载e ...
- Android实验一(在Android Studio中创建项目和模拟器)
北京电子科技学院(BESTI) 实 验 报 告 课程:移动平台开发 班级:1592 姓名:苏泽楠 学号:20159207 成绩: 指导教师 ...
- Java中的三大框架分别有什么用
一.Spring Spring是一个解决了许多在J2EE开发中常见的问题的强大框架. Spring提供了管理业务对象的一致方法并且鼓励了注入对接口编程而不是对类编程的良好习惯.Spring的架构基础是 ...