当前位置:网站首页>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 ;
}
边栏推荐
- 明明的随机数
- MySQL数据库基本操作-DDL | 黑马程序员
- @transactional滥用导致数据源连接池耗尽问题
- LM10丨余弦波动顺势网格策略
- Pythagorean number law (any three numbers can meet the conditions of Pythagorean theorem)
- The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
- 项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
- Educational Codeforces Round 22 E. Army Creation
- 测试工程师如何“攻城”(上)
- 测试工程师如何“攻城”(下)
猜你喜欢

西门子HMI下载时提示缺少面板映像解决方案

与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用

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

Stream stream

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

PolyFit软件介绍

在线SQL转Excel(xls/xlsx)工具

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

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

联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点
随机推荐
FPGA timing constraint sharing 01_ Brief description of the four steps
长城证券开户安全吗 买股票怎么开户
黑马程序员-软件测试--09阶段2-linux和数据库-31-43修改文件权限字母发的说明,-查找链接修改文件,查找文件命令,链接文件,压缩解压方式,vi编辑器基本使用,
1011 World Cup Betting (20 分)(PAT甲级)
The CDC of sqlserver can read the data for the first time, but it can't read the data after adding, deleting and modifying. What's the reason
Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading
26. Delete the duplicate item C solution in the ordered array
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
Shell 编程核心技术《四》
HDU 6440 2018中国大学生程序设计网络选拔赛
Double colon function operator and namespace explanation
TCP两次挥手,你见过吗?那四次握手呢?
876. Intermediate node of linked list
安徽 中安在线文旅频道推出“跟着小编游安徽”系列融媒体产品
FTP, SFTP file transfer
MySQL数据库基本操作-DDL | 黑马程序员
ftp、sftp文件传输
How test engineers "attack the city" (Part I)
Educational Codeforces Round 22 E. Army Creation
测试工程师如何“攻城”(下)