求条悬棺
查看原帖
求条悬棺
741580
niuqichongtian楼主2025/1/17 10:45

小号@ikunyyh

代码思路:首先找到规律,易有:

Eg:3793+37+379+7+79+93+30+7+300+70+9+7+70+9+9333+772+933331+772+933102+(3+72)101+(3+72+93)100514==========================================Eg:1145141+11+114+1145+11451+114514+1+14+145+1451+14514+4+45+451+4514+5+51+514+1+14+4111111+111112+44443+5554+115+461111111+111112+44443+5554+115+46(11)105+(11+12)104+(11+12+43)103+(11+12+43+54)102+(11+12+43+54+15)101+(11+12+43+54+15+46)100Eg:379\\ 3+37+379+7+79+9\\{\huge\Downarrow} \\ 3+30+7+300+70+9+7+70+9+9\\{\huge\Downarrow} \\ 333+77\cdot2+9\cdot3\\{\huge\Downarrow} \\ 333\cdot1+ 77\cdot2+ 9\cdot3\\{\huge\Downarrow} \\ 3\cdot10^2+(3+7\cdot2)\cdot10^1+(3+7\cdot2+9\cdot3)\cdot10^0\\ {\large 514} \\ ==========================================\\ Eg : 114514\\ 1+11+114+1145+11451+114514+1+14+145+\\1451+14514+4+45+451+4514+5+51+514+1+14+4\\{\huge\Downarrow} \\ 111111+11111\cdot2+4444\cdot3+555\cdot4+11\cdot5+4\cdot6\\{\huge\Downarrow} \\ 111111\cdot1+ 11111\cdot2+ 4444\cdot3+ 555\cdot4+ 11\cdot5+ 4\cdot6 \\{\huge\Downarrow} \\ (1\cdot1)\cdot 10^5+\\(1\cdot1+1\cdot2)\cdot10^4+\\(1\cdot1+1\cdot2+4\cdot3)\cdot10^3+\\(1\cdot1+1\cdot2+4\cdot3+5\cdot4)\cdot10^2+\\(1\cdot1+1\cdot2+4\cdot3+5\cdot4+1\cdot5)\cdot10^1+\\(1\cdot1+1\cdot2+4\cdot3+5\cdot4+1\cdot5+4\cdot6)\cdot10^0\\

最后加个高精度,进位一下即可

#include <bits/stdc++.h>
using namespace std;
#define int long long

const int maxn = 1e7+7;
int N;
int a[maxn];
int ans[maxn];

inline void print (int *b) {
    for (register int i = b[0]; i >= 1; i--)
        cout << b[i];
    cout << endl;
    return;
}

inline void get (void) {
    ans[0] = N;
    for (register int i = 1; i <= ans[0]; i++) {
        ans[i + 1] += ans[i] / 10;
        ans[i] %= 10;
    }
    return;
}

signed main(signed argc, char const *argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    char m;
    int k = 0;
    cin >> N;
    for (register int i = 1; i <= N; i++) {
        cin >> m;
        a[i] = m - 48;
    }
    int prefix = 0;
    for (register int i = 1; i <= N; i++) {
        prefix += i * a[i];
        ans[N-i+1] = prefix;
    }
    get();
    print(ans);
    return 0;
}
2025/1/17 10:45
加载中...