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 }
  • 相关阅读:
    vs快捷键
    深入理解react和redux
    eclispe下maven项目报错解决方式
    ios fixed浮层 光标下移解决方案
    jQuery的extend()用法
    连续数字数值转换成逗号分隔
    css 清除浮动
    恶补JavaScript第二篇
    恶补JavaScript第一篇
    中文英文左右padding一致两端对齐实现(转载)
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4787469.html
Copyright © 2011-2022 走看看