[Luogu 2529] [SHOI 2001] flower drum transfer

[Problem of] the original title Portal

[Effect] problem solution

This problem solution written in a very clear and easy to understand, I will not go into details.

Talk about the thing I read in the above blog is not written out directly but may affect the understanding of things:

f(x) = f(x/5) × a(x % 20)

Known non-zero after the last one must be an even number, the number 20 we consider each into a group, so that they are multiplied == 4 * 4% 10 6

(No matter how much is, no effect on the product are not behind a number of points.

Algorithm to achieve:

We give the number denoted by x, since the answer to ans [x].

1% high-precision single-precision (20) = y;

2. record the answers as ans [x] = a [y] * ans [x / 5];

years [x] = a [y] * years [x / 5] = a [y 1] * a [y 2] * years [x / 5/5] = ...

Until x <20.

About a pre-array should be:

4, 1 / 2,5,6,7,8,9,1 / 2,11,12,13,14,1 / 2,16,17,18,19,1 / 2 take the time to remember the prefix and 10%.

Each packet number 20, the number less than the number of the sub-group number less than 20. That number is less than 20 we require pretreatment.

【code】

#include<bits/stdc++.h>
using namespace std;
#define File ""
#define ll long long
inline void file(){
    freopen(File".in","r",stdin);
    freopen(File".out","w",stdout);
}
const int mxn = 110;
char s[mxn];
int T,a[mxn],b[22],n;

inline int calc1(){
    return (a[2]*10+a[1]) % 20;
}

inline void calc2(){
    int t = 0;
    for(int i = n;i >= 1; --i){
        t = t*10+a[i];
        a[i] = t/5;
           t = t%5;
    }
}
int ans;
int main(){
//    file();
    T = 5,b[0] = 1;
    for(int i = 1;i <= 20; ++i){
        if(!(i%5)) b[i] = b[i-1]/2%10;
        else b[i] = b[i-1]*i%10;
    }
//    for(int i = 1;i <= 20; ++i) printf("%d ",b[i]);
//    puts("");
    while(T--){
        scanf("%s",s+1);
        n = strlen(s+1);
        for(int i = 1;i <= n; ++i) a[n-i+1] = s[i]-'0';
        ans = 1;
        while(n > 0){
            while(a[n]==0) n--;
            year = years * b [calc1 ()]% 10 ;
            calc2();
        }
        printf("%d\n",ans);
    }
    return 0;
}
/*
11
12
13
14
15
*/
View Code

 

Guess you like

Origin www.cnblogs.com/ve-2021/p/11076619.html