RE 50pts求助
查看原帖
RE 50pts求助
986551
13389660737ljx楼主2024/11/12 18:54
#include <bits/stdc++.h>
using namespace std;

int n;
string m;
vector<int> temp;
vector<int> cv(string s)
{
	vector<int> a;
	a.push_back(s.size());
	for(int i=0; i<s.size(); i++)
	{
		if('0'<=s[i] && s[i]<='9') a.push_back((s[i]-'0'));
		else if('A'<=s[i] && s[i]<='F') a.push_back((s[i]-'A')+10);
	}
	return a;
}
bool is_pd(vector<int> a)
{
	for(int i=1; i<=a[0]/2; i++) //a[0]是a的元素个数(除a[0])(正中间的一定和自己相等)
	{
		if(a[i]!=a[a[0]-i+1]) return 0;//逆着读和正着读在第i位不等 
	}
	return 1;
}
void add(vector<int> &a,vector<int> b)
{
	vector<int> ans;
	ans.push_back(0);
	int t=0;
	for(int i=1; i<=max(a[0],b[0]); i++)
	{
		if(i<=a[0]) t+=a[i];
		if(i<=b[0]) t+=b[i];//有可能此时b没有数了 
		ans.push_back(t%n),t/=n;//进位 
	}
	if(t) ans.push_back(t),t/=n;//没加完 
	while(ans.size()>1 && ans[ans.size()-1]==0) ans.pop_back();//前缀0 
	reverse(ans.begin()+1,ans.end());//重新翻过来
	ans[0]=ans.size()-1,a.clear();
	for(int i=0; i<=ans[0]; i++) a[i]=ans[i];
}

int main()
{
	cin>>n>>m;
	vector<int> a=cv(m);
	for(int i=0; i<=30; i++)
	{
		vector<int> at;
		for(int i=0; i<=a[0]; i++) at.push_back(a[i]);
		if(is_pd(at)) 
		{
			cout<<"STEP="<<i;//得到解 
			return 0;
		}
		temp.clear();
		
		for(int i=0; i<=a[0]; i++) temp.push_back(a[i]);//复制
		for(int i=1; i<=temp[0]; i++) a[i]=temp[temp[0]-i+1];//反转 
		add(a,temp);//操作
	}
	cout<<"Impossible!";
	return 0;
}

求助 AC#1#2 RE#3#4 AC \#1\#2 \space RE \#3 \#4

错误数据(#3):

输入:
10
89

答案输出:
STEP=24

我的输出:
STEP=24
--------------------------------
Process exited after 7.03 seconds with return value 3221226356
请按任意键继续. . .

求调,谢谢各位大佬

2024/11/12 18:54
加载中...