您的位置:首页 > 其它

HDU 1008电梯问题

2017-07-23 11:03 344 查看

Elevator

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 73522 Accepted Submission(s): 40461

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

思路

1、题目比较水,秒过。大概题意:就是说现在有个升降机,上升一层就要花6秒时间,到了目标楼层后会停留5秒时间,下降一层要花4秒时间,你一开始现在在0层,OJ提供你楼层信息,你计算出整个过程所花费的时间。

2、注意一点就是每行第一个数据代表之后有几组数据。并非算做楼层的

C++解法(OJ C++)

#include <iostream>
using namespace std;

int main()
{
int a[101]={0};
while(cin>>a[0])
{
int end=0;
int begin=0;
int total=0;
int count=1;
if(a[0]==0)
break;
for(int i=1;i<=a[0];i++)
{
cin>>a[i];
count++;
}
for(int i=1;i<count;)
{
end=a[i];

4000
if(end-begin>0)
{
total+=((end-begin)*6+5);
i++;
begin=a[i-1];
}
else
{
total+=((begin-end)*4+5);
i++;
begin=a[i-1];
}
}
cout<<total<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: