Skip to main content

1008Elevator

·221 words·2 mins
WFUing
Author
WFUing
A graduate who loves coding.
Table of Contents

1008 Elevator
#

0、题目
#

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:
#

41

1、题目大意
#

给出电梯上下楼层,根据规则计算运行时间

2、大致思路
#

简单题

3、AC代码
#

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=110;
int n,a[maxn],ans;

int main() {
	scanf("%d",&n);
	a[0]=0;
	ans=0;
	for(int i=1; i<=n; i++) {
		scanf("%d",&a[i]);
	}
	for(int i=1; i<=n; i++) {
		int tmp=0;
		if(a[i]>=a[i-1]){
			tmp=(a[i]-a[i-1])*6;
		}else{
			tmp=(a[i-1]-a[i])*4;
		}
		tmp+=5;
		ans+=tmp;
	}
	cout<<ans;
	return 0;
}