杭电1008

//前往同一层的情况要考虑
//fabs()函数,头文件#include<math.h>
//n=-123;fabs(n)=123;
#include <iostream>
//#include <math.h>
using namespace std;

int main()
{
    int N,count;
    while(cin>>N)
    {
        if(N==0) break;

        int n[N];

        for(int i=0;i<N;++i)
            cin>>n[i];

        count=n[0]*6+5;

        for(int j=0;j<N-1;++j)
        {   int t1=0,t2=0;

            if(n[j+1]-n[j]>=0)
                {
                    t1=n[j+1]-n[j];
                    count=count+t1*6+5;

                }
            else
            {
                t2=n[j]-n[j+1];
                count=count+t1*6+t2*4+5;
            }
        }

        cout<<count<<endl;
        count=0;
    }
        return 0;
}

你可能感兴趣的:(杭电1008)