QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#91000#6138. Function and FunctionyyyyxhAC ✓13ms1704kbC++17898b2023-03-26 16:32:442023-03-26 16:32:47

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-26 16:32:47]
  • 评测
  • 测评结果:AC
  • 用时:13ms
  • 内存:1704kb
  • [2023-03-26 16:32:44]
  • 提交

answer

#include <cstdio>
#include <cstring>
using namespace std;
int read(){
	char c=getchar();int x=0;
	while(c<48||c>57) c=getchar();
	do x=(x<<1)+(x<<3)+(c^48),c=getchar();
	while(c>=48&&c<=57);
	return x;
}
const int val[10]={1,0,0,0,1,0,1,0,2,1};
int f(int x){
	int res=0;
	do res+=val[x%10],x/=10;while(x);
	return res;
}
int pos[1003];
int arr[1003];
int main(){
	int tc=read();
	memset(pos,-1,sizeof pos);
	while(tc--){
		int x=read(),k=read();
		if(!k){printf("%d\n",x);continue;}
		--k;x=f(x);
		if(!k){printf("%d\n",x);continue;}
		arr[pos[x]=0]=x;
		bool fl=1;
		for(int i=1;i<=k;++i){
			x=f(x);
			if(~pos[x]){
				printf("%d\n",arr[pos[x]+(k-i)%(i-pos[x])]);
				for(int j=0;j<i;++j) pos[arr[j]]=-1;
				fl=0;
				break;
			}
			arr[pos[x]=i]=x;
		}
		if(fl){
			for(int i=0;i<=k;++i) pos[arr[i]]=-1;
			printf("%d\n",arr[k]);
		}
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 1500kb

input:

6
123456789 1
888888888 1
888888888 2
888888888 999999999
98640 12345
1000000000 0

output:

5
18
2
0
0
1000000000

result:

ok 6 numbers

Test #2:

score: 0
Accepted
time: 13ms
memory: 1704kb

input:

100000
579268184 2
120252252 777743676
255650198 1
152055433 207664522
137430584 754115403
646417467 164848484
743551976 0
0 408695577
363072674 569574204
464290891 0
761830281 3
0 1
49176280 2
791182580 0
474930784 3
402374924 0
739903247 91553857
0 2
688106229 2
65907033 152261569
875191599 3
5319...

output:

0
0
5
0
1
1
743551976
1
1
464290891
0
1
1
791182580
1
402374924
0
0
2
0
1
1
2
1
0
0
0
3
0
0
0
1
0
0
1
0
2
0
1
1
1
0
1
0
0
0
0
0
0
1
55349255
486354015
1
1
0
1
1
0
1
1
0
1
0
9
0
1
1
0
0
1
0
1
1
1
0
0
0
0
25600152
0
0
1
22903397
705086250
771453912
1
1
0
0
1
0
1
1
1
2
1
1
1
1
1
1
6
3
3
1
0
1
0
1
86248...

result:

ok 100000 numbers