zoukankan      html  css  js  c++  java
  • pat1008. Elevator (20)

    1008. Elevator (20)

    时间限制
    400 ms
    内存限制
    65536 kB
    代码长度限制
    16000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    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
    

    提交代码

     1 #include<cstdio>
     2 #include<stack>
     3 #include<cstring>
     4 #include<iostream>
     5 using namespace std;
     6 int main(){
     7     int n,b=0,cur,t=0;
     8     scanf("%d",&n);
     9     while(n--){
    10         scanf("%d",&cur);
    11         if(cur>b){
    12             t+=(cur-b)*6+5;
    13         }
    14         else{
    15             t+=(b-cur)*4+5;
    16         }
    17         b=cur;
    18     }
    19     printf("%d
    ",t);
    20     return 0;
    21 }
  • 相关阅读:
    MySQ随笔2(连接表、分组)
    MySQL随笔
    Python随笔1
    要学习但还没学的知识点2016年8月4号
    jQuery备忘录--私家版
    Chrome 中的彩蛋——T-Rex
    JavaScript多线程初步学习
    实例:jQuery实现标签切换
    实例:用jQuery实现垂直和水平下拉 菜单
    AJAX编程模板
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4787469.html
Copyright © 2011-2022 走看看