跳到正文

题解

题解:AT_agc066_b [AGC066B] Decreasing Digit Sums

qnqfff约 2 分钟
原文
文章信息与版本

文章信息

发布
2024年12月24日
收录
2026年8月16日
更新
2026年11月8日
篇幅
约 2 分钟

版本

  1. v1当前

思路

首先发现 55 这个数很强啊,你发现大部分 f(5i)<f(5i+1)f(5^i)<f(5^{i+1}),你考虑把若干个 5i5^i 拼起来用 00 隔开,那么一次减少的量十分巨大,且增加的量一定不如减少的量,然后写个高精度就做完了。

代码

C++
#include<bits/stdc++.h>
#define int long long 
using namespace std;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<23],*p1=buf,*p2=buf;
int read(){char c=getchar();int p=0,flg=1;while(c<'0'||c>'9'){if(c=='-') flg=-1;c=getchar();}while(c>='0'&&c<='9'){p=p*10+c-'0';c=getchar();}return p*flg;}
int n,a[10010];
signed main(){
	a[0]=1;a[1]=5;vector<int>ans;ans.push_back(5);
	int lst=0;
	for(int i=1;i<=150;i++){
		int tag=0;for(int j=1;j<=a[0];j++){
			int v=a[j]*5+tag;
			if(v<10) a[j]=v,tag=0;else a[j]=v%10,tag=v/10;
		}if(tag) a[++a[0]]=tag;
		for(int j=1;j<=10;j++) ans.push_back(0);
		int sum=0;
		for(int j=1;j<=a[0];j++) ans.push_back(a[j]),sum+=a[j];
		assert(lst>sum);
	}reverse(ans.begin(),ans.end());for(auto i:ans) cout<<i;
	return 0;
}
原文