yzh091028 @ 2024-01-23 22:08:37
#include<bits/stdc++.h>
using namespace std;
int z[300],d[300],h[300];
int main(){
string m;
int n,ans=0;
cin>>n>>m;
int c1=-1;
for(int i=m.size()-1;i>=0;i--){
if(isdigit(m[i])){
z[++c1]=m[i]-'0';
d[i]=m[i]-'0';
}
else{
z[++c1]=m[i]-'A'+10;
d[i]=m[i]-'A'+10;
}
}
int l=m.size();
while(ans<=30){
int s=0;
for(int i=0;i<l;i++){
if(h[i]+z[i]+d[i]<n){
h[i]=h[i]+z[i]+d[i];
s++;}
else{
h[i]=(h[i]+z[i]+d[i])%n;
h[i+1]=(h[i]+z[i]+d[i])/n;
if(i==l-1){
s++;
}
}
}
int st=1;
for(int i=0;i<l/2;i++){
if(h[i]!=h[l-1-i]){
memset(z,0,sizeof(z));
memset(d,0,sizeof(d));
int c3=-1;
for(int i=l;i>=0;i--){
z[++c3]=h[i];
d[i]=h[i];
}
st=0;
break;
}
}ans++;
if(st==1){
cout<<"STEP="<<ans;
return 0;
}
}
cout<<"Impossible!";
}
by yuxingcheng @ 2024-01-24 00:01:25
代码给你:
#include<bits/stdc++.h>
#define up(l,r,i) for(int i=l,END##i=r;i<=END##i;++i)
#define dn(r,l,i) for(int i=r,END##i=l;i>=END##i;--i)
using namespace std;
typedef long long i64;
const int INF =2147483647;
const int MAXN=1e5+3;
int n,t,H[MAXN],F[MAXN];
int main(){
while(~scanf("%d",&H[++n])); --n;
t=0,memset(F,0,sizeof(F)),F[0]=INF;
up(1,n,i){
int l=0,r=t+1; while(r-l>1){
int m=l+(r-l)/2;
if(F[m]>=H[i]) l=m; else r=m;
}
int x=l+1; // dp[i]
if(x>t) t=x; F[x]=H[i];
}
printf("%d\n",t);
t=0,memset(F,0,sizeof(F)),F[0]=0;
up(1,n,i){
int l=0,r=t+1; while(r-l>1){
int m=l+(r-l)/2;
if(F[m]<H[i]) l=m; else r=m;
}
int x=l+1;
if(x>t) t=x; F[x]=H[i];
}
printf("%d\n",t);
return 0;
}