Logo Wy Online Judge

WyOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#537#116. 【0621 模拟赛】OBILAZAKryp1000ms1720kbC++14608b2025-06-20 10:08:182025-06-21 23:21:10

answer


#include<cstdio>
int n,b=1,a[1025],c,s=2;//s为该完全二叉树当前深度需要输出的节点
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) b*=2;
	b--;//b为要输出的总节点数
	for(int i=1;i<=b;i++) scanf("%d",&a[i]);
	b=(b+1)/2;
	printf("%d\n",a[b]);//输出第一行,为该遍历中间的数
	c=b/2;
	while(--n)//继续输出n-1行
	{
		printf("%d ",a[c]);//先输出第一份中间的数
		for(int i=1;i<s;i++) printf("%d ",a[b*i+c]);//再输出第2到s份中间的数
		printf("\n");
		b=c;
		c/=2;//模拟分割
		s*=2;//深度加1,节点乘2
	}
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

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

input:

10
441 314 935 337 172 628 445 670 715 953 761 525 432 951 217 785 577 933 855 275 178 664 198 298 4...

output:

404
602 213 
147 737 965 842 
42 730 351 430 494 493 490 141 
248 974 681 618 505 196 207 805 255 60...

result:

ok 1023 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 1644kb

input:

4
10 9 3 11 8 14 15 12 7 13 2 1 4 6 5

output:

12
11 1 
9 14 13 6 
10 3 8 15 7 2 4 5 

result:

ok 15 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 1588kb

input:

5
15 23 28 30 4 9 27 19 24 3 29 7 22 17 20 26 8 6 13 1 14 5 11 25 2 31 18 16 10 12 21

output:

26
19 25 
30 7 1 16 
23 9 3 17 6 5 31 12 
15 28 4 27 24 29 22 20 8 13 14 11 2 18 10 21 

result:

ok 31 tokens

Test #4:

score: 0
Accepted
time: 0ms
memory: 1700kb

input:

6
54 6 31 5 26 60 25 46 49 43 33 51 21 28 22 36 7 9 35 39 58 37 59 32 3 48 42 15 18 23 10 12 17 30 5...

output:

12
36 50 
46 32 8 56 
5 51 39 15 45 16 63 20 
6 60 43 28 9 37 48 23 30 13 61 55 47 38 4 1 
54 31 26 ...

result:

ok 63 tokens

Test #5:

score: 0
Accepted
time: 0ms
memory: 1720kb

input:

7
116 56 50 18 15 46 36 96 32 77 85 25 76 74 47 10 121 51 86 4 101 79 63 115 75 62 114 28 122 100 17...

output:

35
45 5 
10 9 30 11 
96 115 21 88 26 83 117 78 
18 25 4 28 105 107 87 123 57 73 81 53 16 48 102 52 
...

result:

ok 127 tokens

Test #6:

score: 0
Accepted
time: 0ms
memory: 1596kb

input:

8
18 138 3 122 199 40 92 144 165 219 196 237 223 60 1 124 65 145 128 107 108 155 62 187 150 29 53 25...

output:

162
13 42 
216 112 8 130 
124 97 157 12 250 208 185 102 
144 187 230 49 82 136 69 197 141 75 195 189...

result:

ok 255 tokens

Test #7:

score: 0
Accepted
time: 0ms
memory: 1644kb

input:

9
32 353 216 63 482 469 367 60 275 244 109 87 158 505 510 419 71 41 504 128 284 445 264 381 461 59 2...

output:

453
312 362 
12 10 509 161 
263 288 301 142 365 145 104 192 
419 283 502 97 471 234 316 295 27 25 25...

result:

ok 511 tokens

Test #8:

score: 0
Accepted
time: 0ms
memory: 1708kb

input:

10
373 367 555 336 718 176 655 152 816 779 736 527 107 357 333 936 714 188 185 543 855 759 350 364 6...

output:

568
1010 1012 
290 132 772 893 
564 894 667 265 264 761 671 15 
190 134 582 282 337 602 181 477 514 ...

result:

ok 1023 tokens

Test #9:

score: 0
Accepted
time: 0ms
memory: 1720kb

input:

10
400 58 680 758 18 699 340 5 192 936 916 362 142 236 383 801 12 753 622 205 428 486 499 341 979 95...

output:

559
883 116 
51 320 195 732 
277 687 866 653 128 174 652 317 
76 466 85 171 855 455 542 696 415 523 ...

result:

ok 1023 tokens