【PAT甲级】1008 Elevator (20 分)

题意:

电梯初始状态停在第0层,给出电梯要接人的层数和层序号,计算接到所有人需要的时间,接完人后电梯无需回到1层(1层不是0层)。电梯上升一层需要6秒,下降一层需要4秒,接人停留时间为5秒。

代码:

#include<bits/stdc++.h>

using namespace std;

int a[100007];

int main(){

int n;

cin>>n;

int ans=0;

for(int i=1;i<=n;++i){

cin>>a[i];

if(a[i]>a[i-1])

ans+=(a[i]-a[i-1])*6+5;

else

ans+=(a[i-1]-a[i])*4+5;

}

cout<<ans;

return 0;

}

原文地址:https://www.cnblogs.com/ldudxy/p/11218121.html

时间: 2024-07-29 11:09:57

【PAT甲级】1008 Elevator (20 分)的相关文章

[PTA] PAT(A) 1008 Elevator (20 分)

目录 Problem Description Input Output Sample Sample Input Sample Output Solution Analysis Code Problem portal: 1008 Elevator (20 分) Description  The highest building in our city has only one elevator. A request list is made up with $N$ positive numbers

1008 Elevator (20分)

1008 Elevator (20分) 题目: 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

【PAT甲级】1008 Elevator (20分)

1008 Elevator 题目: 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

PAT甲级——1035 Password (20分)

To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L in lowercase), or 0 (zero) from O (o in uppercase)

PAT 甲级 1008 Elevator

https://pintia.cn/problem-sets/994805342720868352/problems/994805511923286016 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 spe

1008 Elevator (20 分)

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 seco

PAT:1008. Elevator (20) AC

#include<stdio.h> int main() { int n,ans=0,now=0; //要停n层,ans是总时间,now代表当前层数 scanf("%d",&n); for(int i=0 ; i<n ; ++i) { int tmp; scanf("%d",&tmp); if(tmp>now) //上楼,每上一层6秒 { ans+=(tmp-now)*6; now=tmp; } else if(tmp<

PAT甲级——1005.SpellItRight(20分)

Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English. Input Specification: Each input file contains one test case. Each case occupies one line which contains an N (≤10 ?1

1008. Elevator (20)——PAT (Advanced Level) Practise

题目信息: 1008. Elevator (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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 w