当前位置:网站首页>Digital statistics DP acwing 338 Counting problem
Digital statistics DP acwing 338 Counting problem
2022-07-03 09:05:00 【T_ Y_ F666】
Digital statistics DP AcWing 338. Counting problem
Original link
Ideas
For numbers n Each number has a number x Have a classified discussion
Fourth place here d For example 
See code for details
Code
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 15;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
int pow(int x){
int res=1;
while(x--){
res*=10;
}
return res;
}
// Get array a The first r Bit to bit l Digit number
int get(vector<int> a, int l, int r){
int res=0;
Rep(i, l, r){
res=res*10+a[i];
}
return res;
}
// 1 to n in x Number of occurrences
int cnt(int n, int x){
if(!n){
return 0;
}
else{
vector<int> a;
while(n){
a.push_back(n%10);
n/=10;
}
int res=0;
n=a.size();
// if x by 0 n-2->0 Because the highest bit cannot be 0, So we should start from n-2 Start
// if x Not 0 n-1->0
Rep(i, n-1-!x, 0){
// front i digit ( namely abc) Composition less than n In the numbers x Number of occurrences
if(i<n-1){
res+=(get(a, n-1, i+1))*pow(i);
// Before removal i The number of digits is zero
if(!x){
res-=pow(i);
}
}
// The first i Bit after ( namely efg) Less than n In the numbers x Number of occurrences
if(a[i]==x){
res+=get(a, i-1, 0)+1;
}else if(a[i]>x){// The first i The number of all digits after the digit
res+=pow(i);
}
}
return res;
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int a, b;
while(a=read(), b=read(), a){
if(a>b){
swap(a, b);
}
rep(i, 0, 10){
// a To b in i Number of entries
printf("%lld ", cnt(b, i)-cnt(a-1, i));
}
puts("");
}
return 0;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
- Tree DP acwing 285 A dance without a boss
- 【点云处理之论文狂读前沿版10】—— MVTN: Multi-View Transformation Network for 3D Shape Recognition
- PIC16F648A-E/SS PIC16 8位 微控制器,7KB(4Kx14)
- Too many open files solution
- AcWing 786. 第k个数
- Convert video to GIF
- Format - C language project sub file
- 浅谈企业信息化建设
- Methods of using arrays as function parameters in shell
- DOM 渲染系统(render mount patch)响应式系统
猜你喜欢

On the setting of global variable position in C language

Low code momentum, this information management system development artifact, you deserve it!

记忆化搜索 AcWing 901. 滑雪

【点云处理之论文狂读前沿版10】—— MVTN: Multi-View Transformation Network for 3D Shape Recognition

LeetCode 438. Find all letter ectopic words in the string

Dom4j traverses and updates XML

LeetCode 515. Find the maximum value in each tree row

LeetCode 715. Range module

AcWing 786. Number k

Concurrent programming (VI) ABA problems and solutions under CAS
随机推荐
LeetCode 1089. 复写零
Education informatization has stepped into 2.0. How can jnpf help teachers reduce their burden and improve efficiency?
LeetCode 871. Minimum refueling times
LeetCode 30. Concatenate substrings of all words
AcWing 787. 归并排序(模板)
LeetCode 508. 出现次数最多的子树元素和
【点云处理之论文狂读经典版11】—— Mining Point Cloud Local Structures by Kernel Correlation and Graph Pooling
LeetCode 324. Swing sort II
Gaussian elimination acwing 883 Gauss elimination for solving linear equations
MySQL three logs
In the digital transformation, what problems will occur in enterprise equipment management? Jnpf may be the "optimal solution"
Methods of using arrays as function parameters in shell
20220630学习打卡
dried food! What problems will the intelligent management of retail industry encounter? It is enough to understand this article
Get the link behind? Parameter value after question mark
拯救剧荒,程序员最爱看的高分美剧TOP10
数字化管理中台+低代码,JNPF开启企业数字化转型的新引擎
LeetCode 515. Find the maximum value in each tree row
传统办公模式的“助推器”,搭建OA办公系统,原来就这么简单!
PHP uses foreach to get a value in a two-dimensional associative array (with instances)