1 条题解

  • 0
    @ 2003-8-26 17:56:56

    【例58.3】 电梯运行时间

    解题思路

    电梯单调上到最高楼H再回0,上下路程共10H秒。每个不同目的楼开门一次,每次5秒;每个乘客下梯1秒。因此总时间10H+5×不同楼层数+n。

    正确性说明

    按顺序完成所述运算后,每个输入元素都被处理在相应位置或统计项中。保存的中间状态与已处理数据对应,最终输出与题目定义一致。

    易错点

    0层结束不额外计开门,题目说有人到达才开门。

    复杂度

    时间O(n log n),空间O(n)。

    参考代码(C++11)

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int n;
        cin >> n;
        set<long long> floor;
        long long H = 0;
        for (int i = 0; i < n; i++) {
            long long x;
            cin >> x;
            floor.insert(x);
            H = max(H, x);
        }
        cout << 10 * H + 5 * floor.size() + n << "\n";
        return 0;
    }
    
    • 1

    信息

    ID
    384
    时间
    1000ms
    内存
    64MiB
    难度
    普及−
    标签
    递交数
    0
    已通过
    0
    上传者