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.

Input

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 a1, a2, ..., an (1 ≤ ai ≤ 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 a1, a2, ..., an are
not necessarily different.

Output

Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.

Sample test(s)
input
4
33 44 11 22
output
2
input
7
10 10 58 31 63 40 76
output
10

相当于一个简单的冒泡排序了,只是不用直接排序,仅仅是计算一下而已。

注意

1 最大值和最小值交换的时候能够降低一次交换的。

2 元素是会反复的。

#include <iostream>
using namespace std; namespace{
static const int MAX_VAL = (int) 1E9;
static const int MIN_VAL = (int) 1E-9;
}
void ArrivaloftheGeneral()
{
int n, max_i, min_i, max_n = MIN_VAL, min_n = MAX_VAL, a;
cin>>n;
for (unsigned i = 0; i < n; i++)
{
cin>>a;
if (a <= min_n)
{
min_n = a;
min_i = i;
}
if (a > max_n)
{
max_n = a;
max_i = i;
}
}
cout<<max_i + (n - min_i - 1) - (max_i > min_i);
}

codeforces Arrival of the General 题解的更多相关文章

  1. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  2. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  3. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  4. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  5. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  6. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  7. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  8. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

  9. Codeforces Round #383 (Div. 2) 题解【ABCDE】

    Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...

随机推荐

  1. JS类百度的动态提示框思路及完成

    参考的代码来自这里: http://www.jb51.net/article/28075.htm 不过说实话,这个网站太烂了,不适合看代码,另外写代码的人是个大牛,但是却没有模块化思想,所以朕不高兴直 ...

  2. OLEDB 连接EXCEL的连接字符串IMEX的问题(Oledb)

    今天碰到一个问题需要想EXCEL表中写数据,折腾了好久才发现是IMEX惹得祸,所以记录下提醒自己,也希望大家不要出同样的错. 碰到问题:使用语句 "insert into [Sheet1$] ...

  3. IE下判断IE版本的语句

    <!--[if lte IE 6]> <![endif]--> IE6及其以下版本可见   <!--[if lte IE 7]> <![endif]--> ...

  4. jquery插件:点击拉出的右侧滑动菜单

    就是一个停留在页面右侧的滑动菜单,点击可以拉出,带回调函数.宽高位置可以参数指定.插件代码如下: (jquery的路径请自己修改) (function($){ $.fn.sideSwitch = fu ...

  5. MYSQL Model报错:指定的存储区提供程序在配置中找不到 的解决

    开了项目发现没装mysql及mysql connector/.net.下了个最新版本,结果打开vs,进入模型edmx页面就出了这个问题. 刚开始以为是ProviderManifestToken版本的问 ...

  6. google protocol buffer -2-.proto 定义规则

    essage为主要关键字,类似于java中的class.定义简单message类型 SearchRequest.proto定义了每个查询请求的消息格式,每个请求都会有查询关键词query,查询结果的页 ...

  7. spark 环境变量系列配置

    1. hadoop core-site.xml配置

  8. php页面显示空白

    问题: 本人php初学者,网站下载wamp5,安装好之后,测试环境是否正常,用phpinfo(),但是页面不能正确显示. 1.显示连接错误 2.显示空白页 解决方法: 一.显示连接错误 步骤: 1.p ...

  9. nginx-301重定向开始

    日常工作中使用301重定向的情况很多:如网页目录结构变动,网页重命名.网页的扩展名改变.网站域名改变.SEO优化.等等,301重定向可以很方便的使页面实现跳转. 参考 URL重写模块 一.首先更改配置 ...

  10. 摇滚吧HTML5!有声前端交互!(一)

    生命的伊始,婴儿用明亮的哭声宣告一个新生命的诞生,睁开双眼之前,一双小耳朵已经开始聆听这个世界.在如今的用户体验领域,几乎所有公司都会有视觉设计师,却鲜有注重听觉交互的公司.随着各大厂商对HTML5支 ...