View
λ¬Έμ λ§ν¬:
https://www.acmicpc.net/problem/15953
μμ€ μ½λ:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
/* μ 1ν μ½λ νμ€ν°λ² μ 보 */
int[] rank1Info = {1, 2, 3, 4, 5, 6};
int[] prize1Info = {500, 300, 200, 50, 30, 10};
/* μ 2ν μ½λ νμ€ν°λ² μ 보 */
int[] rank2Info = {1, 2, 4, 8, 16};
int[] prize2Info = {512, 256, 128, 64, 32};
public static void main(String[] args) throws IOException {
Main solution = new Main();
solution.solve();
}
public void solve() {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
// λ±μ κ°μ μ λ릴 νμ
int t = Integer.parseInt(st.nextToken());
for (int i = 0; i < t; i++) {
st = new StringTokenizer(br.readLine());
int rank1 = Integer.valueOf(st.nextToken());
int rank2 = Integer.valueOf(st.nextToken());
int result = calc(rank1, rank1Info, prize1Info)
+ calc(rank2, rank2Info, prize2Info);
bw.append(result + System.lineSeparator()); // '/r/n'κ³Ό κ°μ μν
}
bw.flush();
bw.close();
br.close();
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public int calc(int p, int[] rankInfo, int[] prizeInfo) {
// μ΄ μκΈ
int totPrize = 0;
// μκΈμ λ°μ μ μλ μΈμ
int totPerson = Arrays.stream(rankInfo).sum();
if (p > 0 && p <= totPerson) {
int count = 0;
for (int i = 0; i < rankInfo.length; i++) {
count += rankInfo[i];
if (p <= count) {
totPrize += prizeInfo[i];
return totPrize * 10000;
}
}
}
return totPrize * 10000;
}
}
κ°κ°μ κΈ°λ₯μ νλ ν΄λμ€λ₯Ό λ°λ‘ λ§λ€μ΄μ ꡬννλ €κ³ νλ€.
μ΄νμ νμ€ν°λ² μ λ³΄κ° λ μΆκ°λμ΄λ μ½κ² κ³μ°ν μ μκ²λ μ 보λ₯Ό λ΄λ κ°μ²΄κ° μμΌλ©΄ μ’μ κ² κ°λ€.
'κ°λ° > Algorithm' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[νλ‘κ·Έλλ¨Έμ€] 42586λ²: κΈ°λ₯ κ°λ° (JAVA) (0) | 2022.06.20 |
---|---|
[νλ‘κ·Έλλ¨Έμ€] 17677λ²: λ΄μ€ ν΄λ¬μ€ν°λ§ (JAVA) (0) | 2022.06.20 |
[λ°±μ€/BOJ] 1406λ²: μλν° (JAVA) (0) | 2022.06.08 |
[νλ‘κ·Έλλ¨Έμ€] 92334λ²: μ κ³ κ²°κ³Ό λ°κΈ° (JAVA) (0) | 2022.06.06 |
reply