思想;跟据题意进行编程即可【注意每次与上一个数进行比较】;
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
#include <sstream>
#include <set>
#include <string>
#include <stack>
#include <vector>
using namespace std;
const int N = 50;
typedef long long LL;
const int inf = 0x3f3f3f3f;
int main()
{
LL n;
while(cin>>n&&n)
{
LL m,ml,t=0;
cin>>m;
t+=m*6;
for(int i=1;i<n;i++)
{
cin>>ml;
if(ml>=m)
t+=(ml-m)*6;
else
t+=(m-ml)*4;
m=ml;
}
cout<<t+5*n<<endl;
}
return 0;
}