杭电1008

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package oj;

import java.util.Scanner;

public class Main_1008 {

public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
while(scanner.hasNext()){
int n=scanner.nextInt();
if (n==0) {
break;
}else{
int[] a=new int[n];
for(int i=0;i<a.length;i++){
a[i]=scanner.nextInt();
}
doThing(a);
}
}

}

private static void doThing(int[] a) {
int step=0;
int count=0;
for(int i=0;i<a.length;i++){
count+=5;
int distance=a[i]-step;
if (distance>0) {
count+=distance*6;
}else{
count+=(-distance*4);
}
step=a[i];
}
System.out.println(count);

}

}