LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 451|回复: 1

问一道题

[复制链接]
发表于 2003-11-17 23:05:31 | 显示全部楼层 |阅读模式
Sorting a Three-Valued Sequence
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 sorted have at most three different key values. This happens for instance when we sort medalists of a competition according to medal value, that is, gold medalists come first, followed by silver, and bronze medalists come 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 to be accomplished by a sequence of exchange operations. An exchange operation, defined by two position numbers p and q, exchanges the elements in positions p and q.

You are given a sequence of key values. Write a program that computes the minimal number of exchange operations that are necessary to make the sequence sorted.
PROGRAM NAME: sort3
INPUT FORMAT
Line 1:         N (1 <= N <= 1000), the number of records to be sorted
Lines 2-N+1:         A single integer from the set {1, 2, 3}
SAMPLE INPUT (file sort3.in)


  1. 9
  2. 2
  3. 2
  4. 1
  5. 3
  6. 3
  7. 3
  8. 2
  9. 3
  10. 1
复制代码


OUTPUT FORMAT
A single line containing the number of exchanges required
SAMPLE OUTPUT (file sort3.out)


  1. 4
复制代码
发表于 2003-11-18 19:40:42 | 显示全部楼层
看不懂
可以把你的要求说明一下吗
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表