当前位置:网站首页>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 ;
}
边栏推荐
猜你喜欢

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

更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?

物联网应用技术的就业前景和现状

大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
![[release] a tool for testing WebService and database connection - dbtest v1.0](/img/4e/4154fec22035725d6c7aecd3371b05.jpg)
[release] a tool for testing WebService and database connection - dbtest v1.0

建立自己的网站(15)

奥迪AUDI EDI INVOIC发票报文详解

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

YOLOv5s-ShuffleNetV2

Process of manually encrypt the mass-producing firmware and programming ESP devices
随机推荐
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
Rookie post station management system based on C language
Wechat reading notes of "work, consumerism and the new poor"
repeat_P1002 [NOIP2002 普及组] 过河卒_dp
函数式接口
Summary and sorting of 8 pits of redis distributed lock
Caché WebSocket
1672. Total assets of the richest customers
Go微服务(二)——Protobuf详细入门
2022-07-04: what is the output of the following go language code? A:true; B:false; C: Compilation error. package main import 'fmt' func
《工作、消费主义和新穷人》的微信读书笔记
《看完就懂系列》字符串截取方法substr() 、 slice() 和 substring()之间的区别和用法
Using FTP
Shell 编程核心技术《一》
Is Guoyuan futures a regular platform? Is it safe to open an account in Guoyuan futures?
问下各位大佬有用过cdc直接mysql to clickhouse的么
Perfect JS event delegation
在线SQL转Excel(xls/xlsx)工具
Shell 編程核心技術《四》
[mathematical basis of machine learning] (I) linear algebra (Part 1 +)