卷王 @ 2022-11-02 20:49:26
#include <bits/stdc++.h>
using namespace std;
int n, step = 0;
int len;
string s1, s2;
inline void work() //计算s2并累加
{
for(int i = 0; i < len; i++)
s2[len-i-1] = s1[i];
len += 2;
for(int i = 0; i < len; i++)
{
s1[i] = s1[i] + s2[i];
s1[i+1] += s1[i] / n;
s1[i] %= n;
}
while(!s1[len-1]) len--;
}
inline bool check() //判断是否是回文数
{
for(int i = 0; i < len / 2; i++)
if(s1[i] != s1[len-i-1]) return false;
return true;
}
int main()
{
cin >> n >> s1;
len = s1.size();
for(int i = 0; i < len; i++)
{
if(s1[i] >= '0' && s1[i] <= '9') s1[i] = s1[i] - '0';
else s1[i] = s1[i] - 'A' + 10;
}
while(check() == false)
{
step++;
if(step > 30) break;
work();
}
if(step <= 30) cout << "STEP=" << step;
else cout << "Impossible!";
return 0;
}
RERERERE
by AK_SLS @ 2022-11-02 20:53:05
开一下O2就好了
by 2011Andy @ 2022-11-02 20:53:08
评测里面你过了呀?
by 卷王 @ 2022-11-02 20:54:41
@2011Andy 啊不是,那人和我不一样OK吗?你仔细看看。。。
by 卷王 @ 2022-11-02 20:55:12
@AK_SLS @2011Andy 不过现在我过了
by 2011Andy @ 2022-11-02 20:56:09
emmmmm...........................
by 卷王 @ 2022-11-02 20:56:27
@2011Andy 你看看,问题解决了
by 卷王 @ 2022-11-02 20:57:20
@AK_SLS 如果比赛上不能开O2我怎么写?
by 2011Andy @ 2022-11-02 20:57:55
6
by AK_SLS @ 2022-11-02 21:00:47
现在CSP都是开O2的
by 2011Andy @ 2022-11-02 21:01:25
虽然@的不是我但我还是给你kangkang (看看)
求关QAQ
#include<iostream>
#include<cstring>
using namespace std;
int n,a[101],b[101],ans,i;
void init(int a[])
{
string s;
cin>>n>>s;
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;
}
}
bool check(int a[])
{
for(i=1; i<=a[0]; i++)
{
if(a[i]!=a[a[0]-i+1]) return false;
}
return true;
}
void jia(int a[])
{
for(int i=1; i<=a[0]; i++) b[i]=a[a[0]-i+1];
for(int i=1; i<=a[0]; i++) a[i]+=b[i];
for(int i=1; i<=a[0]; i++)
{
a[i+1]+=a[i]/n;
a[i]%=n;
}
if(a[a[0]+1]>0) a[0]++;
}
int main()
{
init(a);
if(check(a))
{
cout<<0<<endl;
return 0;
}
ans=0;
while(ans++<=30)
{
jia(a);
if(check(a))
{
cout<<"STEP="<<ans<<endl;
return 0;
}
}
cout<<"Impossible!"<<endl;
return 0;
}