当前位置:网站首页>1008 elevator (20 points) (PAT class a)
1008 elevator (20 points) (PAT class a)
2022-07-04 19:37:00 【Acacia moon tower】
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 ;
}
边栏推荐
- Double colon function operator and namespace explanation
- Allure of pytest visual test report
- Euler function
- Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
- BCG 使用之新建向导效果
- SSRS筛选器的IN运算(即包含于)用法
- "Only one trip", active recommendation and exploration of community installation and maintenance tasks
- Jetpack compose tutorial
- Pointnet/Pointnet++点云数据集处理并训练
- Lm10 cosine wave homeopathic grid strategy
猜你喜欢

Pythagorean number law (any three numbers can meet the conditions of Pythagorean theorem)

Mysql database basic operation -ddl | dark horse programmer

OpenCV的二值化处理函数threshold()详解

Euler function

92. (cesium chapter) cesium building layering

如何使用Async-Awati异步任务处理代替BackgroundWorker?

How to use async Awati asynchronous task processing instead of backgroundworker?

【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案

联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点

黑马程序员-软件测试--09阶段2-linux和数据库-31-43修改文件权限字母发的说明,-查找链接修改文件,查找文件命令,链接文件,压缩解压方式,vi编辑器基本使用,
随机推荐
HDU 6440 2018 Chinese college student program design network competition
Introduction to polyfit software
.NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
关于判断点是否位于轮廓内的一点思考
线上数据库迁移的几种方法
"Only one trip", active recommendation and exploration of community installation and maintenance tasks
1011 World Cup Betting (20 分)(PAT甲级)
YOLOv5s-ShuffleNetV2
添加命名空间声明
Double colon function operator and namespace explanation
西门子HMI下载时提示缺少面板映像解决方案
TCP两次挥手,你见过吗?那四次握手呢?
Unity adds a function case similar to editor extension to its script, the use of ContextMenu
How test engineers "attack the city" (Part 2)
Guys, for help, I use MySQL CDC 2.2.1 (Flink 1.14.5) to write Kafka and set
Master the use of auto analyze in data warehouse
Swagger突然发癫
Technologie de base de la programmation Shell IV
反射(一)
Explicit random number