题意:
题目背景
汉东省政法大学附属中学所在的光明区最近实施了名为“智慧光明”的智慧城市项目。具体到交通领域,通过“智慧光明”终端,可以看到光明区所有红绿灯此时此刻的状态。小明的学校也安装了“智慧光明”终端,小明想利用这个终端给出的信息,估算自己放学回到家的时间。
问题描述
一次放学的时候,小明已经规划好了自己回家的路线,并且能够预测经过各个路段的时间。同时,小明通过学校里安装的“智慧光明”终端,看到了出发时刻路上经过的所有红绿灯的指示状态。请帮忙计算小明此次回家所需要的时间。
输入格式
输入的第一行包含空格分隔的三个正整数 r、y、g,表示红绿灯的设置。这三个数均不超过 106。
输入的第二行包含一个正整数 n,表示小明总共经过的道路段数和路过的红绿灯数目。
接下来的 n 行,每行包含空格分隔的两个整数 k、t。k=0 表示经过了一段道路,将会耗时 t 秒,此处 t 不超过 106;k=1、2、3 时,分别表示出发时刻,此处的红绿灯状态是红灯、黄灯、绿灯,且倒计时显示牌上显示的数字是 t,此处 t 分别不会超过 r、y、g。
输出格式
输出一个数字,表示此次小明放学回家所用的时间。
样例输入
30 3 30
8
0 10
1 5
0 11
2 2
0 6
0 3
3 10
0 3
样例输出
70
样例说明
小明先经过第一段道路,用时 10 秒,然后等待 5 秒的红灯,再经过第二段道路,用时 11 秒,然后等待 2 秒的黄灯和 30 秒的红灯,再经过第三段、第四段道路,分别用时6、3秒,然后通过绿灯,再经过最后一段道路,用时 3 秒。共计 10 + 5 + 11 + 2 + 30 + 6 + 3 + 3=70 秒。
public class Light {
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
int r = scanner.nextInt();
int y = scanner.nextInt();
int g = scanner.nextInt();
int n = scanner.nextInt();
if (r<Math.pow(10, 6)&&y<Math.pow(10, 6)&&g<Math.pow(10, 6)) {
System.out.println(Result(r,y,g,n));
}
}
public static int Result(int red,int yellow,int green,int n) {
Scanner scanner = new Scanner(System.in);
int result = 0;
int[][] array = new int[n][2];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
array[i][j] = scanner.nextInt();
}
}
for (int i = 0; i < array.length; i++) {
if(array[i][0]==2) {
result = result+array[i][1]+red;
}else if (array[i][0]==3) {
}else {
result = result+array[i][1];
}
}
return result;
}
}