Count number counts (Bzoj 1833)

Source: Internet
Author: User

Description given two positive integers a and B, for all integers in [a, b], how many times each digital (digit) appears. Only one line of two integers a, B, is included in the input file, meaning as described above. The output file contains a row of 10 integers representing the number of times that 0-9 appears in [A, b]. Sample Input1 99
Sample Output9 20 20 20 20 20 20 20 20 20
HINT

30% of the data in,a<=b<=10^6;
100% of the data, a<=b<=10^12.

/*make F[i] The number of occurrences of each number in the I-digit (the leading 0) (must be the same, so only one is recorded) there is f[i]=f[i-1]*10+10^ (i-1)*/#include<cstdio>#include<iostream>#defineLon Long Longusing namespaceStd;lon ans[ -],f[ -];voidResolve (Lon X,lon POS) { while(x) ans[x%Ten]+=pos,x/=Ten;}voidDP (Lon X,lon flag) {intI,j;lon Pos,now;  for(i=1, pos=Ten;p os<x;i++,pos*=Ten){//"integer" section         for(j=0; j<=9; j + +) Ans[j]+=f[i-1]*9*Flag;  for(j=1; j<=9; j + +) Ans[j]+=pos/Ten*Flag; } Now=pos/=Ten; i--;  while(now<x) {//The decimals Section         while(now+pos<=x) {Lon temp=now/POS; Resolve (Temp,pos*flag);  for(j=0; j<=9; j + +) Ans[j]+=f[i]*Flag; now+=POS; } POS/=Ten; i--; }    }intMain () {Lon a,b,pos;inti; f[1]=1;  for(i=2, pos=Ten; i<= A; i++,pos*=Ten) F[i]=f[i-1]*Ten+POS; CIN>>a>>b; DP (b+1,1);DP(a,-1);//differential     for(intI=0; i<=9; i++) printf ("%lld%c", ans[i],i==9?'\ n':' '); return 0;}

Count number counts (Bzoj 1833)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.