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. 网站资料收集 主要查看js的学习部分

    1.Asp.Net MVC3.0基本的简单的可能都会用,更深入的使用还需加深研究,之后希望对MVC4.0和5.0进行对比学习,暂时看到@葡萄城控件技术团队博客的MVC5系列正在继续http://www ...

  2. Erlang入门(一)

    读erlang.org上面的Erlang Course四天教程1.数字类型,需要注意两点1)B#Val表示以B进制存储的数字Val,比如 7> 2#101.5 二进制存储的101就是10进制的5 ...

  3. memcached性能监控

    在上文“在Windows .NET平台下使用Memcached”中,我给大家介绍了如何在Windows平台上部署Memecached服务端,如何在.NET平台中应用Memcached,详细介绍了两种流 ...

  4. Innodb buffer pool/redo log_buffer 相关

    InnoDB存储引擎是基于磁盘存储的,并将其中的记录按照页的方式进行管理.在数据库系统中,由于CPU速度和磁盘速度之前的鸿沟,通常使用缓冲池技术来提高数据库的整体性能. 1. Innodb_buffe ...

  5. e8_4输出菲波拉契数列的前10项

    program fbnq;{输出菲波拉契数列的前10项} var a:..] of integer; i:integer; begin a[]:=; a[]:=; do a[i]:=a[i-]+a[i ...

  6. PHP 安全检测代码片段

    /** * html转换输出(只转义' " 保留Html正常运行) * @param $param * @return string */ function htmlEscape($para ...

  7. class0513(html)

    精通DIV+CSS Meta 1.div span 2.三种样式表 内联样式(行内样式) 嵌入样式 外部样式 就近原则 3.常见样式 复合样式background border css单位 % px ...

  8. JavaScript基本概念(二)

    JavaScript 基本概念(二) 操作符和语句 目录 操作符 一元操作符 位操作符 布尔操作符 乘性操作符 其他操作符 语句部分 说起操作符,回忆下上一篇文章末尾说的话. 操作符 一元操作符 ++ ...

  9. JDBC 的基本步骤

    JDBC 的基本步骤: 一.导入mysql-connector-java-x.x.x-bin.jar后: 二.代码 1. 注册驱动(三种方式)2. 创建一个连接对象(三种方式) 3. 创建一个sql语 ...

  10. kvm usb