🍑 HDOJ 1008 Elevator
输入
1 2
3 2 3 1
0
输出
17
41
🍑 AC代码
import java.util.Scanner;
public class Main
{
static int N = 110;
static int[] a = new int[N];
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (sc.hasNext())
{
int n = sc.nextInt();
if (n == 0)
break;
for (int i = 0; i < n; i++)
a[i] = sc.nextInt();
int res = 5 * n;//每层楼都必须停5秒
int pre = 0;
for (int i = 0; i < n; i++)
{
if (a[i] > pre)
res += (a[i] - pre) * 6;
else if (a[i] < pre)
res += (pre - a[i]) * 4;
pre = a[i];
}
System.out.println(res);
}
}
}