itzy @ 2022-10-19 19:49:36
云剪贴板网址: https://www.luogu.com.cn/paste/qwdyk3ju 代码如下:
#include <bits/stdc++.h>
using namespace std;
int m[500],mm[500],len;
void get(string x)
{
len=x.size();
for (int i=0; i<len; i++)
{
if (x[i]>='0' && x[i]<='9')
{
m[i]=x[i]-'0';
}
else
{
m[i]=x[i]+'A'-10;
}
}
}
void plus(int n)
{
for (int i=0; i<len; i++)
{
mm[0+j]=m[len-1-j];
}
for (int j=0; j<len; j++)
{
m[j]+=mm[j];
if (m[j]>=n)
{
m[j+1]+=m[j]/n;
m[j]%=n;
if (j+1==len) len++;
}
}
}
bool huwe()
{
for (int j=0; j<=len/2; j++)
{
if (m[j]!=m[len-1-i]) return false;
}
return true;
}
int main()
{
int n;
string s;
cin >> n;
cin >> s;
get(s);
for (int k=3; k<=30; k++)
{
plus(n);
if (huwe())
{
cout << "STEP=" << k;
return 0;
}
}
cout << " Impossible!" << endl;
return 0;
}
by QianZezhong @ 2022-10-19 20:06:26
get函数的else里面应该是m[i]=x[i]-'A'+10吧 plus函数也有问题,要考虑连续进位。而且第一个循环应该是判断而不是赋值吧...?
by xingcode @ 2022-11-19 10:16:22
string s;
cin>>n>>s;
memset(a,0,sizeof(a));
a[0]=s.length();
for(i=1;i<=a[0];i++)
{
if(s[a[0]-
i]>='0'&&s[a[0]-i]
<='9')
{
a[i]=s[a[0]-i]-'0';
}
else
{
a[i]=s[a[0]-i]-'A'+10;
}
}
for(i=1;i<=a[0];i++)
{
if(a[i]!=a[a[0]-i+1])
return false;
}
return true;
for(i=1;i<=a[0];i++)
{
b[i]=a[a[0]-i+1];
}
for(i=1;i<=a[0];i++)
{
a[i]=a[i]+b[i];
}
for(i=1;i<=a[0];i++)
{
a[i+1]+=a[i]/n;
a[i]%=n;
}
if(a[a[0]+1]>0) a[0]++;
init(a);
if(check(a))
{
cout<<"STEP="<<0;
return 0;
}
s=0;
while(s<=30)
{
s++;
jia(a);
if(check(a))
{
cout<<"STEP="<<s;
return 0;
}
}
cout<<"Impossible!";
return 0;
by xingcode @ 2022-11-19 10:17:17
大概写了写