CSP-S day1

T1 temporarily change the title (huan)
1.1 Description title
and now have half past eight, pufanyi now because std pan is autistic, and decided to temporarily change the title. Original
to the Day1T1 will be moved Day2, and now you see the original Day2T1.
This problem was decimal count.
And general girls, like teaching little Di Jun Jun count.
Given two integers n and l r, for any x, satisfies l ≤ x ≤ r, x the number of all about all write
to. For each number written down, retaining only the highest digital bit. Seek times for each digital appears [91,].
Here is the divisor: For any positive integer y, if x a positive integer such that there exists a positive integer k kx = y, x is
a number from about y.
1.2 Input Output Format
1.2.1 input format
to read from the file huan.in.
Input line two positive integers l and r.
1.2.2 output format
output to a file huan.out in.
Output line 9 non-negative integers, each separated by a space between the two numbers, the i-th digital i represents the
number of times the current.
1.3 Sample
1.3.1 Sample input
14
1.3.2 Output Sample 1
421100000
1.3.3 Sample 1 illustrates
a number from about the highest number of bits
1 1 1
2 1, 2 1, 2
31, 31 3
41, 2, 41, 2, 4
1.3.4 Input Sample 2
233 238
1.3.5 Sample 2 outputs
13104221301
1.3.6 Sample 2 explains
submultiple number MSB
2331, 2331, 2
234 1, 2, 3, 6, 9, 13, 18, 1, 2, 3, 6, 9, 1, 1, 2, 3, 7, 1, 2
26, 39, 78, 117 234
2351, 5, 47, 2351, 5, 4, 2
2361, 2, 4, 59, 118, 2361, 2, 4, 5, 1, 2,
237 1, 3, 79, 2371, 3, 7, 2
238 1, 2, 7, 14, 17, 1, 2, 7, 1, 1, 3, 1, 2
34 119 238
1.4 data range and prompted
the present problem in all 10 test points, 10 points for each test point.
For all test points have l ≤ r.
Specific limits for each test point in the table below.
No special properties test point r
1 ~ 2 ≤ 10000 no
. 3 ~. 5 ≤ 107
. 6. 7 ~ r ≤ 109 - 1000 ≤ L
. 8 ~ 10 No
The answer to this question has 32-bit integer overflow risk, so be sure to use 64-bit integer when statistical answer.

 


Ideas:
the meaning of the questions can be obtained ans [getmax (i)] + = n / i
violence, then 1e7 can lead directly to 50 points, 1e9 will TLE
because in fact need only consider the most significant contribution to the answers, and we found a certain period of range the contribution of the answers is the same
, such as (50, 100] = 1
and the interval of (n / k + 1, n / k], the contribution value of K;
enumeration traversal different from the first section
1 -> (10,19 ) -> (100-199)
and then in accordance with this interval (n / k + 1, n / k] is divided interval
final answer accumulating a (current section worth contribution) * d (interval length)
Example: 100
30-39 interval
a = 3, section 33 (30, 33) 100 / 2,100 = 34/2 = 50, 50 and 39 are compared (34, 39)
it is divided into (30,33) (34, 39)

 

 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 inline int read(){
 5     int s=0,w=1;
 6     char ch=getchar();
 7     while(ch<'0'||ch>'9'){if(ch=='-')w=-1,ch=getchar();}
 8     while(ch>='0'&&ch<='9'){s=s*10+ch-'0',ch=getchar();}
 9     return s*w;
10 }
11 ll ans[2][10],l,r;
12 inline void solve(int tot,int n){
13     for(int i=1;i<=9;i++){
14         for(int j=1;j*i<=n;j*=10){
15             D LL, L = I * J * 1LL, R & lt = min (I * * 1LL + J-J . 1 , (LL) n-); // D interval length, l, r around the boundary 
16              for (K LL = L; K <= R & lt; K + = D) {
 . 17                  LL a = n-/ K, B = n-% K; // a unified contribution section, B = Na * K; 
18 is                  D = . 1 + min (B / a , rk); // B / a = n-/ AK, (n-/ a) is the value of the breakpoint, rk prevent cross-border 
. 19                  ANS [TOT] [I] = a * + D; 
 20 is              } 
 21 is          }
 22 is      }
 23 is  }
 24  int main () {
 25      The freopen ( " huan.in " , "r", stdin);
26     freopen("huan.out", "w", stdout);
27     scanf("%d%d", &l, &r);
28     solve(0, r), solve(1, l - 1);
29     for (int i = 1; i <= 9; ++i) {
30         printf("%lld ", ans[0][i] - ans[1][i]);
31     }
32     return 0;
33 }

Guess you like

Origin www.cnblogs.com/Shayndel/p/11822280.html