为什么,为什么25分(痛苦,扭曲爬行)(嘶吼)(四肢分裂)

P1015 [NOIP1999 普及组] 回文数

emu_ @ 2023-07-25 16:03:07

#include<bits/stdc++.h>
using namespace std;
long long n,a[10005],l,b[10005],ans;
string s;
void cuiz()
{
    int j=0;
    for(int i=0;i<l;i++)
    {
        if(s[i]>='0' && s[i]<= '9') 
            a[++j]=s[i]-'0';
        else 
            a[++j]=s[i]-'A'+10;
    }
}
bool pand()
{
    int le=l,i=1,j=l;
    while(le--)
    {
        if(le<l/2)
            break;
        if(a[i]!=a[j])
            return 1;
        i++;
        j--;
    }
    return 0;
}
void fanz()
{
    int j=0;
    for(int i=l;i>=1;i--)
        b[++j]=a[i];

}
void jia()
{
    for(int i=1;i<=l;i++)
    {
        a[i]+=b[i];
        a[i+1]+=a[i]/10;
        a[i]%=n;
    }
    if(a[l+1]>0) l++;
}
int main()
{
     cin>>n>>s;
     l=s.length();
     cuiz();
     while(pand())
    {
        fanz();
        jia();
        ans++;
        if(ans>30)
        {
            break;
        }
    } 
    if(ans<=30)
        cout<<"STEP="<<ans;
    else
        cout<<"Impossible!";
    return 0;
}

by lyx2011 @ 2023-07-25 16:31:19

#include <bits/stdc++.h>

using namespace std;

const int N = 105;

int a[N], b[N];
int n, len;
string m;

bool check() {
    for (int i = 0; i < len; ++i) {
        if (a[i] != a[len - i - 1]) {
            return false;
        }
    }
    return true;
}

void ps() {
    for (int i = 0; i < len; ++i) {
        b[i] = a[len - i - 1];
    }
    for (int i = 0; i < len; ++i) {
        a[i] += b[i];
    }
    for (int i = 0; i < len; ++i) {
        a[i + 1] += a[i] / n;
        a[i] %= n;
    }
    if (a[len]) {
        ++len;
    }
}

int main() {
    scanf("%d", &n);
    cin >> m;
    len = m.size();
    for (int i = 0; i < len; ++i) {
        if (m[i] >= '0' && m[i] <= '9') {
            a[i] = m[len - 1 - i] - '0';
        } else {
            a[i] = m[len - 1 - i] - 'A' + 10;
        }
    }

    int step;
    for (step = 1; step <= 30; ++step) {
        ps();
        if (check())
            break;
    }

    if (step <= 30) {
        cout << "STEP=" << step << endl;
    } else {
        cout << "Impossible!" << endl;
    }

    return 0;
}

|