当前位置:网站首页>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 ;
}
边栏推荐
- BI技巧丨权限轴
- 神经网络物联网平台搭建(物联网平台搭建实战教程)
- Pointnet/Pointnet++点云数据集处理并训练
- 与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
- 从实时应用角度谈通信总线仲裁机制和网络流控
- 26. Delete the duplicate item C solution in the ordered array
- LM10丨余弦波动顺势网格策略
- 问下各位大佬有用过cdc直接mysql to clickhouse的么
- [opencv introduction to mastery 9] opencv video capture, image and video conversion
- Introduction to polyfit software
猜你喜欢
Pytorch学习(四)
YOLOv5s-ShuffleNetV2
Summary and sorting of 8 pits of redis distributed lock
神经网络物联网平台搭建(物联网平台搭建实战教程)
小发猫物联网平台搭建与应用模型
如何使用Async-Awati异步任務處理代替BackgroundWorker?
用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
从实时应用角度谈通信总线仲裁机制和网络流控
Rookie post station management system based on C language
英特尔集成光电研究最新进展推动共封装光学和光互连技术进步
随机推荐
2022养生展,健康展,北京大健康展,健康产业展11月举办
Go microservice (II) - detailed introduction to protobuf
爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
The 15th youth informatics competition in Shushan District in 2019
【uniapp】uniapp开发app在线预览pdf文件
OpenCV的二值化处理函数threshold()详解
Wireshark网络抓包
测试工程师如何“攻城”(下)
发送和接收IBM WebSphere MQ消息
Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
1672. 最富有客户的资产总量
神经网络物联网平台搭建(物联网平台搭建实战教程)
One question per day (2022-07-02) - Minimum refueling times
Qt实现界面滑动切换效果
In flinksql, in addition to data statistics, is the saved data itself a state
在线SQL转Excel(xls/xlsx)工具
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
如何使用Async-Awati异步任务处理代替BackgroundWorker?
Generate XML elements
FPGA时序约束分享01_四大步骤简述