计算多组数据中电梯的不同路径所用的时间
2015-01-27 13:40
232 查看
Problem Description 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 There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed. Output Print the total time on a single line for each test case. Sample Input 1 2 3 2 3 1 0 Sample Output 17 41 #include <iostream> using namespace std; int main() { int a[100],n,i; while(cin>>n&&n!=0) { int s=0; for(i=0;i<n;i++) cin>>a[i]; s+=a[0]*6+5; for(i=1;i<n;i++) { if(a[i]>a[i-1]) s+=6*(a[i]-a[i-1])+5; else s+=4*(a[i-1]-a[i])+5; } cout<<s<<endl; } return 0; }
<img src="http://img.blog.csdn.net/20150127134140001?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYTcxNjEyMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
相关文章推荐
- 【例6】计算生成等于某个给定值的随机数据所用时间
- 例6 用LabVIEW计算生成等于某个给定值的随机数据所用时间
- [SQL]循环插入数据,并且计算插入所用时间
- 单线程扫描电脑所有文件与并行计算扫描电脑所有文件所用时间?
- Windows环境是使用C语言计算程序或算法执行时间的不同粒度实现
- sqlserver 触发器/计算两个时间的间隔天数/查询倒数第二条数据
- c# 计算程序执行时间,计算一段代码执行所用的时间,测试效率
- C/C++日期时间使用方法,struct tm, time_t, clock_t,计算循环所用时间
- 大数据计算:如何仅用1.5KB内存计算十亿个不同的对象
- [导入]c# 统计方法执行时间,计算缓存读取数据方法的命中率
- 开发日志:计算Java内一段代码运行所用的时间
- Oracle DATA数据类型中计算时间差
- 计算当天起始点和结束点时间戳 去当天的数据
- 【C++学习笔记】计算程序运行所用的时间
- 计算代码段所用时间
- cognos transformer 建一个85w数据的cube所用的时间,接优化
- 通过StateChangeEvent事件(StateChangeEventHadler委托)计算数据庫访问时间次数
- 计算加载页面所用的时间
- json 返回数据时间的绑定的转换 和时间的差值计算