zoukankan      html  css  js  c++  java
  • PAT Advanced 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
    
     考了英语。看清题目没有难度
    #include <iostream>
    
    using namespace std;
    
    int main(){
        int N;cin>>N;
        int bef=-1,now,sum=0;
        while(N--){
            cin>>now;
            if(bef==-1) sum+=(now*6+5);
            else if(now>bef) sum+=((now-bef)*6+5);
            else sum+=((bef-now)*4+5);
            bef=now;
        }
        cout<<sum;
        return 0;
    }
  • 相关阅读:
    ? ?? 类?
    类 建索引
    访问局域网计算机文件
    JS 在元素后面添加新的元素
    js 网页加载完毕,执行js函数
    设置快捷键(3种方式)
    winform设置textbox设置水印
    ADO.NET 学生管理
    C#整理 条件语句
    ADO.NET 数据访问类查询、属性扩展
  • 原文地址:https://www.cnblogs.com/littlepage/p/11806371.html
Copyright © 2011-2022 走看看