Problem 2652 --Sort I - Selection Sort

2652: Sort I - Selection Sort

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

Selection Sort

Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:

SelectionSort(A) 

1 for i = 0 to A.length-1 

2     mini = i 

3    for j = i to A.length-1 

4           if A[j] < A[mini] 

5               mini = j 

6     swap A[i] and A[mini] 

Note that, indices for array elements are based on 0-origin.

Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.

The first line of the input includes an integer N, the number of elements in the sequence. 

In the second line, N elements of the sequence are given separated by space characters.

The output consists of 2 lines. 

In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character.

 In the second line, please print the number of swap operations.

6
5 6 4 2 1 3
1 2 3 4 5 6
4
1 ≤  N ≤  100

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

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$0 $ms] 834927 2022-04-07 09:38:58
内存最少[$1152 $KB] Kaiser 717821 2021-03-15 18:01:34
第一AC 卑微小赵 286182 2018-10-13 09:25:25
第一挑战 卑微小赵 286182 2018-10-13 09:25:25

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

竞赛编号 竞赛名称 竞赛时间 访问比赛
1786 2023-2024-1学期《程序设计技能实训》排序和线性表【23计算机】 2023-12-18 00:00:00 请登录
1682 2021-2022-2学期<算法分析与设计> 第3周练习:递归和基础排序 2022-03-07 08:00:00 请登录
1608 2020-2021-2学期<算法分析与设计>第4周练习:排序算法 2021-03-15 08:00:00 请登录
1571 2020-2021-1学期《程序设计技能实训》基础排序【20计算机12345】 2020-12-22 09:00:00 请登录
1285 2018-2019-2学期18计算机123班《C语言程序设计II》数组排序(选择、冒泡、插入排序实现) 2019-03-01 16:20:00 请登录