PAT -- 甲级1008(1008 Elevator)

1008 Elevator (20 分)

The highest building in our city has only one elevator. A request list is made up with NNN 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 NNN, followed by NNN 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

给一个数n后面跟着n个数,表示电梯的层数,刚开始从0层开始,上升1层用6秒,下降一层用4秒,停一层用5秒,问按照这个顺序执行需要用几秒,电梯最后不必返回0层

思路:模拟

Code

#include<bits/stdc++.h>

using namespace std;

int val[105],n;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> val[i];
	}
	int res = val[0] * 6, tmp;
	for (int i = 1; i < n; i++) {
		tmp = val[i] - val[i - 1];
		if (tmp > 0) {
			res += tmp * 6;
		} else {
			res -= tmp * 4;
		}
	}
	cout << res + n * 5 << endl;
	return 0;
}
全部评论

相关推荐

03-26 13:04
已编辑
电子科技大学 算法工程师
xiaowl:你这个简历“条目上”都比较有深度性,但是实际上面试官又没法很好的评估你是怎么达到很多看上去很厉害的结果的。要避免一些看上去很厉害的包装,比如高效的内存复用策略的表达,如果仅是简单的一些内存共享机制,而且面试上也没有深挖的空间,就不要这样表达。比如,工程化模式本质上可能就是定义了一些abstract class,那也就没特别多值得讲的内容。建议简历上应该侧重那些你花了大量时间和精力解决、研究的问题,不要过分追求“丰富”,而是关注在技术深入度、问题解决能力的表现上。
没有实习经历,还有机会进...
点赞 评论 收藏
分享
04-03 15:12
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务