当前位置:网站首页>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 ;
}
边栏推荐
- 西门子HMI下载时提示缺少面板映像解决方案
- 一文掌握数仓中auto analyze的使用
- Unity adds a function case similar to editor extension to its script, the use of ContextMenu
- 关于判断点是否位于轮廓内的一点思考
- The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize
- Shell 編程核心技術《四》
- 牛客小白月赛7 F题
- 1002. A+b for Polynomials (25) (PAT class a)
- BCG 使用之CBCGPProgressDlgCtrl进度条使用
- “只跑一趟”,小区装维任务主动推荐探索
猜你喜欢
Master the use of auto analyze in data warehouse
联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点
92. (cesium chapter) cesium building layering
MySQL数据库基本操作-DDL | 黑马程序员
Several methods of online database migration
Stream stream
The 300th weekly match of leetcode (20220703)
升级智能开关,“零火版”、“单火”接线方式差异有多大?
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
如何使用Async-Awati异步任务处理代替BackgroundWorker?
随机推荐
Hough Transform 霍夫变换原理
ftp、sftp文件传输
2014合肥市第三十一届青少年信息学奥林匹克竞赛(小学组)试题
Generate XML elements
An example of multi module collaboration based on NCF
C # implementation defines a set of SQL statements that can be executed across databases in the middle of SQL (detailed explanation of the case)
FPGA timing constraint sharing 01_ Brief description of the four steps
Shell 编程核心技术《一》
勾股数规律(任意三个数能够满足勾股定理需要满足的条件)
测试工程师如何“攻城”(上)
1005 Spell It Right(20 分)(PAT甲级)
FTP, SFTP file transfer
Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
Leetcode ransom letter C # answer
Educational Codeforces Round 22 E. Army Creation
node_exporter部署
@transactional滥用导致数据源连接池耗尽问题
The kth largest element in the array
牛客小白月赛7 I 新建 Microsoft Office Word 文档
Educational Codeforces Round 22 E. Army Creation