浙大 PAT Advanced level 1008. Elevator
2016-04-23 20:18
330 查看
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
非常简单的模拟题
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
非常简单的模拟题
#include <iostream> using namespace std; int main() { int n; // 总输入个数 int cur = 0; // 当前楼层 int next; // 下一个停靠楼层 unsigned int time = 0; cin >> n; time += 5*n; while(n--) { cin >> next; if (next > cur) { time += 6*(next-cur); } if (next < cur) { time += 4*(cur-next); } cur = next; } cout << time << endl; system("pause"); return 0; }
相关文章推荐
- Unity脚本执行顺序
- 编程之美之子数组和的最大值(二维)
- React Native官方实例UIExplorer项目(for android)运行遇到的问题
- 第九周项目四 人数不定的工资类
- Node.js全局对象
- bzoj4546 codechef XRQRS
- matlab保存图片的四种方法&&遇到的一些问题
- 常用的Eclipse快捷键
- 第八周作业
- JMS基础知识
- Android 开发 Android-Failed to resolve: com.android.support:appcompat-v7:23.+
- 剑指offer 面试题6:重建二叉树(Leetcode105. Construct Binary Tree from Preorder and Inorder Traversal) 解题报告
- 每日Scrum(5)
- 站立会议第五天
- stack堆栈容器
- json&jsonp
- python内置函数super()
- 重定向和管道——让Linux如虎添翼
- 欢迎使用CSDN-markdown编辑器
- 重建二叉树java