当前位置:网站首页>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 ;
}
边栏推荐
- 大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
- Online data migration scheme encountered in the project 1 - general idea sorting and technical sorting
- 1002. A+B for Polynomials (25)(PAT甲级)
- Explicit random number
- 92.(cesium篇)cesium楼栋分层
- 升级智能开关,“零火版”、“单火”接线方式差异有多大?
- .NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
- Bi skills - permission axis
- Matrix flip (array simulation)
- HDU 1097 A hard puzzle
猜你喜欢

Euler function

勾股数规律(任意三个数能够满足勾股定理需要满足的条件)

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

一文掌握数仓中auto analyze的使用

Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples

Pytorch学习(四)

Stream流

如何使用Async-Awati异步任務處理代替BackgroundWorker?

TCP两次挥手,你见过吗?那四次握手呢?

Bi skills - permission axis
随机推荐
BCG 使用之CBCGPProgressDlg进度条使用
1006 sign in and sign out (25 points) (PAT class a)
The kth largest element in the array
Bi skills - permission axis
关于判断点是否位于轮廓内的一点思考
Detailed explanation of the binary processing function threshold() of opencv
BCG 使用之CBCGPProgressDlgCtrl进度条使用
English grammar_ Noun - use
牛客小白月赛7 谁是神箭手
FPGA timing constraint sharing 01_ Brief description of the four steps
Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
Summary and sorting of 8 pits of redis distributed lock
TCP两次挥手,你见过吗?那四次握手呢?
添加命名空间声明
如何使用Async-Awati异步任务处理代替BackgroundWorker?
.NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
ftp、sftp文件传输
kotlin 条件控制
Explicit random number
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks