1833: [ZJOI2010]count 数字计数
生活随笔
收集整理的这篇文章主要介绍了
1833: [ZJOI2010]count 数字计数
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
1833: [ZJOI2010]count 数字计数
Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 2951 Solved: 1307
[Submit][Status][Discuss]
Description
给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次。Input
输入文件中仅包含一行两个整数a、b,含义如上所述。Output
输出文件中包含一行10个整数,分别表示0-9在[a,b]中出现了多少次。Sample Input
1 99Sample Output
9 20 20 20 20 20 20 20 20 20HINT
30%的数据中,a<=b<=10^6;
100%的数据中,a<=b<=10^12。
Source
Day1
//数位dp:[l,r]=[1,r+1)-[1,l) //论文:刘聪 《浅谈数位类统计问题》 #include<bits/stdc++.h> using namespace std; typedef long long ll; ll a,b,f[20],c[20]; void dp(ll x,ll flag){int i,j,k;ll pos,now;for(i=1,pos=10;pos<x;i++,pos*=10){for(j=0;j<=9;j++) f[j]+=c[i-1]*9*flag;for(j=1;j<=9;j++) f[j]+=pos/10*flag;}for(i--,now=(pos/=10);now<x;pos/=10,i--){for(;now+pos<=x;now+=pos){ll tmp=now/pos;for(;tmp;tmp/=10) f[tmp%10]+=pos*flag;for(j=0;j<=9;j++) f[j]+=c[i]*flag;}} } int main(){int i;ll pos;c[1]=1;for(i=2,pos=10;i<=12;i++,pos*=10)c[i]=c[i-1]*10+pos;cin>>a>>b;dp(b+1,1);dp(a,-1);for(i=0;i<=9;i++){cout<<f[i];if(i<9) cout<<' ';}return 0; }
转载于:https://www.cnblogs.com/shenben/p/6288039.html
总结
以上是生活随笔为你收集整理的1833: [ZJOI2010]count 数字计数的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: LAMP编译安装1
- 下一篇: 通过libVirt抓取kvm虚拟机监控指