首页 技术 正文
技术 2022年11月15日
0 收藏 670 点赞 3,178 浏览 2585 个字

原题链接

题意:求[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 longusing 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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844