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虚拟机监控指