# 1008. Elevator (20)

61人阅读 评论(0)

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

----------------------华丽的分割线--------------------------

#include<cstdio>
#include<cstdlib>

#define Maxn 101

int input[Maxn];

int main(void)
{
int N,i;
int sum = 0;
scanf("%d",&N);
sum += 5 * N;
for(i=1;i<=N;++i)
{
scanf("%d",&input[i]);
if(input[i] > input[i-1])
sum += 6 * (input[i] - input[i-1]);
else if(input[i] < input[i-1])
sum += 4 * (input[i-1] - input[i]);
}
printf("%d",sum);
system("pause");
return 0;
}

0
0

【直播】计算机视觉原理及实战—屈教授
【套餐】深度学习入门视频课程—唐宇迪
【套餐】嵌入式Linux C编程基础--朱有鹏
【套餐】2017软考系统集成项目——任铄
【套餐】Android 5.x顶级视频课程——李宁
【直播】广义线性模型及其应用——李科
【直播】从0到1 区块链的概念到实践
【直播】机器学习之凸优化——马博士
【套餐】微信订阅号+服务号Java版 v2.0--翟东平

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：13281次
• 积分：1086
• 等级：
• 排名：千里之外
• 原创：102篇
• 转载：0篇
• 译文：0篇
• 评论：2条
阅读排行
评论排行
最新评论