QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#407520#8297. Defining LabelssmlAC ✓70ms3696kbC++20903b2024-05-08 21:38:232024-05-08 21:38:24

Judging History

你现在查看的是最新测评结果

  • [2024-05-08 21:38:24]
  • 评测
  • 测评结果:AC
  • 用时:70ms
  • 内存:3696kb
  • [2024-05-08 21:38:23]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int ks(int a,int b)
{
	int res=1;
	while(b){
		if(b&1) res=res*a;
		b>>=1;
		a*=a;
	} 
	return res;
}
void solve()
{
     int k,x;
     cin>>k>>x;
     if(x==1){
     	cout<<10-k<<'\n';
     	return;
	 }
     //k属于2-10:
	 string ans;
	 //int u=0;
	 map<int,char>dk;
	 int st=0;
	 for(int i=10-k;i<=9;i++) dk[st++]=(i+'0');
	 int u=1;
	 int sum=0;
	 while(sum<x){
	 //	sum+=ks(k,u);
	 	if(sum+ks(k,u)>=x) break;
	 	sum+=ks(k,u);
	 	u++;
	 }
//	 cout<<u<<'\n';
//	 cout<<sum<<'\n';
	 x-=sum;
	 //if(u>1) x-=sum;
	 x--;
	 while(x){
	 	ans+=dk[x%k];
	 	x/=k;
	 }
	 while(ans.size()<u) ans+=dk[0];
	 reverse(ans.begin(),ans.end());
	 cout<<ans<<'\n'; 
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int t=1;
	cin>>t;
	while(t--) solve();
	return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3532kb

input:

2
10
10
5
10

output:

9
59

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 70ms
memory: 3696kb

input:

100000
8
385305681
7
109699235
4
261908086
7
502646222
4
12580383
5
126745533
3
288419055
2
85504901
6
321113975
2
282134041
10
993024241
2
586597753
9
19217233
5
87237368
7
379291900
2
393340455
2
237168121
5
128698999
10
937803725
3
34331441
6
144544189
7
221381693
9
69838388
8
504174151
4
1156320...

output:

3786757232
4693488784
88767967676867
37534486833
788888669688
668865768557
797898789978778979
89888998889899889998888998
84799659768
8888998988898888899888899898
881913130
88898999989989988898989999898
39138971
578756987877
34475855393
8999899988899998899888989888
998889888989998898999999898
6698657...

result:

ok 100000 lines

Extra Test:

score: 0
Extra Test Passed