-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12346.java
58 lines (41 loc) · 1.07 KB
/
12346.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
/*
* UVa 12346: Water Gate Management
*
* Problem Statement: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3768
*/
import java.util.Scanner;
public class Main {
public static int[][] gates;
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
gates = new int[n][2];
for (int i = 0; i < n; i++) {
gates[i][0] = scan.nextInt();
gates[i][1] = scan.nextInt();
}
int m = scan.nextInt();
int v, t;
for (int i = 1; i <= m; i++) {
v = scan.nextInt();
t = scan.nextInt();
int min = Integer.MAX_VALUE;
int tf, tc;
for (int j = 0; j < (1 << n); j++) {
tf = 0;
tc = 0;
for (int k = 0; k < n; k++) {
tf += (1 & (j >> k)) * gates[k][0];
tc += (1 & (j >> k)) * gates[k][1];
}
if (tf * t >= v) {
min = Math.min(min, tc);
}
}
if (min < Integer.MAX_VALUE)
System.out.println("Case " + i + ": " + min);
else
System.out.println("Case " + i + ": IMPOSSIBLE");
}
}
}