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 

直接上代码

 1 #include <stdio.h>
 2 
 3 int main()
 4 {
 5     int N;
 6     int sum;
 7     int i;
 8     int start_pos,end_pos;
 9     while(scanf("%d",&N) != EOF){
         sum = ;
         start_pos = ;
         for(i=;i<N;++i){
             scanf("%d",&end_pos);
             if(start_pos < end_pos){
                 sum = sum +  * (end_pos - start_pos);
             }
             else{
                 sum = sum +  * (start_pos - end_pos);
             }
             start_pos = end_pos;
         }
         sum = sum +  * N;
         printf("%d\n",sum);
     }
     return ;
 }

PAT 1008的更多相关文章

  1. PAT 1008数组元素右移问题

    PAT 1008数组元素右移问题 一个数组A中存有N(>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥0)个位置,即将A中的数据由(A​0​​A​1​​⋯A​N−1​​)变 ...

  2. PAT 1008. Elevator (20)

    1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...

  3. PAT 1008 Elevator

    1008 Elevator (20 分)   The highest building in our city has only one elevator. A request list is mad ...

  4. PAT 1008 数组元素循环右移问题 (20)(代码)

    1008 数组元素循环右移问题 (20)(20 分) 一个数组A中存有N(N&gt0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A ...

  5. PAT——1008. 数组元素循环右移问题

    一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0A1……AN-1)变换为(AN-M …… AN-1 A0  ...

  6. pat 1008 Elevator(20 分)

    1008 Elevator(20 分) The highest building in our city has only one elevator. A request list is made u ...

  7. PAT 1008. 数组元素循环右移问题 (20)

    一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0 A1--AN-1)变换为(AN-M -- AN-1 A0 ...

  8. PAT 1008 数组元素循环右移问题

    https://pintia.cn/problem-sets/994805260223102976/problems/994805316250615808 一个数组A中存有N(N&gt0)个整 ...

  9. PAT 1008 Elevator 数学

    The highest building in our city has only one elevator. A request list is made up with N positive nu ...

随机推荐

  1. 自己定制Linux发行版(资料)

    /******************************************************************** * 自己定制Linux发行版(资料) * 声明: * 随着L ...

  2. mysql中php生成唯一ID

    <?php //uniqid官方手册 function create_guid($namespace = '') { static $guid = ''; $uid = uniqid(" ...

  3. Hibernate4.x之映射关系--单向一对多

    在领域模型中,类与类之间最普遍的关系就是关联关系在UML中,关联是有方向的 以Customer和Order为例:一个用户能发出多个订单,而一个订单只能属于一个客户.从Order到Customer的关联 ...

  4. [Everyday Mathematics]20150102

    设 \[ a_1=3,\quad a_{n+1}=\dfrac{1}{2}(a_n^2+1)\quad(n=1,2,\cdots). \] 试求 \[ \vsm{n}\dfrac{1}{1+a_n}. ...

  5. [转载] Zookeeper中的 ACL(Access Control List)访问控制列表

    zk做为分布式架构中的重要中间件,通常会在上面以节点的方式存储一些关键信息,默认情况下,所有应用都可以读写任何节点,在复杂的应用中,这不太安全,ZK通过ACL机制来解决访问权限问题,详见官网文档:ht ...

  6. MySQL 字段类型详解

    一.非数字类型 类型 范围 说明   Char(N) [ binary] N=1~255 个字元 binary :分辨大小写 固定长度 std_name cahr(32) not null VarCh ...

  7. adb 启动失败的原因和修改adb端口号

    在我们使用Android Studio的时候,有时候就会出现adb打开失败或者启动不了的情况. adb 启动失败的原因:有其他程序占用了adb默认启动的端口号(像我就遇到过,每次只要提前启动了酷狗音乐 ...

  8. leetcode@ [263/264] Ugly Numbers & Ugly Number II

    https://leetcode.com/problems/ugly-number/ Write a program to check whether a given number is an ugl ...

  9. Linq to Sql 总生成 where ID is null 的解决办法

    using (Entities com = new Entities()){     com.Configuration.UseDatabaseNullSemantics = true; } EF+M ...

  10. Camtasia Studio的安装步骤

    总的来说: 1.安装 2.安装之后,进行汉化. 破解方法: 1):输入注册码安装 用户名:6-Y 注册码:GCABC-CPCCE-BPMMB-XAJXP-S8F6R 2):软件汉化 安装完成后使用汉化 ...