๐ŸŒžAlgorithm/๐Ÿ”ฅBaekjoon

[Baekjoon] 6235_Argus

๋ฟŒ์•ผ._. 2025. 12. 16. 12:10
๋ฌธ์ œ(์ถœ์ฒ˜: 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