当前位置:网站首页>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 
边栏推荐
- Method of intercepting string in shell
- LeetCode 75. Color classification
- Escape from heaven and forget what he suffered. In ancient times, it was called the punishment of escape from heaven. Article collection
- Log4j2 vulnerability recurrence and analysis
- LeetCode 513. Find the value in the lower left corner of the tree
- too many open files解决方案
- 我們有個共同的名字,XX工
- TP5 order multi condition sort
- Life cycle of Servlet
- Concurrent programming (III) detailed explanation of synchronized keyword
猜你喜欢

Debug debugging - Visual Studio 2022

Binary tree traversal (first order traversal. Output results according to first order, middle order, and last order)

LeetCode 532. K-diff number pairs in array

Complex character + number pyramid

Common penetration test range

LeetCode 1089. 复写零

What is an excellent fast development framework like?

数位统计DP AcWing 338. 计数问题

浅谈企业信息化建设

一个优秀速开发框架是什么样的?
随机推荐
URL backup 1
PIC16F648A-E/SS PIC16 8位 微控制器,7KB(4Kx14)
Binary tree traversal (first order traversal. Output results according to first order, middle order, and last order)
Analysis of Alibaba canal principle
LeetCode 515. Find the maximum value in each tree row
Escape from heaven and forget what he suffered. In ancient times, it was called the punishment of escape from heaven. Article collection
SQL statement error of common bug caused by Excel cell content that is not paid attention to for a long time
Debug debugging - Visual Studio 2022
Life cycle of Servlet
Dom4j traverses and updates XML
Es8 async and await learning notes
LeetCode 57. 插入区间
AcWing 788. Number of pairs in reverse order
LeetCode 1089. Duplicate zero
状态压缩DP AcWing 291. 蒙德里安的梦想
干货!零售业智能化管理会遇到哪些问题?看懂这篇文章就够了
<, < <,>, > > Introduction in shell
LeetCode 532. K-diff number pairs in array
Find the combination number acwing 885 Find the combination number I
Concurrent programming (VI) ABA problems and solutions under CAS