当前位置:网站首页>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 ;
}
边栏推荐
- 1003 emergency (25 points) (PAT class a)
- The 15th youth informatics competition in Shushan District in 2019
- BCG 使用之CBCGPProgressDlg进度条使用
- 在线文本行固定长度填充工具
- .NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
- Oracle with as ORA-00903: invalid table name 多表报错
- Pythagorean number law (any three numbers can meet the conditions of Pythagorean theorem)
- BCG 使用之CBCGPProgressDlgCtrl进度条使用
- C# 使用StopWatch测量程序运行时间
- 2021 Hefei informatics competition primary school group
猜你喜欢

FPGA timing constraint sharing 01_ Brief description of the four steps

SSRS筛选器的IN运算(即包含于)用法

线上数据库迁移的几种方法
牛客小白月赛7 谁是神箭手

Master the use of auto analyze in data warehouse

Stream stream

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

"Only one trip", active recommendation and exploration of community installation and maintenance tasks
Summary and sorting of 8 pits of redis distributed lock

在线SQL转Excel(xls/xlsx)工具
随机推荐
1006 Sign In and Sign Out(25 分)(PAT甲级)
Educational Codeforces Round 22 E. Army Creation
爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
Oracle with as ORA-00903: invalid table name 多表报错
勾股数规律(任意三个数能够满足勾股定理需要满足的条件)
Master the use of auto analyze in data warehouse
. Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
Wireshark网络抓包
Have you guys ever used CDC direct Mysql to Clickhouse
Educational Codeforces Round 22 E. Army Creation
Niuke Xiaobai monthly race 7 I new Microsoft Office Word document
Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
Shell 编程核心技术《一》
node_ Exporter deployment
《工作、消费主义和新穷人》的微信读书笔记
2014 Hefei 31st youth informatics Olympic Games (primary school group) test questions
Guys, for help, I use MySQL CDC 2.2.1 (Flink 1.14.5) to write Kafka and set
Allure of pytest visual test report
偏移量函数及开窗函数