QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21029. 位置不对

Statistics

Farmer John 雄心勃勃,打算尝试一件似乎总是不太顺利的事情:给整个奶牛群拍照。

为了让照片好看,他希望奶牛从矮到高排成一行。不幸的是,就在奶牛排好后,总爱捣乱的 Bessie 走出队列,又插到了队列中的另一个位置!

Farmer John 想通过交换成对的奶牛,让整个牛群重新排好。请帮助他确定达到这一目标所需的最少交换次数。

输入格式

输入第一行包含 $N$($2 \leq N \leq 100$)。接下来的 $N$ 行描述 Bessie 移动之后队列中奶牛的身高。每头奶牛的身高都是 $1 \ldots 1,000,000$ 范围内的整数。奶牛的身高可以相同。

输出格式

请输出 Farmer John 为使队列有序所需的最少成对交换次数。交换的奶牛不必在队列中相邻。

样例

输入格式 1

6
2
4
7
7
9
3

输出格式 1

3

说明

这个例子中,Bessie 显然是身高为 3 的奶牛。FJ 可以用下面的三次交换恢复有序队列:

2 4 7 7 9 3 - 原始队列
2 4 7 7 3 9 - 交换最后两头奶牛
2 4 3 7 7 9 - 交换第一个 7 和 3
2 3 4 7 7 9 - 交换 4 和 3

题目作者:Brian Dean

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.