CF144A.Arrival of the General
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all n squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important.
For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong.
Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct.
国防部派了一名将军来视察上校SuperDuper指挥的超级机密军事小队。得知这一消息后,上校命令所有 n 名士兵在阅兵场上列队。
根据军规,士兵应按身高非递增顺序站立。但由于时间极为紧迫,士兵们随意排成了一个队列。然而,这位将军视力不佳,他认为:只要队列中第一名士兵的身高为最高,且最后一名士兵的身高为最低,那么该队列就是正确的。请注意,其余士兵的站位方式无关紧要——包括存在多个最高或最低身高的士兵的情形。唯一重要的是第一名与最后一名士兵的身高。
例如,将军认为身高序列 (4,3,4,2,1,1) 是正确的,而序列 (4,3,1,2,2) 是错误的。
上校每秒钟可以交换任意两名相邻士兵的位置。请帮助他计算出使队列满足将军要求所需的最短时间(秒数)。
输入格式
The first input line contains the only integer n (2 ≤ n ≤ 100) which represents the number of soldiers in the line. The second line contains integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers _a_1, _a_2, ..., a__n are not necessarily different.
第一行输入包含唯一一个整数 n(2≤n≤100),表示队列中士兵的数量。
第二行包含 n 个整数 a1, a2, …, an(1≤ai≤100),表示士兵的身高值,按队列从前到后的顺序给出。各数字以空格分隔。
数字 a1, a2, …, an 不一定互不相同。
输出格式
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
输出唯一的整数——上校形成将军所喜欢的队列所需的最少秒数。
输入输出样例
输入#1
4 33 44 11 22
输出#1
2
输入#2
7 10 10 58 31 63 40 76
输出#2
10
说明/提示
In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
- (10, 10, 58, 31, 63, 40, 76)
- (10, 58, 10, 31, 63, 40, 76)
- (10, 58, 10, 31, 63, 76, 40)
- (10, 58, 10, 31, 76, 63, 40)
- (10, 58, 31, 10, 76, 63, 40)
- (10, 58, 31, 76, 10, 63, 40)
- (10, 58, 31, 76, 63, 10, 40)
- (10, 58, 76, 31, 63, 10, 40)
- (10, 76, 58, 31, 63, 10, 40)
- (76, 10, 58, 31, 63, 10, 40)
- (76, 10, 58, 31, 63, 40, 10)
在第一个样例中,上校需要交换第一位和第二位士兵,然后交换第三位和第四位士兵,总共耗时 2 秒。士兵最终的排列为 (44,33,22,11)。
在第二个样例中,上校可以按如下序列交换士兵:
- (10,10,58,31,63,40,76)
- (10,58,10,31,63,40,76)
- (10,58,10,31,63,76,40)
- (10,58,10,31,76,63,40)
- (10,58,31,10,76,63,40)
- (10,58,31,76,10,63,40)
- (10,58,31,76,63,10,40)
- (10,58,76,31,63,10,40)
- (10,76,58,31,63,10,40)
- (76,10,58,31,63,10,40)
- (76,10,58,31,63,40,10)
输入解题思路,AI测评打分。不知道怎么写?