BZOJ 1833 [ZJOI 2010] 数字统计 (数位DP)

题目链接:BZOJ 1833

听说这道是一道水DP(Orz).

我到现在都不知道BZOJ上long long要用I64d输出,还是用lld输出Orz。应该是lld吧(DK)。反正我用I64d输出一直PE,改用cout就A了(这个傲娇的评测机= =)。

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define LL long long

LL A,B;
int a[30];
LL c[20],num[20];

void init(){
	LL base=1;
	for(int i=1;i<=12;i++){
		c[i]=c[i-1]*10+base;
		base*=10;
	}
}

void work(LL x,LL y){
	while(x){
		num[x%10]+=y; x/=10;
	}
}

void get(LL N,int l,int col){
	LL base=1;
	int i;
	for(i=1;i<l;i++){
		for(int j=0;j<=9;j++){
			num[j]+=c[i-1]*col*9;
		}
		for(int j=1;j<=9;j++){
			num[j]+=base*col;
		}
		base*=10;
	}
	
	LL now=base; i--;
	while(now<N){
		while(now+base<=N){
			LL t=now/base;
			work(t,base*col);
			for(int j=0;j<=9;j++){
				num[j]+=c[i]*col;
			}
			now+=base;
		}
		base/=10; i--;
	}
}

void find(LL N,int col){
	int tot=0;
	LL temp=N;
	while(temp){
		a[++tot]=temp%10; temp/=10;
	}
	get(N,tot,col);
}

int main(){
	init();
	cin>>A>>B;
	find(B+1,1);
	find(A,-1);
	
	for(int i=0;i<=9;i++){
		cout<<num[i];
		if(i!=9)printf(" ");//最后输出格式要注意啊,否则会PE
	}
	return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值