๋ฌธ์ (์ถ์ฒ: https://www.acmicpc.net/problem/6235)
< Argus >
๋ฌธ์ ํ์ด
์ฐ์ ์์ ํ๋ฅผ ์ฌ์ฉํ์ฌ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํ๋ ์์๋ฅผ ๊ตฌํ๋ค.
my solution (Java)
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class _6235_ { // Argus
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
String str = "";
PriorityQueue<int[]> queue = new PriorityQueue<>(new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
if (o1[1] == o2[1]) {
return o1[0] - o2[0];
}
return o1[1] - o2[1];
}
});
while (!(str = bf.readLine()).equals("#")) {
st = new StringTokenizer(str);
st.nextToken();
int num = Integer.parseInt(st.nextToken());
int p = Integer.parseInt(st.nextToken());
queue.add(new int[] { num, p, p });
}
int k = Integer.parseInt(bf.readLine());
for (int i = 0; i < k; i++) {
int temp[] = queue.poll();
bw.write(temp[0] + "\n");
queue.add(new int[] { temp[0], temp[1] + temp[2], temp[2] });
}
bw.flush();
}
}
๋ณ์)
str : ์ ๋ ฅ๊ฐ
queue : ์ฐ์ ์์ ํ
num, p : ์ง์์ ID ๋ฒํธ, ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํ๋ ์ฃผ๊ธฐ
k : ์ถ๋ ฅํด์ผ ํ๋ ๊ฐ์
#๊ฐ ์ ๋ ฅ๋ ๋๊น์ง ์ ๋ ฅ๋ฐ์ [์ง์์ ID ๋ฒํธ, ์๊ฐ, ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํ๋ ์ฃผ๊ธฐ]๋ฅผ ์ฐ์ ์์ ํ์ ์ ์ฅํ๋ค. k๋ฅผ ์ ๋ ฅ๋ฐ๋๋ค. k๋งํผ ์ฐ์ ์์ ํ์์ poll ํ์ฌ ๊ฐ์ ์ถ๋ ฅํ๊ณ , ๋ค์ ์ฐ์ ์์ํ์ ์๊ฐ์ ๋ํด ์ ์ฅํ๋ค.

'๐Algorithm > ๐ฅBaekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [Baekjoon] 25101_Robin Hood (0) | 2025.12.18 |
|---|---|
| [Baekjoon] 27589_Streets Ahead (0) | 2025.12.17 |
| [Baekjoon] 5872_Clumsy Cows (0) | 2025.12.15 |
| [Baekjoon] 17047_Titlovi (0) | 2025.12.12 |
| [Baekjoon] 10331_Miscalculation (0) | 2025.12.10 |