萌新妹纸刚学OI,RE求助
查看原帖
萌新妹纸刚学OI,RE求助
227728
冰糖鸽子TJ鸽子协会楼主2021/6/30 12:21

RT,除了主函数都是从数字计数那题的AC代码搬过来的,空格也处理的,但是是点1就RE


// Problem: P2602 [ZJOI2010]数字计数
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P2602
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define M 25
#define int long long
int L,R,len,T,f[4][M],tf,mb[M],pt[M],forw[M],back[M];
int Sol(int x,int y)//计算1-x的答案
{
	memset(mb,0,sizeof(mb));memset(forw,0,sizeof(forw));memset(f[y],0,sizeof(f[y]));len=0,tf=x;
	while(x) mb[++len]=x%10,x/=10;
	reverse(mb+1,mb+1+len);forw[len]=back[len]=tf;
	for(int i=len-1;i>=0;i--) forw[i]=forw[i+1]/10;
	for(int i=1;i<len;i++) back[i]=mb[len-i+1]*pt[i-1]+back[i-1];
	// for(int i=0;i<=len;i++) cout<<pt[i]<<' '; cout<<endl;
	// for(int i=0;i<=len;i++) cout<<back[i]<<' '; cout<<endl;
	for(int i=1;i<=len;i++)
	{
		for(int j=0;j<10;j++) f[y][j]+=forw[i-1]*pt[len-i];
		for(int j=0;j<mb[i];j++) f[y][j]+=pt[len-i];
		f[y][mb[i]]+=back[len-i]+1;f[y][0]-=pt[i-1];
	}
}
signed main()
{
	pt[0]=1;for(int i=1;i<=18;i++) pt[i]=pt[i-1]*10;
	cin>>L>>R;
	while(!(L==0&&R==0))
	{
		if(L>R) swap(L,R);
		Sol(R,1);Sol(L-1,0);
		for(int i=0;i<9;i++) cout<<f[1][i]-f[0][i]<<' ';
		cout<<f[1][9]-f[0][9];
		cin>>L>>R;
		cout<<endl;
	}
	return 0;
}
2021/6/30 12:21
加载中...