当前位置: 代码迷 >> 综合 >> HDOJ 1008 Elevator
  详细解决方案

HDOJ 1008 Elevator

热度:32   发布时间:2023-10-21 20:27:10.0

HDACM1008

先算停的所有时间和,在判断电梯是上还是下,每上走一层就+6,每下一层就+4

import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner sc = new Scanner(System.in);while (sc.hasNext()) {int n = sc.nextInt();if (n==0) {break;}int time = 5*n;int b =0;while (n-->0) {int a = sc.nextInt();if (a-b>0) {time += (a-b)*6;}else {time += (b-a)*4;}b=a;}System.out.println(time);        }}
}