当前位置:网站首页>1008 Elevator(20 分)(PAT甲级)
1008 Elevator(20 分)(PAT甲级)
2022-07-04 17:58:00 【相思明月楼】
problem description:
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:
4 1
#include <iostream>
using namespace std;
int main() {
int n, sum, beginn, endd, x;
sum = beginn = endd = 0;
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d", &x);
endd = x;
if(endd > beginn) {
sum += (endd-beginn)*6+5;
beginn = endd;
} else if(endd < beginn) {
sum += (beginn-endd)*4+5;
beginn = endd;
} else {
sum += 5;
}
}
cout<<sum<<endl;
return 0 ;
}
边栏推荐
猜你喜欢

每日一题(2022-07-02)——最低加油次数

Pytorch学习(四)

Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?

大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行

Introduction to polyfit software
![[uniapp] uniapp development app online Preview PDF file](/img/11/d640338c626249057f7ad616b55c4f.png)
[uniapp] uniapp development app online Preview PDF file

读写关闭的channel是啥后果?

神经网络物联网平台搭建(物联网平台搭建实战教程)

PointNeXt:通过改进的模型训练和缩放策略审视PointNet++

Hough Transform 霍夫变换原理
随机推荐
How to use async Awati asynchronous task processing instead of backgroundworker?
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
2022健康展,北京健博会,中国健康展,大健康展11月13日
Nebula importer data import practice
The CDC of sqlserver can read the data for the first time, but it can't read the data after adding, deleting and modifying. What's the reason
Unity editor extends C to traverse all pictures in folders and subdirectories
PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
Qt实现界面滑动切换效果
Lex and yacc based lexical analyzer + parser
Pointnet/Pointnet++点云数据集处理并训练
删除字符串中出现次数最少的字符【JS,Map排序,正则】
LeetCode 赎金信 C#解答
整理混乱的头文件,我用include what you use
26. Delete the duplicate item C solution in the ordered array
LM10丨余弦波动顺势网格策略
Is the securities account opened by qiniu safe?
Guys, for help, I use MySQL CDC 2.2.1 (Flink 1.14.5) to write Kafka and set
Leetcode fizzbuzz C # answer
Process of manually encrypt the mass-producing firmware and programming ESP devices
QT realizes interface sliding switching effect