当前位置:网站首页>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 
边栏推荐
- Concurrent programming (V) detailed explanation of atomic and unsafe magic classes
- 数字化管理中台+低代码,JNPF开启企业数字化转型的新引擎
- Solution of 300ms delay of mobile phone
- too many open files解决方案
- LeetCode 871. 最低加油次数
- AcWing 787. Merge sort (template)
- 常见渗透测试靶场
- cres
- 【点云处理之论文狂读经典版8】—— O-CNN: Octree-based Convolutional Neural Networks for 3D Shape Analysis
- 高斯消元 AcWing 883. 高斯消元解线性方程组
猜你喜欢

LeetCode 241. Design priorities for operational expressions

Notes and bugs generated during the use of h:i:s and y-m-d

LeetCode 513. 找树左下角的值

LeetCode 513. Find the value in the lower left corner of the tree

ES6 promise learning notes
![[set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q](/img/76/6561a78b7f883a0e75a53e037153c3.jpg)
[set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q

Life cycle of Servlet

Gaussian elimination acwing 883 Gauss elimination for solving linear equations

求组合数 AcWing 885. 求组合数 I

传统企业数字化转型需要经过哪几个阶段?
随机推荐
传统企业数字化转型需要经过哪几个阶段?
【点云处理之论文狂读经典版8】—— O-CNN: Octree-based Convolutional Neural Networks for 3D Shape Analysis
PHP mnemonic code full text 400 words to extract the first letter of each Chinese character
【点云处理之论文狂读前沿版10】—— MVTN: Multi-View Transformation Network for 3D Shape Recognition
求组合数 AcWing 886. 求组合数 II
LeetCode 715. Range module
Concurrent programming (III) detailed explanation of synchronized keyword
Low code momentum, this information management system development artifact, you deserve it!
dried food! What problems will the intelligent management of retail industry encounter? It is enough to understand this article
Alibaba canaladmin deployment and canal cluster Ha Construction
AcWing 788. 逆序对的数量
LeetCode 515. Find the maximum value in each tree row
Six dimensional space (C language)
Find the combination number acwing 885 Find the combination number I
LeetCode 241. 为运算表达式设计优先级
Basic knowledge of network security
剑指 Offer II 029. 排序的循环链表
传统办公模式的“助推器”,搭建OA办公系统,原来就这么简单!
22-06-28 西安 redis(02) 持久化机制、入门使用、事务控制、主从复制机制
我們有個共同的名字,XX工