60分TLE求助
查看原帖
60分TLE求助
201971
william_zy楼主2021/8/7 15:02
#include<bits/stdc++.h>
#undef pow
using namespace std;
int n,base,ans[10000000],Pow[1000];
void IN()
{
    int t=1;
    for(int i=0;i<1000;i++)
    {
        Pow[i]=t;
        t*=base;
    }
}
bool cmp()
{
    int cnt=0;
    for(int i=0;ans[i]!=0;i++)
    {
        cnt+=ans[i]*Pow[i];
    }
    return cnt==n;
}
void ADD()
{
    ans[0]++;
    int i=0;
    while(ans[i]>=abs(base)){
        ans[i]-=abs(base);
        ans[i+1]++;
        i++;
    }
}
char tmp[1001]="0123456789ABCDEFGHIJKLMNOPQRST";
int main()
{
	cin>>n>>base;
	if(base<=-16)base=-16;
	IN();
	while(!cmp()){
	    ADD();
	}
	int i=0;
	while(ans[i]!=0)i++;
	i--;
	cout<<n<<"=";
	for(;i>=0;i--)cout<<tmp[ans[i]];
	cout<<"(base"<<base<<')';
}

出了什么问题 求助 记录

2021/8/7 15:02
加载中...