Elevator
来源:互联网 发布:泪目什么意思网络词 编辑:程序博客网 时间:2024/05/16 09:39
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 1Sample Output:
41
提交代码
#include<stdio.h>int main(){int n,sum=0;scanf("%d",&n);int a[n+1]={0};for(int i=1;i<=n;i++){scanf("%d",&a[i]);if(a[i]-a[i-1]>=0){sum=sum+(a[i]-a[i-1])*6+5;}else{sum=sum+(a[i-1]-a[i])*4+5;}}printf("%d\n",sum);return 0;}
- Elevator
- Elevator
- Elevator
- elevator
- Elevator
- Elevator
- Elevator
- Elevator
- Elevator
- elevator
- Elevator
- Elevator
- Elevator
- Elevator
- Elevator
- Elevator
- Elevator
- Elevator
- 蓝创十周年庆,感恩有您陪伴
- elasticsearch 查询(match和term)
- jzoj3777. 【NOI2015模拟8.17】最短路(shortest)
- Android 中动态设置控件高宽
- MySQL数据库概述和常用管理命令
- Elevator
- 蓝创大庆十周年,三重大礼享不停
- 2017 Multi-University Training Contest
- 数据库设计四范式
- 史上最简单的 MySQL 教程(二十)「数据的高级操作 之 主键冲突」
- UML中关系在代码中的体现
- Java的封装
- 【实战】电脑 开发板 虚拟机三者互ping通教程
- H2:构建单元测试的本地内存数据库