1 条题解

  • 0
    @ 2025-4-14 18:41:38

    C++ :

    #include<stdlib.h>
    #include<stdio.h>
    #include<string.h>
    int main()
    {
        int k,n,a[101],c[101];
        char st[101];
        scanf("%d",&k);
        scanf("%s",st);
        n=strlen(st);
        memset(a,0,sizeof(a));
        for(int i=0;i<n;i++)
        {
            if(st[i]>='0' && st[i]<='9') a[i]=st[i]-'0';
            else if(st[i]>='A' && st[i]<='Z') a[i]=st[i]-55;
        }
        int step=0,b=1;
        for(int i=0;i<=(n/2)-1;i++)
            if(a[i]!=a[n-i-1]) b=0;
        while(b==0)
        {
            step++;
            for(int i=0;i<n;i++)
                c[i]=a[n-i-1];
            for(int i=0;i<n;i++)
            {
                a[i]+=c[i];
                if(a[i]>=k)
                {
                    a[i]-=k;
                    a[i+1]++;
                }
            }
            if(a[n+1-1]>0) n++;
            b=1;
            for(int i=0;i<=(n/2)-1;i++)
                if(a[i]!=a[n-i-1]) b=0;
            if(step>=30) {printf("Impossible!");
            return 0;}
        }
        printf("STEP=%d",step);
        return 0;
    }
    
    • 1

    信息

    ID
    3186
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    (无)
    递交数
    0
    已通过
    0
    上传者