Problem 2654 --Sort I - Shell Sort

2654: Sort I - Shell Sort

"
Time Limit $6$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $2$ 正确数量 $4$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签 STL

Shell Sort 

Shell Sort is a generalization of Insertion Sort to arrange a list of nn elements A. 

1   insertionSort(A, n, g)

2        for i = g to n-1 

3              v = A[i] 

4              j = i - g 

5             while j >= 0 && A[j] > v 

6                  A[j+g] = A[j] 

7                    j = j - g

8                     cnt++ 

9                 A[j+g] = v 

10 

11  shellSort(A, n) 

12       cnt = 0 

13        m = ? 

14        G[] = {?, ?,..., ?} 

15        for i = 0 to m-1 

16           insertionSort(A, n, G[i])

A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every g-th elements. Beginning with large values of g, it repeats the insertion sort with smaller g. 

Your task is to complete the above program by filling ?. Write a program which reads an integer n and a sequence A, and prints m, Gi(i=0,1,...,m-1) in the pseudo code and the sequence A in ascending order. The output of your program must meet the following requirements:

1≤ m≤ 100

0≤ Gi≤ n 

cnt does not exceed ⌈n^1.5⌉

In the first line, an integer n is given. In the following n lines, Ai(i=0,1,...,n−1) are given for each line.

In the first line, print an integer mm. 

In the second line, print mm integers Gi(i=0,1,...,m−1)separated by single space character in a line.

In the third line, print cnt in a line. In the following nn lines, print Ai(i=0,1,...,n−1)respectively.

This problem has multiple solutions and the judge will be performed by a special validator.

5
5
1
4
3
2
2
4 1
3
1
2
3
4
5

1≤ n≤ 1,000,000

0≤ Ai≤ 10^9

推荐代码 查看2654 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$0 $ms] AOJ大管家 437215 2019-06-08 12:59:36
内存最少[$5872 $KB] Hunter 761160 2021-07-20 17:23:57
第一AC AOJ大管家 338579 2018-12-05 21:34:55
第一挑战 AOJ大管家 338579 2018-12-05 21:34:55

赛题来源/所属竞赛 会津大学《挑战数据结构与算法》 挑战数据结构与算法

竞赛编号 竞赛名称 竞赛时间 访问比赛