当前位置:网站首页>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 ;
}
边栏推荐
- 项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
- Mysql database basic operation -ddl | dark horse programmer
- Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading
- The 300th weekly match of leetcode (20220703)
- 1006 sign in and sign out (25 points) (PAT class a)
- Swagger突然发癫
- ftp、sftp文件传输
- Hough Transform 霍夫变换原理
- Leetcode ransom letter C # answer
- 联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点
猜你喜欢

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

Detailed explanation of the binary processing function threshold() of opencv

Euler function

升级智能开关,“零火版”、“单火”接线方式差异有多大?

BCG 使用之新建向导效果

LM10丨余弦波动顺势网格策略

线上数据库迁移的几种方法

92. (cesium chapter) cesium building layering

2022CoCa: Contrastive Captioners are Image-Text Fountion Models

Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
随机推荐
Master the use of auto analyze in data warehouse
Technologie de base de la programmation Shell IV
92.(cesium篇)cesium楼栋分层
Summary and sorting of 8 pits of redis distributed lock
关于判断点是否位于轮廓内的一点思考
求2的n次方
勾股数规律(任意三个数能够满足勾股定理需要满足的条件)
HMM隐马尔可夫模型最详细讲解与代码实现
Specify the character set to output
BCG 使用之CBCGPProgressDlgCtrl進度條使用
Pythagorean number law (any three numbers can meet the conditions of Pythagorean theorem)
牛客小白月赛7 F题
Double colon function operator and namespace explanation
1008 Elevator(20 分)(PAT甲级)
QT realizes interface sliding switching effect
Shell 编程核心技术《二》
26. Delete the duplicate item C solution in the ordered array
Allure of pytest visual test report
How test engineers "attack the city" (Part 2)
Several methods of online database migration