当前位置:网站首页>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 ;
}
边栏推荐
- HMM隐马尔可夫模型最详细讲解与代码实现
- 【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
- 2022CoCa: Contrastive Captioners are Image-Text Fountion Models
- Introduction to polyfit software
- 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
- "Only one trip", active recommendation and exploration of community installation and maintenance tasks
- 函数式接口
- Shell 编程核心技术《四》
- 《工作、消费主义和新穷人》的微信读书笔记
- Shell 编程核心技术《二》
猜你喜欢
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
Hough Transform 霍夫变换原理
在线文本行固定长度填充工具
一文掌握数仓中auto analyze的使用
BCG 使用之新建向导效果
FPGA时序约束分享01_四大步骤简述
"Only one trip", active recommendation and exploration of community installation and maintenance tasks
The 300th weekly match of leetcode (20220703)
Some thoughts on whether the judgment point is located in the contour
牛客小白月赛7 谁是神箭手
随机推荐
Detailed explanation of issues related to SSL certificate renewal
指定输出的字符集
有关架构设计的个人思考(本文后续不断修改更新)
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
socket编程demo二
2014合肥市第三十一届青少年信息学奥林匹克竞赛(小学组)试题
HMM隐马尔可夫模型最详细讲解与代码实现
Unity adds a function case similar to editor extension to its script, the use of ContextMenu
生成XML元素
项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
English grammar_ Noun - use
YOLOv5s-ShuffleNetV2
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
1002. A+b for Polynomials (25) (PAT class a)
The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
Shell programming core technology "four"
函数式接口
爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
HDU 1097 A hard puzzle