1008. Elevator (20)
2016-04-11 11:59
447 查看
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
IDEA
很简单的题目,没啥好说的。。。
CODE
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
IDEA
很简单的题目,没啥好说的。。。
CODE
#include<iostream> #define up 6 #define down 4 #define stop 5 using namespace std; int main(){ int n; cin>>n; int sum_time=0; int pre=0; for(int i=0;i<n;i++){ int last; cin>>last; if(pre<=last){ sum_time+=(last-pre)*up+stop; }else{ sum_time+=(pre-last)*down+stop; } pre=last; } cout<<sum_time; return 0; }
相关文章推荐
- MTT PRocess
- python-面向对象(三)——类的特殊成员
- iOS动态计算Label的宽高
- LLDB 崩溃调试
- SVGALib
- 中文和英文的比较
- Mysql非安装版的安装使用相关问题
- knockout.js
- 这些小工具让你的Android 开发更高效
- PHP实现的浏览器检查类
- 关于 Java 中 finally 语句块的深度辨析
- 有上下界的网络流
- OpenGL之坐标转换(好文-清晰版)
- 测试驱动开发(TDD)在海外组的实践总结
- OpenCV中cvADDS()为啥第二个参数要是CvScalar类型?mask=NULL又是何意?
- LeetCode 14. Longest Common Prefix
- 【day0411 C++】字符串流istringstream和ostringstream的用法
- ZZULI 1868: UP UP UP!【dp】
- 决策树的数学原理
- vsftp登陆错误530login incorrect及500 oops问题解决