CodeForces 144AArrival of the General
来源:互联网 发布:javascript identifier 编辑:程序博客网 时间:2024/05/16 23:27
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.
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.
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
433 44 11 22
2
710 10 58 31 63 40 76
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)
#include<map>#include<set>#include<ctime>#include<cmath>#include<queue>#include<bitset>#include<string>#include<vector>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<functional>using namespace std;#define ms(x,y) memset(x,y,sizeof(x))#define rep(i,j,k) for(int i=j;i<=k;i++)#define per(i,j,k) for(int i=j;i>=k;i--)#define loop(i,j,k) for (int i=j;i!=-1;i=k[i])#define inone(x) scanf("%d",&x)#define intwo(x,y) scanf("%d%d",&x,&y)#define inthr(x,y,z) scanf("%d%d%d",&x,&y,&z)#define infou(x,y,z,p) scanf("%d%d%d%d",&x,&y,&z,&p)#define lson x<<1,l,mid#define rson x<<1|1,mid+1,r#define mp(i,j) make_pair(i,j)#define ft first#define sd secondtypedef long long LL;typedef pair<LL, LL> pii;const int low(int x) { return x&-x; }const int INF = 0x7FFFFFFF;const int N = 1e5 + 10;const double eps = 1e-10;int n, a[N], mi, mx;int main(){inone(n);mi = n; mx = 1;rep(i, 1, n) inone(a[i]);rep(i, 1, n) if (a[mx] < a[i]) mx = i;per(i, n, 1) if (a[mi] > a[i]) mi = i;if (mi < mx) printf("%d\n", mx - 1 + n - mi - 1);else printf("%d\n", mx - 1 + n - mi);return 0;}
- CodeForces 144AArrival of the General
- CodeForces 144A Arrival of the General
- codeforces 144A Arrival of the General
- codeforces 144A Arrival of the General
- Codeforces Arrival of the General
- codeforces Arrival of the General 题解
- 144A - Arrival of the General
- Arrival of the General
- A. Arrival of the General
- CodeForces144A Arrival of the General
- the general framework of RL_DQN
- General Overview of The System(一)
- The art in general operation of linux
- The art in general operation of Windows
- NOJ [1039] Arrival of the General
- General overview of the Linux file system
- Scripts to Check the Setup of the General Ledger Calendar
- the thinker of code complete -- general issues in using variables
- docker初级操作——by蠢鱼
- 高并发的基本解决方案
- acm书中题目 u-21
- Java常见4种排序
- Java反射机制详解
- CodeForces 144AArrival of the General
- 有支付宝的赶紧过来看看,支付宝新政策!
- react Warning: Each child in an array or iterator should have a unique "key" prop. Check the render
- Linux 命令大全
- 点击程序的输入框卡死问题的解决
- KINECT同时提取六人骨骼数据
- 门罗币基础技术介绍
- Python学习笔记-input和raw_input
- Name node is in safe mode