xpg007 @ 2024-05-03 16:48:52
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
vector<int> b;
int main() {
int n;
string s;
cin >> n >> s;
for (int i = 0; i < s.size(); i++){
if (s[i] >= '0' && s[i] <= '9')
a.push_back(s[i] - '0');
else
a.push_back(s[i] - 'A' + 10);
}
b = a;
reverse(a.begin(), a.end());
if (a == b){
cout << "STEP=0";
return 0;
}
for (int i = 1; i <= 30; i++) {
for (int j = 0; j < a.size(); j++) {
a[j] += b[j];
if (j != a.size() - 1)
a[j + 1] += a[j] / n;
else if (a[j] >= n)
a.push_back(a[j] / n);
a[j] %= n;
}
b = a;
reverse(b.begin(), b.end());
if (a == b){
cout << "STEP=" << i;
return 0;
}
}
cout << "Impossible!";
return 0;
}
by StarsIntoSea_SY @ 2024-05-03 17:06:36
@xpg007 ???开 O2 25分 , 不开又 75分了??
by StarsIntoSea_SY @ 2024-05-03 17:07:13
@xpg007 为什么我这边样例都没过啊
by xpg007 @ 2024-05-03 17:07:26
@StarsIntoSea_SY
我的50分啊!
by StarsIntoSea_SY @ 2024-05-03 17:08:24
@xpg007 你把你评测记录发一下
by xpg007 @ 2024-05-03 17:09:39
@StarsIntoSea_SY
#1
by StarsIntoSea_SY @ 2024-05-03 17:53:00
@xpg007 抱歉,你这个我改不了,因为会出现相同的输入不同的输出,我也不太清楚为什么。而且你这个计算时会有负数,我不经常用 vetcor 但我的建议是换成普通数组而非 vector ,可以参考一下我的:
#include <iostream>
#include <stdio.h>
#include <cstring>//回文数
using namespace std;
char a1[300];
int a[300],b[300],len,m;
void into(){ //倒转操作
for(int i=1;i<=len;i++)
b[i]=a[len-i+1];
}
bool po(){ //判断是否回文
for(int i=1;i<=len;i++)
if(a[i]!=b[i]) return false;
return true;
}
void solve(int t){
if(t>30){
cout<<"Impossible!"<<endl;
return ;
}
into();
if(po()){
cout<<"STEP="<<t<<endl;
return ;
}
int x=0;
for(int i=1;i<=len;i++){
a[i]=a[i]+b[i]+x;
x=a[i]/m;
a[i]%=m;
}
a[len+1]=x;
while(a[len+1]>0) len++; //重新判断长度
solve(t+1);
}
int main(){
cin>>m;
scanf("%s",a1);
len=strlen(a1);
for(int i=0;i<len;i++){
if(a1[i]>='0' && a1[i]<='9') a[len-i]=a1[i]-'0';
else a[len-i]=a1[i]+10-'A';
}
solve(0);
}
by xpg007 @ 2024-05-03 20:51:39
@StarsIntoSea_SY
谢谢,但你加团吗QwQ
by StarsIntoSea_SY @ 2024-05-03 22:03:09
@xpg007 可以,但不出题