HDU
来源:互联网 发布:java项目上线流程 编辑:程序博客网 时间:2024/06/05 09:53
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>#include <cstdio>using namespace std;int main(){ int n; int a[10000]; while(cin>>n && n) { int ans=0; for(int i=0;i<n;i++) cin>>a[i]; ans+=(a[0]-0)*6+5; for(int i=1;i<n;i++) { if(a[i]>a[i-1]) ans+=(a[i]-a[i-1])*6+5; else ans+=(a[i-1]-a[i])*4+5; } cout<<ans<<endl; } return 0;}
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- LeetCode 521. Longest Uncommon Subsequence I
- 初识java
- MFC Windows程序设计--工具栏,状态栏,组合栏
- IDEA的草稿功能,瞬间变为强大的文本编辑器
- Wing IDE安装与破解方法
- HDU
- Could not find helloworld.apk
- 第64天(就业班) springmvc
- PCA的数学原理
- 初识CSS3
- S4HANA OP1511环境说明
- 记京东Java开发实习生一面
- 杭电oj2016_数据的交换输出
- 人性的弱点