Hdu Problem E
来源:互联网 发布:cpp socket编程 编辑:程序博客网 时间:2024/05/29 15:33
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.
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 23 2 3 10
Sample Output
1741
代码:
#include <iostream>#include <cmath>using namespace std;int main(){ int a,i,j,t,sum; while (cin>>t&&t) { int a[t+1]; a[0]=0; sum=0; i=1; while(i<=t) cin>>a[i++]; for (i=1;i<=t;i++) { if(a[i]>a[i-1]) sum=sum+(a[i]-a[i-1])*6+5; else sum=sum+(a[i-1]-a[i])*4+5; } cout<<sum<<endl; } return 0;}运行结果:
0 0
- Hdu Problem E
- HDU 5689 Problem E
- dp基础7-- [HDU-1087] [Problem E]
- Problem E
- Problem E
- Problem E
- Problem E
- Problem E
- Problem E
- Problem E
- Problem E
- problem E
- Problem E
- Problem E
- Problem E
- Problem E
- Problem E
- Problem E
- ZOJ:3633 Alice's present(离线处理)
- FKJAVA读书笔记--第七章--与运行环境的交互
- UIViewController的生命周期
- xueweird 无法打开包括文件:“extensions/ExtensionMacros.h”: No such file or directory无法打开包括文件:“extensions/Exte
- 我的java学习笔记(15)关于接口
- Hdu Problem E
- string,vector和array(C++ Primer读书笔记)
- Swift 1
- 给自己的开源库添加cocopods支持
- qt 中建立空项目时找不到头文件问题
- HDU 1754 I Hate It(线段树入门题)
- IOS 单例的两种方法
- POJ 2488A Knight's Journey
- android 自己实现的一个类似expandablelistview的一个控件