codeforce小水题——
来源:互联网 发布:繁忙的收发室 优化 编辑:程序博客网 时间:2024/06/05 18:04
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.
将军近视眼:输入一组数据,只要排头最高,排尾最矮,这个队伍就ok~本题要统计交换的次数。
#include<iostream>using namespace std;int main(){ int b,max=0,min=101,t1,t2,m,count=0,i; cin>>b; int a[b]; for(i=0;i<b;i++) { cin>>a[i]; if(max<a[i]) { max=a[i]; t1=i; }//同样高的,位子尽量靠前站,即i越小越好。 if(min>=a[i]) { min=a[i]; t2=i; }//同样矮的,位子尽量靠后站,即i越大越好。 } count=t1+b-1-t2;//交换的总次数。 if(t2<t1) count--;//如果一开始,最矮的人站在最高的人前面,交换的总次数就减少一次。 cout<<count<<endl;}
- codeforce小水题——
- Indivisibility——Codeforce
- codeforce 246B——Good Sequences
- CodeForce 180 C ——Letter
- codeforce 185 A——Plant
- Codeforce 189B——Counting Rhombi
- codeforce小水题--A. Presents
- codeforce
- codeforce
- Codeforce
- Codeforce
- Codeforce
- Codeforce
- Codeforce
- Codeforce
- Codeforce
- Codeforce
- Codeforce
- 抓取屏幕保存为AVI文件
- 蛙泳姿势教学
- Logistic Regression--逻辑回归算法汇总
- CAS 之 实现用户注册后自动登录
- iOS 气泡聊天效果
- codeforce小水题——
- android 自定义lib
- 黑马程序员java枚举
- win7 mysql 安装 报The security settings could not be applied to the database
- MySql存储过程—7、游标(Cursor)
- CDH4 impala安装配置
- SELECT语句执行顺序解析
- Struts2教程5:使用Validation框架验证数据
- Remove Comodo Cleaning Essentials with WindowsUninstaller.Org Removal Tips