首页 技术 正文
技术 2022年11月7日
0 收藏 452 点赞 851 浏览 1167 个字

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

题目意思:电梯从0层开始向上运行,依次给出电梯所到达的楼层数,电梯上升一层需要6s,电梯下降一层需要4s,电梯停下来需要5s,问走完所有电梯要到达的楼层总共花了多少时间。

解题思路:确定电梯当前是向上还是向下,若是a[i]>a[i-1],向上运行,需要(a[i]-a[i-1])*6秒;若是a[i]<a[i-1],向下运行,需要(a[i]-a[i-1])*4秒。同时每停止一次需要5秒,最后累加起来即可。

#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
int i,n,sum=;
int a[];
cin>>n;
a[]=;
for(i=;i<=n;i++)
{
cin>>a[i];
}
for(i=;i<=n;i++)
{
if(a[i]>=a[i-])
{
sum+=(a[i]-a[i-])*;
}
else
{
sum+=(a[i-]-a[i])*;
}
}
sum+=n*;
cout<<sum;
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898