0
已解决
高乐彤
修练者
修练者
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstdlib>
using namespace std;
string pos,m,r;
int n,cnt;
string sj(string a,string b){
string ans=pos;
int c[1010],d[1010],h[1010],n1,n2,jw=0;
for(int i=0;i<=1000;i++){
c[i]=0;
d[i]=h[i]=c[i];
}
n1=a.size();
n2=b.size();
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
for(int i=0;i<n1;i++)
c[i]=(int)(a[i]-'0');
for(int i=0;i<n2;i++)
d[i]=(int)(b[i]-'0');
if(n1>n2)
swap(n1,n2);
for(int i=0;i<n2;i++)
h[i]=c[i]+d[i];
for(int i=0;i<n2;i++){
jw=h[i]/n;
h[i]=h[i]%n;
h[i+1]+=jw;
jw=0;
}
if(h[n2]!=0)
ans+=h[n2]+'0';
for(int i=n2-1;i>=0;i--)
ans+=h[i]+'0';
return ans;
}string sj1(string a,string b){
string ans=pos;
int c[1010],d[1010],h[1010],n1,n2,jw=0;
for(int i=0;i<=1000;i++){
c[i]=0;
d[i]=h[i]=c[i];
}
n1=a.size();
n2=b.size();
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
for(int i=0;i<n1;i++){
if(a[i]<='9')
c[i]=a[i]-'0';
else
c[i]=a[i]-'A'+10;
}
for(int i=0;i<n2;i++){
if(b[i]<='9')
d[i]=b[i]-'0';
else
d[i]=b[i]-'A'+10;
}
if(n1>n2)
swap(n1,n2);
for(int i=0;i<n2;i++)
h[i]=c[i]+d[i];
for(int i=0;i<n2;i++){
jw=h[i]/16;
h[i]=h[i]%16;
h[i+1]+=jw;
jw=0;
}
if(h[n2]!=0){
if(h[n2]<10)
ans+=h[n2]+'0';
else
ans+=h[n2]-10+'A';
}
for(int i=n2-1;i>=0;i--){
if(h[i]<10)
ans+=h[i]+'0';
else
ans+=h[i]-10+'A';
}
return ans;
}
int main(){
cin>>n>>m;
if(n==16){
while(cnt<30){
cnt++;
r=m;
reverse(r.begin(),r.end());
m=sj1(m,r);
r=m;
reverse(r.begin(),r.end());
if(r==m){
cout<<"STEP="<<cnt;
return 0;
}
}
}else{
while(cnt<30){
cnt++;
r=m;
reverse(r.begin(),r.end());
m=sj(m,r);
r=m;
reverse(r.begin(),r.end());
if(r==m){
cout<<"STEP="<<cnt;
return 0;
}
}
}
cout<<"Impossible!";
return 0;
}
哪错了?