当前位置:网站首页>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 ;
}
边栏推荐
- An example of multi module collaboration based on NCF
- 【uniapp】uniapp开发app在线预览pdf文件
- 2022CoCa: Contrastive Captioners are Image-Text Fountion Models
- 2022-07-04: what is the output of the following go language code? A:true; B:false; C: Compilation error. package main import 'fmt' func
- “只跑一趟”,小区装维任务主动推荐探索
- [uniapp] uniapp development app online Preview PDF file
- Build your own website (15)
- Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
- 2019年蜀山区第十五届青少年信息学竞赛
- 千万不要只学 Oracle、MySQL!
猜你喜欢
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
Lm10 cosine wave homeopathic grid strategy
Use canal and rocketmq to listen to MySQL binlog logs
Don't just learn Oracle and MySQL!
升级智能开关,“零火版”、“单火”接线方式差异有多大?
node_exporter部署
Bi skills - permission axis
更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?
Build your own website (15)
Lex and yacc based lexical analyzer + parser
随机推荐
Wireshark网络抓包
神经网络物联网应用技术学什么
2021 合肥市信息学竞赛小学组
YOLOv5s-ShuffleNetV2
node_exporter部署
Shell programming core technology "I"
How to use async Awati asynchronous task processing instead of backgroundworker?
php伪原创api对接方法
To sort out messy header files, I use include what you use
Bi skills - permission axis
神经网络物联网是什么意思通俗的解释
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
LeetCode 赎金信 C#解答
使用FTP
[release] a tool for testing WebService and database connection - dbtest v1.0
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
Pytest 可视化测试报告之 Allure
国元期货是正规平台吗?在国元期货开户安全吗?
2022CoCa: Contrastive Captioners are Image-Text Fountion Models