1008. Elevator (20)

简介: 简析:10分钟内ac,没有难度。#include using namespace std;int main(int argc, const char * argv[]) { int n, f0 = 0, f...

简析:10分钟内ac,没有难度。

#include <iostream>
using namespace std;

int main(int argc, const char * argv[]) {
    int n, f0 = 0, f1, sum = 0;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    
    for (int i = 0; i < n; i++) {
        f1 = a[i];
        if (f1 - f0 > 0) {
            sum += (f1 - f0) * 6;
        }else{
            sum += (f1 - f0) * -4;
        }
        f0 = f1;
    }
    
    sum += n * 5;
    
    cout << sum << endl;
    
    return 0;
}

目录
相关文章
|
29天前
|
编解码 安全 Linux
Clock sources, Clock events, sched_clock() and delay timers【ChatGPT】
Clock sources, Clock events, sched_clock() and delay timers【ChatGPT】
HDOJ 1008 Elevator
HDOJ 1008 Elevator
87 0
HDOJ 1004题 Let the Balloon Rise strcmp()函数
HDOJ 1004题 Let the Balloon Rise strcmp()函数
101 0
HDOJ 1004 Let the Balloon Rise
HDOJ 1004 Let the Balloon Rise
136 0
|
算法 C# 索引
算法题丨Move Zeroes
描述 Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.
1163 0
1142. Maximal Clique (25) 19‘
#include #include #include #include #include using namespace std; int e[201][201]; vector temp; bool judge(){ int flag = 1; for(int i = 0; i < temp.
974 0