2.1 sort3三值排序
来源:互联网 发布:王石田朴珺 知乎 编辑:程序博客网 时间:2024/05/16 08:32
IOI'96 - Day 2
Sorting is one of the most frequently performed computational tasks.Consider the special sorting problem in which the records to be sortedhave at most three different key values. This happens for instancewhen we sort medalists of a competition according to medal value, thatis, gold medalists come first, followed by silver, and bronze medalistscome last.
In this task the possible key values are the integers 1, 2 and 3.The required sorting order is non-decreasing. However, sorting has tobe accomplished by a sequence of exchange operations. An exchangeoperation, defined by two position numbers p and q, exchanges the elementsin positions p and q.
You are given a sequence of key values. Write a program that computesthe minimal number of exchange operations that are necessary to makethe sequence sorted.
PROGRAM NAME: sort3
INPUT FORMAT
Line 1: N (1 <= N <= 1000), the number ofrecords to be sorted Lines 2-N+1: A single integer from the set {1, 2, 3}SAMPLE INPUT (file sort3.in)
9
2
2
1
3
3
3
2
3
1
OUTPUT FORMAT
A single line containing the number of exchanges required
SAMPLE OUTPUT (file sort3.out)
4
- 2.1 sort3三值排序
- usaco 2.1.3 sort3
- Section 2.1 sort3
- usaco 2.1 sort3 2008.5.20
- USACO-Section2.1 sort3[排序][递归]
- USACO 2.1 Sorting A Three-Valued Sequence (sort3)
- USACO sort3
- USACO sort3
- usaco sort3
- usaco——sort3
- 我的 usaco sort3
- USACO 2.1 三值的排序 (杂项)
- USACO 2.1 三值的排序 (杂项)
- 三值排序
- 三值排序
- 计蒜客---三值排序
- 三值排序
- 三值排序
- Linux启动界面切换:图形界面-字符界面(转)
- 连接数据库发生异常com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primar
- 2.1 frac1
- 跳转指令
- 今天的碰头会议
- 2.1 sort3三值排序
- pctfree和pctused,initrans,maxtrans,next
- MatPlotLib
- MFC编程参考
- 被哥忘却的函数指针
- 关于DIV块背景图设置问题
- ASPnet网页 母版页 用户控件Load事件执行顺序
- 凤凰科技
- 25匹马取前5