贪心 1006

来源:互联网 发布:出入无时 莫知其乡 编辑:程序博客网 时间:2024/06/16 23:47

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

3 2 3 10
 

Sample Output
1741
上电梯的问题 很简单的啦 上去 6 下去 4分钟 停留 5分钟 ok
#include<iostream>#include<string.h>#include<set>#include<stdio.h>#include<vector>#include<algorithm>#include<numeric>#include<math.h>#include<string.h>#include<sstream>#include<stdio.h>#include<string>#include<cstdlib>#include<algorithm>#include<iostream>#include<map>#include<queue>#include<string>using namespace std;int main(){    int n;    int i;    int f;    vector<int> s;    while(cin>>n&&n!=0)    {   s.clear();        for(i=1;i<=n;i++)        {            cin>>f;            s.push_back(f);        }        int sum;        sum=0;        sum=sum+s[0]*6;        for(i=1;i<n;i++)        {            if(s[i]>s[i-1])            {                sum=sum+(s[i]-s[i-1])*6;            }            else            {                sum=sum+(s[i-1]-s[i])*4;            }        }        sum=sum+n*5;        cout<<sum<<endl;    }    return 0;}


3 2 3 10
 

Sample Output
1741
0 0