当前位置:网站首页>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 ;
}
边栏推荐
- 在线文本行固定长度填充工具
- "Only one trip", active recommendation and exploration of community installation and maintenance tasks
- BCG 使用之CBCGPProgressDlgCtrl进度条使用
- Add namespace declaration
- 升级智能开关,“零火版”、“单火”接线方式差异有多大?
- Master the use of auto analyze in data warehouse
- Pytorch学习(四)
- Hough transform Hough transform principle
- 1009 Product of Polynomials(25 分)(PAT甲级)
- Wechat reading notes of "work, consumerism and the new poor"
猜你喜欢
Pythagorean number law (any three numbers can meet the conditions of Pythagorean theorem)
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
BCG 使用之CBCGPTabWnd控件(相当于MFC TabControl)
TCP两次挥手,你见过吗?那四次握手呢?
BCG 使用之新建向导效果
Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
Online sql to excel (xls/xlsx) tool
HMM隐马尔可夫模型最详细讲解与代码实现
Stream stream
English grammar_ Noun - use
随机推荐
English语法_名词 - 使用
Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading
Oracle with as ora-00903: invalid table name multi report error
Use canal and rocketmq to listen to MySQL binlog logs
Shell 编程核心技术《三》
HDU 1372 & POJ 2243 Knight moves (breadth first search)
Shell programming core technology "four"
牛客小白月赛7 I 新建 Microsoft Office Word 文档
Find the nth power of 2
添加命名空间声明
Pytest 可视化测试报告之 Allure
Add namespace declaration
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
Shell programming core technology "three"
1006 Sign In and Sign Out(25 分)(PAT甲级)
Functional interface
92. (cesium chapter) cesium building layering
Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
How test engineers "attack the city" (Part I)