144A - Arrival of the General

#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;
}

操作系统代码实现:Number Project Name Content Summary State Type 一、Process Scheduling Algorithm Simulation 1、 Simulate the operation of the round-robin algorithm for process scheduling. 2、 Create at least 15 processes and output their scheduling situation under the scheduling algorithm mentioned above and output it to theterminal to check the execution of the algorithm. 3、 The output should include the arrival time of the processes, the end time, and the average execution time. Essential. General 二、Readers-Writer Problem Implmentation 1、 A data set is shared among several concurrent processes: Readers – only read the data set; they do not perform any updates. Writers – can both read and write. 2、 Problem – allow multiple readers (at most 8) to read at the same time. Only one single writer can access the shared data at the same time. Essential. General 三、Program for Least Recently used Algorithm 1、 Create a page access sequence (page number range 0-18) using a random function. The sequence length is 54 and assume that the number of main memory frames allocated to the thread is 6, that is, M = 6. 2、 Implement the LRU algorithm for page replacement on the above access sequence. 3、 Output the page replacement sequence and the page fault rate. Essential. General Requirements 1、 For each experiment project, submit a design report and code. The code should be implemented in C++. The requirements are as follows: a) The content of the design report should include the design ideas and implementation. b) The results of the design report should include testing and running results (screenshots of screen outputs). c) The conclusion of the design report should summarize the problems encountered, the solutions and experiences during the implementation process.
06-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值