您的位置:首页 > 其它

144A - Arrival of the General

2015-05-22 11:57 232 查看
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int a[110];

int main() {

    int n;
    int ans = 0;
    int maxh = 0, minh = 1000000;
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        if(maxh < a[i]) {
            maxh = a[i];
        }
        if(minh > a[i]) {
            minh = a[i];
        }
    }
    int id1 = -1, id2 = -1;
    for(int i = 1, j = n; i <= n; ++i, --j) {
        if(a[i] == maxh && id1 == -1) {
            id1 = i;
        }
        if(a[j] == minh && id2 == -1) {
            id2 = j;
        }
    }
    if(id1 < id2) {
        ans = id1 - 1 + n - id2;
    } else {
        ans = id1 - 1 + n - id2 - 1;
    }
    cout << ans << endl;
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: