当前位置:网站首页>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 ;
}
边栏推荐
- 页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
- 指定输出的字符集
- There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
- IBM WebSphere MQ检索邮件
- Have you guys ever used CDC direct Mysql to Clickhouse
- 模板_大整数减法_无论大小关系
- Shell 编程核心技术《二》
- ftp、sftp文件传输
- Shell 编程核心技术《四》
- [release] a tool for testing WebService and database connection - dbtest v1.0
猜你喜欢
Use canal and rocketmq to listen to MySQL binlog logs
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
性能优化之关键渲染路径
Build your own website (15)
[uniapp] uniapp development app online Preview PDF file
DeFi生态NFT流动性挖矿系统开发搭建
To sort out messy header files, I use include what you use
用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
Wireshark网络抓包
FPGA timing constraint sharing 01_ Brief description of the four steps
随机推荐
Summary and sorting of 8 pits of redis distributed lock
1672. 最富有客户的资产总量
在线SQL转Excel(xls/xlsx)工具
页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
Wireshark网络抓包
大佬们,求助一下,我用mysql cdc 2.2.1(flink 1.14.5)写入kafka,设置
To sort out messy header files, I use include what you use
Pytorch学习(四)
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
26. Delete the duplicate item C solution in the ordered array
发送和接收IBM WebSphere MQ消息
使用FTP
信息学奥赛一本通 1336:【例3-1】找树根和孩子
LeetCode 赎金信 C#解答
Process of manually encrypt the mass-producing firmware and programming ESP devices
更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?
The kth largest element in the array
Send and receive IBM WebSphere MQ messages
FPGA时序约束分享01_四大步骤简述
基于NCF的多模块协同实例