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 }
  • 相关阅读:
    PHP 使用memcached
    linux下使用yum安装 mencached
    mysql 连接字符串 CONCAT
    linux 下 apache启动、停止、重启命令
    js中push()的用法
    linux下使用yum安装mysql
    SVN服务器多个项目的权限分组管理
    yum 安装nginx
    Linux下php安装Redis安装
    使用BarcodeLib.Barcode.ASP.NET生成条形码
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4787469.html
Copyright © 2011-2022 走看看