forked from improper4/uva
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UVa00394_Mapmaker.java
89 lines (76 loc) · 2.6 KB
/
UVa00394_Mapmaker.java
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package uva;
/* USER: 46724 (sfmunera) */
/* PROBLEM: 330 (394 - Mapmaker) */
/* SUBMISSION: 08571942 */
/* SUBMISSION TIME: 2011-02-11 19:02:31 */
/* LANGUAGE: 2 */
import java.util.*;
public class UVa00394_Mapmaker {
static class Array {
String name;
int base;
int size;
int D;
int[] lower;
int[] upper;
public Array(String n, int b, int s, int d, int[] l, int[] u) {
this.name = n;
this.base = b;
this.size = s;
this.D = d;
this.lower = l;
this.upper = u;
}
}
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
int N = Integer.parseInt(in.next());
int R = Integer.parseInt(in.next());
Array[] arrays = new Array[N];
for (int i = 0; i < N; ++i) {
String n = in.next();
int b = Integer.parseInt(in.next());
int s = Integer.parseInt(in.next());
int d = Integer.parseInt(in.next());
int[] l = new int[d];
int[] u = new int[d];
for (int j = 0; j < d; ++j) {
l[j] = Integer.parseInt(in.next());
u[j] = Integer.parseInt(in.next());
}
arrays[i] = new Array(n, b, s, d, l, u);
}
for (int i = 0; i < R; ++i) {
String name = in.next();
int ind = 0;
for (int j = 0; j < N; ++j) {
if (arrays[j].name.equals(name)) {
ind = j;
break;
}
}
int D = arrays[ind].D;
int[] index = new int[D];
int[] C = new int[D + 1];
int ref = 0;
for (int j = 0; j < D; ++j)
index[j] = Integer.parseInt(in.next());
C[D] = arrays[ind].size;
for (int d = D - 1; d > 0; --d)
C[d] = C[d + 1] * (arrays[ind].upper[d] -
arrays[ind].lower[d] + 1);
C[0] = arrays[ind].base;
for (int d = 1; d < D + 1; ++d)
C[0] -= C[d] * arrays[ind].lower[d - 1];
ref = C[0];
for (int d = 1; d < D + 1; ++d)
ref += C[d] * index[d - 1];
System.out.print(name + "[");
for (int d = 0; d < D; ++d) {
System.out.print(index[d]);
if (d < D - 1) System.out.print(", ");
}
System.out.println("] = " + ref);
}
}
}