P5965 [PA 2019] A+B
题目描述
在列竖式计算两个十进制数的和的时候,人们可能会错算成这样:

在图里的左边,248+208248+208248+208 被错算成了 441644164416。
给定正整数 nnn,问有多少对非负整数 a,ba,ba,b 满足 a+ba+ba+b 会被错算成 nnn。
请注意 aaa 可以等于 bbb,且 a=1,b=2a=1,b=2a=1,b=2 和 a=2,b=1a=2,b=1a=2,b=1 是两种不同的方案。
输入格式
第一行包含一个正整数 nnn。
输出格式
输出一个整数,即满足条件的 a,ba,ba,b 的数量。
输入输出样例 #1
输入 #1
112
输出 #1
50
说明/提示
对于 100%100\%100% 的数据,1≤n<10181\le n<10^{18}1≤n<1018。
C++实现
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
inline void read(int &x) {
int f = 1; x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {if (ch == '-') f = -1; ch = getchar();}
while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
x *= f;
}
const int maxn=25;
int len,a[maxn];
string s;
ll f[maxn];
int main(){
cin>>s;
len=s.size();
for(int i=1;i<=len;i++)
a[i]=s[i-1]-'0';
f[0]=1;
for(int i=1;i<=len;i++){
f[i]=f[i-1]*(a[i]+1);
if(i>=2&&a[i-1]==1)
f[i]+=f[i-2]*(9-a[i]);
}
printf("%lld",f[len]);
return 0;
}

后续
接下来我会不断用C++来实现信奥比赛中的算法题、GESP考级编程题实现、白名单赛事考题实现,记录日常的编程生活、比赛心得,感兴趣的请关注,我后续将继续分享相关内容
4万+

被折叠的 条评论
为什么被折叠?



