-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBaekjoon15953.java
73 lines (56 loc) · 1.8 KB
/
Baekjoon15953.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
package Algorithms;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
/**
* https://www.acmicpc.net/problem/15953
* 백준 15953번 상금 헌
*/
public class Baekjoon15953 {
private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static int[] lastYearMoney = new int[101];
private static int[] thisYearMoney = new int[65];
public static void main(String[] args) throws IOException {
int testCase = Integer.parseInt(br.readLine());
initMoney();
for (int i = 0; i < testCase; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
System.out.println(solution(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())));
}
}
private static void initMoney() {
initLastYearMoney();
initThisYearMoney();
}
private static int solution(int a, int b) {
int lastYear = lastYearMoney[a];
int thisYear = thisYearMoney[b];
return (lastYear + thisYear) * 10000;
}
private static void initLastYearMoney() {
int[] money = { 500, 300, 200, 50, 30, 10};
int temp = 1;
int lastIndex = 1;
for (int i = 0; i < money.length; i++) {
for (int j = 0; j < temp; j++) {
lastYearMoney[lastIndex++] = money[i];
}
temp++;
}
}
private static void initThisYearMoney() {
int money = 512;
int temp = 1;
int i = 1;
while (i < 32) {
for (int j = 0; j < temp; j++) {
thisYearMoney[i + j] = money;
}
money /= 2;
i += temp;
temp *= 2;
}
}
}