• PAT 1008 Elevator (20)


    The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.

    For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.

    Input Specification:

    Each input file contains one test case. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100.

    Output Specification:

    For each test case, print the total time on a single line.

    Sample Input:

    3 2 3 1
    

    Sample Output:

    41

    题目大意:一栋大楼里面只有一部电梯,初始在0楼,上升一楼要6秒,下降一楼要4秒, 每一楼要停留5秒,现在给出一串电梯停靠的楼层,计算按照顺序停靠完,需要多少时间
    输入:第一个数字是需要停靠的次数,后面跟着停靠的楼层
    last:上一次停靠的楼层
    now:这一次停靠的楼层
    ans: 记录所需时间
     1 #include<iostream>
     2 using namespace std;
     3 int main(){
     4   int n, last = 0, now, ans = 0;
     5   cin>>n;
     6   for(int i=0; i<n; i++){
     7     cin>>now;
     8     if(now>last) ans += (now-last)*6;
     9     else ans += (last-now)*4;
    10     ans += 5;
    11     last = now;
    12   }
    13   cout<<ans;
    14 }
    有疑惑或者更好的解决方法的朋友,可以联系我,大家一起探讨。qq:1546431565
  • 相关阅读:
    odoo10学习笔记十二:web controller
    odoo10学习笔记十一:视图综述
    odoo10学习笔记十:Actions
    odoo10学习笔记九:Odoo10 API
    odoo10学习笔记八:qweb引擎
    knockoutjs data-bind 声明式绑定整理
    使用mpvue开发小程序教程(六)
    使用mpvue开发小程序教程(五)
    使用mpvue开发小程序教程(四)
    使用mpvue开发小程序教程(三)
  • 原文地址:https://www.cnblogs.com/mr-stn/p/9131399.html
Copyright © 2020-2023  润新知