[HDU1008] Elevator

Notice

This is an old article and only available in Chinese. If you need a translation, please leave a comment and I will do my best to provide it as soon as possible.

题目很简单,一次就能 A,把代码拉过来测试一下发表文章~

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

int main() {
    int n;
    while (std::cin >> n) {
        if (!n)
            return 0;
        int currFloor = 0;
        int sum = 0, aim;
        while (n--) {
            std::cin >> aim;
            sum += ((currFloor > aim) ? (4) : (-6)) * (currFloor - aim) + 5;
            currFloor = aim;
        }
        std::cout << sum << std::endl;
    }

    return 0;
}
comments powered by Disqus
Except where otherwise noted, content on this blog is licensed under CC-BY 2.0.
Built with Hugo
Theme Stack designed by Jimmy