hdu1008Elevator

http://acm.hdu.edu.cn/showproblem.php?pid=1008

#include <iostream>
using namespace std;
int
main(int argc, char *argv[])
{

    int
n;
    int
a;
    while
(cin>>n)
    {
   
if
(n>0)
        {

        int
i=0;
        int
s=0;
        while
(n--)
        {

            cin>>a;
            if
(i<a)
            {

                s+=6*(a-i);
                s+=5;
                i=a;
            }

            else

            {

                s+=4*(i-a);
                s+=5;
                i=a;
            }
           
        }

            cout<<s<<endl;
    }

    else break
;
    }

        return
0;
}

posted @ 2013-04-02 11:24  90后程序媛  阅读(131)  评论(0编辑  收藏  举报