HDU 1008 Elevator

题目链接:HDU 1008 Elevator

题目大意:
一个电梯往上一层要\(6\)秒,往下一层要\(4\)秒,每层停留\(5\)秒,电梯开始在\(0\)层,给你电梯总共运行次数\(n\),后面的\(n\)个数为这\(n\)次分别到的层数,求运行时间。

题解:
按顺序模拟。

#include <iostream>
using namespace std;
#define io_speed_up ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

int n, ans, nxt, now;

int main() {
    io_speed_up;
    while (cin >> n && n) {
        ans = now = 0;
        for (int i = 1; i <= n; ++i) {
            cin >> nxt;
            if (nxt > now) {
                ans += 6 * (nxt - now) + 5;
            } else {
                ans += 4 * (now - nxt) + 5;
            }
            now = nxt;
        }
        cout << ans << endl;
    }
    return 0;
}
posted @ 2020-10-18 02:03  ZZHHOOUU  阅读(82)  评论(0编辑  收藏  举报