zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    【Spark】Spark Streaming 动态更新filter关注的内容
    【Scala】Scala-Option-Null的蹊跷
    java-汉字转化拼音(纯java)
    java-汉字转换拼音-pinyin4j.jar
    mysql-拼接字段concat,concat_ws函数
    sql-将查询字段拼接起来
    sql-insert一条语句执行多条数据插入
    证券挂单时间
    jquery-通过js编写弹出窗口
    html-css控制背景图全屏拉伸不重复显示
  • 原文地址:https://www.cnblogs.com/mr-stn/p/9131399.html
Copyright © 2011-2022 走看看