练习一1006
来源:互联网 发布:网络出现异常怎么办 编辑:程序博客网 时间:2024/05/21 09:30
roblem 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
Statistic | Submit | Back
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
Statistic | Submit | Back
思路:
本题非常简单,只是要注意只有电梯到达终点时才会停留5.
代码:
#include<iostream>
using namespace std;
int main()
{
int n,a[100];
while(cin>>n)
{
if(n==0) break;
for(int i=0;i<n;i++)
cin>>a[i];
int t=a[0]*6+5;
for(int j=1;j<n;j++)
{
if(a[j]>a[j-1]) t+=(a[j]-a[j-1])*6+5;
else t+=(a[j-1]-a[j])*4+5;
}
cout<<t<<endl;
}
return 0;
}
using namespace std;
int main()
{
int n,a[100];
while(cin>>n)
{
if(n==0) break;
for(int i=0;i<n;i++)
cin>>a[i];
int t=a[0]*6+5;
for(int j=1;j<n;j++)
{
if(a[j]>a[j-1]) t+=(a[j]-a[j-1])*6+5;
else t+=(a[j-1]-a[j])*4+5;
}
cout<<t<<endl;
}
return 0;
}
0 0
- 练习一1006
- 练习一
- 练习一
- 练习一
- 练习一
- 2016SDAU课程练习一1006
- 2016SDAU课程练习一 1006
- 课程练习一 Problem G id:1006
- access+asp 练习一
- 数据库练习一答案
- C++基础练习一
- XML练习(一)
- javascript练习(一)
- jQuery练习(一)
- 软件测试练习一
- 听力练习一
- c++练习一
- OpenGL小练习一
- HDU 3001 Travelling 三进制状压DP
- after会在元素内容后面而不是元素后面插入一个伪元素
- Mac 下安装MySQL5.7.6版本时,修改安装生成的root临时密码时遇到的一个问题
- 工作中常用的第三方框架
- memcached全面剖析--3.memcached的删除机制和发展方向
- 练习一1006
- 你哈啦啦啦
- 基础总结之一:Activity生命周期
- CDOJ 1066 Palindromic String 字符串哈希/马拉车算法
- 【Python】基于Celery的分布式应用
- c++ 全局变量 局部变量
- Uva 10635 简单dp
- 【机器学习】最小中值平方法
- 用数学方法解决工程问题系列(四) 计算包围一组多边形的几何形状