MnZn代码70pts离谱测评结果求调

P1591 阶乘数码

SiXinchen @ 2023-08-07 21:58:26

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

int main(){
    //freopen("xx.in","r",stdin);
    //freopen("xx.out","w",stdout);
    long long sum,n,t,x,top,b,toop;
    int a[100005],c[100005];
    scanf("%lld",&t);
    while(t--){
        memset(a,0,sizeof(a));
        sum=0,top=1;
        scanf("%lld %lld",&n,&x);
        a[1]=1;
        for(long long i=2;i<=n;i++){
            b=i;
            memset(c,0,sizeof(c));
            for(long long j=0;b;b/=10,j++){
                for(long long k=1;k<=top;k++){
                    c[k+j]+=a[k]*(b%10);
                    long long l=0;
                    while(c[k+j+l]>=10){
                        c[k+j+l+1]+=c[k+j+l]/10;
                        c[k+j+l]%=10;
                        l++;
                    }
                    toop=max(toop,k+j+l);
                }
            }
            for(long long j=1;j<=toop;j++){
                a[j]=c[j];
            }
            //cout<<top<<" ";
            top=toop;
            //cout<<top<<endl;
        }
        for(long long i=1;i<=top;i++){
            if(a[i]==x)sum++;
            //cout<<a[i]<<" 1 ";
        }
        printf("%lld\n",sum);
    }
    return 0;
}

前三个点WA了,没错,前三个点(悲


by __dreams__ @ 2023-08-17 20:50:39

#include <bits/stdc++.h>
using namespace std;
int a[20001],b[20001],c[20001];
int t,n,l; 
int anss;
string k;
string fun3(string x,string y){
    string s1;
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    int lenx=x.length();
    int leny=y.length();
    for(int i=0;i<lenx;i++){
        a[lenx-i-1]=x[i]-'0';
    }
    for(int i=0;i<leny;i++){
        b[leny-i-1]=y[i]-'0';
    }
    int lenc=lenx+leny;
    for(int i=0;i<lenx;i++){
        for(int j=0;j<leny;j++){
            c[i+j]+=a[i]*b[j];
        }
    }
    for(int i=0;i<lenc;i++){
        c[i+1]+=c[i]/10;
        c[i]%=10;
    }
    while(c[lenc-1]==0&&lenc>1){
        lenc--;
    }
    for(int i=lenc-1;i>=0;i--){
        s1=s1+to_string(c[i]);
    }
    return s1;
}
int main(){
    string ans,sum="1";
    cin>>t;
    for(int i=1;i<=t;i++){
        anss=0;
        cin>>n>>k;
        sum="1";
        for(int j=1;j<=n;j++){
            sum=fun3(sum,to_string(j));
        }
        l=sum.length();
        for(int j=0;j<l;j++){
            if(sum[j]==k[0]){
                anss++;
            }
        }
        cout<<anss<<"\n";
    }
    return 0;
}

这是我的 你看看哪错了


|