codeforces 144A Arrival of the General
来源:互联网 发布:网络借贷平台哪个方便 编辑:程序博客网 时间:2024/05/26 22:58
网址:点击打开链接
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:
题意:(假如有很多个最大值和最小值)把第一个最大值移到第一个位置,把最后一个最小值移到最后一个位置的步骤和,只能两两交换。
#include<stdio.h>int main(){ int n,s[110],least=0,largest=0; scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%d",&s[i]); } for(int i=1; i<n; i++) { if(s[least]>=s[i]) least=i; if(s[largest]<s[i]) largest=i; } if(least<largest) { printf("%d\n",largest+n-1-least-1); } else if(least==largest) { printf("0\n"); } else//least>largest { printf("%d\n",largest+n-1-least); } //printf("%d %d %d %d\n",s[least],s[largest],least,largest); return 0;}
- CodeForces 144A Arrival of the General
- codeforces 144A Arrival of the General
- codeforces 144A Arrival of the General
- 144A - Arrival of the General
- Codeforces Arrival of the General
- A. Arrival of the General
- codeforces Arrival of the General 题解
- Arrival of the General
- CodeForces144A Arrival of the General
- NOJ [1039] Arrival of the General
- CodeForces 144AArrival of the General
- the general framework of RL_DQN
- CodeForces-124A-The number of positions
- CodeForces-124A-The number of positions
- codeforces 124A The number of positions
- A list of books on general-purpose algorithms for the practical programmer (or 'software engineer')
- General Overview of The System(一)
- The art in general operation of linux
- 在html页面上实现下载功能
- “玲珑杯”线上赛 Round #15 河南专场:A -- Reverse the lights
- 如何从COCOS_CODE_IDE过渡到用AndroidStudio开发cocos的?
- Java_java命令行编译运行
- [Echarts可视化] 二.php和ajax连接数据库实现动态数据可视化
- codeforces 144A Arrival of the General
- Vim 快速上手
- Ubuntu下sublime安装完package control后Preference下没有出现的问题
- 安卓事件传递机制
- 倒计时
- hdoj1052 Tian Ji -- The Horse Racing(贪心算法+2)
- 为兼容IE8 使用layer弹框简记
- Ajax的基础知识
- 控制随机数生成概率的一种解决方法