# 2021.11.24 P1015 [NOIP1999 普及组] 回文数(2021.11.24 p1015 [noip1999 popularity group] number of palindromes)-其他

## 2021.11.24 P1015 [NOIP1999 普及组] 回文数(2021.11.24 p1015 [noip1999 popularity group] number of palindromes)

``````题目描述

STEP1：87+78=16587+78=165
STEP2：165+561=726165+561=726
STEP3：726+627=1353726+627=1353
STEP4：1353+3531=48841353+3531=4884

10 87

STEP=4
``````
• 这道题主要练的是分块的想法
一开始我的想法是高精加一段，数字翻转一段，后来发现高精代码段太长了，再加上标程给的是数组转换一段，加法一段
–>看起来立刻舒服了
• 但还是有一些莫名其妙的问题
就比如说在洛谷上第一次交的时候WA掉了一个点
``````#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string.h>
using namespace std;
int n,a[10010],b[10010],ans,l;
void zhuanhuan()//输入加转换
{
string s;
cin>>n>>s;
memset(a,0,sizeof(a));
l=s.length();
for(int i=1;i<=l;i++)
{
if(s[l-i]>='0'&&s[l-i]<='9')a[i]=s[l-i]-'0';
else a[i]=s[l-i]-'A'+10;
}
}
bool check()//判断回文
{
for(int i=1;i<=l;i++)
{
if(a[i]!=a[l-i+1])return false;
}
return true;
}
void gaojing()//进位比较特殊
{
for(int i=1;i<=l;i++)b[i]=a[l-i+1];
for(int i=1;i<=l;i++)a[i]+=b[i];
for(int i=1;i<=l;i++)
{
a[i+1]+=a[i]/n;
a[i]%=n;
}
if(a[l+1]>0)l++;
}
int main()
{
zhuanhuan();
if(check())
{
printf("STEP=0\n");
return 0;
}
for(int ans=1;ans<=30;++ans)
{
gaojing();
if(check())
{
printf("STEP=%d\n",ans);
return 0;
}
}
printf("Impossible");
return 0;
}
``````
————————
``````题目描述

STEP1：87+78=16587+78=165
STEP2：165+561=726165+561=726
STEP3：726+627=1353726+627=1353
STEP4：1353+3531=48841353+3531=4884

10 87

STEP=4
``````
• This question is mainly about the idea of dividing blocks
At first, my idea was to add a high-precision segment and flip a number. Later, I found that the high-precision code segment was too long. In addition, the standard procedure gave an array conversion segment and an addition segment
–>It looks comfortable immediately
• But there are still some inexplicable problems
For example, WA dropped a point when it was handed over for the first time in Los Angeles
``````#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string.h>
using namespace std;
int n,a[10010],b[10010],ans,l;
void zhuanhuan()//输入加转换
{
string s;
cin>>n>>s;
memset(a,0,sizeof(a));
l=s.length();
for(int i=1;i<=l;i++)
{
if(s[l-i]>='0'&&s[l-i]<='9')a[i]=s[l-i]-'0';
else a[i]=s[l-i]-'A'+10;
}
}
bool check()//判断回文
{
for(int i=1;i<=l;i++)
{
if(a[i]!=a[l-i+1])return false;
}
return true;
}
void gaojing()//进位比较特殊
{
for(int i=1;i<=l;i++)b[i]=a[l-i+1];
for(int i=1;i<=l;i++)a[i]+=b[i];
for(int i=1;i<=l;i++)
{
a[i+1]+=a[i]/n;
a[i]%=n;
}
if(a[l+1]>0)l++;
}
int main()
{
zhuanhuan();
if(check())
{
printf("STEP=0\n");
return 0;
}
for(int ans=1;ans<=30;++ans)
{
gaojing();
if(check())
{
printf("STEP=%d\n",ans);
return 0;
}
}
printf("Impossible");
return 0;
}
``````