[BZOJ1833] [Zjoi2010]count Digit Count
Question Description
Given two positive integers a and B, for all integers in [a, b], how many times each digital (digit) appears.
Input
The input file contains only a row of two integers a, B, meaning as described above.
Output
The output file contains a row of 10 integers representing the number of times that 0-9 appears in [A, b].
Input example
1 About
Output example
9 - - - - - - - - -
Data size and conventions
30% of the data in,a<=b<=10^6;
100% of the data, a<=b<=10^12.
Exercises
Digital DP, many of the disgusting boundary conditions need to be considered.
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype > #include <algorithm>using namespace std; #define LL Long Longll Read () {ll x = 0, f = 1; char c = GetChar (); while (!isdigit (c)) {if (c = = '-') f =-1; c = GetChar ();} while (IsDigit (c)) {x = x * + C-' 0 '; c = GetChar ();} return x * f;} #define MAXN 20LL F[MAXN][MAXN][MAXN], ANS[MAXN], ten[maxn];void sum (LL x, int fl) {if (x < 0) return; if (!x) ans[0] + = Fl LL TOT[MAXN], tx = X;memset (tot, 0, sizeof (TOT)), int num[maxn], cnt = 0;while (x) num[++cnt] = x%, x/= 10;for (int k = 0; K <= 9; k++) for (int i = 1; i < CNT, i++) for (int j = (i = = 1 0:1); J <= 9; j + +) Tot[k] + = f[k][i][j];//for (int i = 0; I & Lt;= 9; i++) printf ("%lld%c", Tot[i], I < 9? ': ' \ n '), for (int i = cnt, I; i--) {LL sum = 0;for (int k = 0; k <= 9; k++) for (int j = (i = = cnt && i > 1?) 1:0); J < Num[i]; J + +) Tot[k] + = F[k][i][j];tot[num[i]] + = tx% ten[i-1] + 1;} //for (int i = 0; I <= 9; i++) printf ("%lld%c", Tot[i], I < 9? ': ' \ n '); for (int i = 0; I <= 9; i++) Ans[i] + + tot[i] * fl;return;} int main () {ten[0] = 1;for (int i = 1; i <; i++) ten[i] = ten[i-1] * 10;for (int k = 0; k <= 9; k++) F[k][1][k] = 1 ; for (int k = 0, K <= 9; k++) for (int i = 1; i <=; i++) for (int j = 0; J <= 9; j + +) {//if (k = = 1) printf ("%d" D:%lld\n ", K, I, J, F[k][i][j]); for (int x = 0; x <= 9; × x + +) f[k][i+1][x] + = F[k][i][j] + (x = = k) * Ten[i-1];} LL a = read (), B = read (); sum (b, 1); SUM (A-1,-1); for (int i = 0; I <= 9; i++) printf ("%lld%c", Ans[i], I < 9? ': ' \ n '); return 0;}
It's best to shoot with violence when you do it ...
[BZOJ1833] [Zjoi2010]count Digit Count