_TeaClaudz_ @ 2023-08-07 20:44:14
#include<bits/stdc++.h>
using namespace std;
int n;
char st[7] = "ABCDEF";
void add(string &a) {
string b = a;
reverse(b.begin(), b.end());
int na[105], nb[105], l = a.length();
for(int i = 0; i < l; ++i) {
na[l - i - 1] = isdigit(a[i])?a[i]-'0':a[i]-'A'+10;
nb[l - i - 1] = isdigit(b[i])?b[i]-'0':b[i]-'A'+10;
}
for(int i = 0; i < l; ++i) {
na[i] += nb[i];
if(na[i] >= n) na[i+1]+=na[i]/n, na[i]%=n;
}
if(na[l]) l++;
for(int i = 0; i < l; ++i) {
a[i] = na[l - i - 1] < 10?na[l-i-1]+'0':st[na[l-i-1]-10];
}
}
int main() {
string a, t;
cin >> n >> a;
for(int i = 0; i <= 30; ++i) {
t = a;
reverse(t.begin(), t.end());
if(t == a) {
cout << "STEP=" << i;
return 0;
}
add(a);
}
cout << "Impossible!";
return 0;
}
by _TeaClaudz_ @ 2023-08-07 20:47:26
测试点输出全是"Impossible!",不知道什么问题T_T
by I_am_a_rookie_O @ 2023-08-07 21:08:59
证明判断条件未执行,有可能是你递归出错
by _TeaClaudz_ @ 2023-08-07 21:14:38
@DU654321 新的代码,但是只有本地能过
#include<bits/stdc++.h>
using namespace std;
int n;
char st[17] = "0123456789ABCDEF";
void add(string &a) {
string b = a;
reverse(b.begin(), b.end());
int na[105], nb[105], l = a.length();
for(int i = 0; i < l; ++i) {
na[l - i - 1] = isdigit(a[i])?a[i]-'0':a[i]-'A'+10;
nb[l - i - 1] = isdigit(b[i])?b[i]-'0':b[i]-'A'+10;
}
int x;
/*
a1=8 a0=7 b1=7 b0=8
a0=7+8=15
x=1
a0=5
a1=8+7+1=16
x=1
a1=6
*/
for(int i = 0; i < l; ++i) {
na[i] += nb[i] + x;
x = na[i] / n;
na[i] %= n;
}
if(x) na[l] = x, l++;
while(na[l] == '0') l--;
//cout << l << endl;
a.clear();
for(int i = l - 1; i >= 0; --i) {
a += st[na[i]];
//cout << st[na[i]] << " a:"<< a << endl;
}
}
int main() {
string a, t;
cin >> n >> a;
for(int i = 0; i < 30; ++i) {
t = a;
reverse(t.begin(), t.end());
//cout << "a:" << a << " t:" << t << endl;
if(t == a) {
cout << "STEP=" << i;
return 0;
}
add(a);
}
cout << "Impossible!";
return 0;
}
by _TeaClaudz_ @ 2023-08-07 21:15:41
@DU654321 奥,结论出来了,x没初始化()
by I_am_a_rookie_O @ 2023-08-07 21:20:44
聪明,6我居然没想到T-T