๐ŸŒžAlgorithm/๐Ÿ”ฅBaekjoon

[Baekjoon] 11265_๋๋‚˜์ง€ ์•Š๋Š” ํŒŒํ‹ฐ

๋ฟŒ์•ผ._. 2023. 12. 22. 22:16

Gold V

๋ฌธ์ œ(์ถœ์ฒ˜: https://www.acmicpc.net/problem/11265)

< ๋๋‚˜์ง€ ์•Š๋Š” ํŒŒํ‹ฐ >

 

๋ฌธ์ œ ํ’€์ด 

 

ํ”Œ๋กœ์ด๋“œ ์›Œ์…œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•ด์„œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ–ˆ๋‹ค.

 

 

 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.StringTokenizer;

public class _11265_ { // ๋๋‚˜์ง€ ์•Š๋Š” ํŒŒํ‹ฐ

	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 = new StringTokenizer(bf.readLine());

		int n = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());

		int arr[][] = new int[n + 1][n + 1];
		for (int i = 1; i <= n; i++) {
			st = new StringTokenizer(bf.readLine());
			for (int j = 1; j <= n; j++) {
				arr[i][j] = Integer.parseInt(st.nextToken());
			}
		}

		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				for (int k = 1; k <= n; k++) {
					arr[j][k] = Math.min(arr[j][k], arr[j][i] + arr[i][k]);
				}
			}
		}

		for (int i = 0; i < m; i++) {
			st = new StringTokenizer(bf.readLine());
			int start = Integer.parseInt(st.nextToken());
			int end = Integer.parseInt(st.nextToken());
			int time = Integer.parseInt(st.nextToken());

			if (arr[start][end] <= time) {
				bw.write("Enjoy other party\n");
			} else {
				bw.write("Stay here\n");
			}
		}
		bw.flush();
	}
}
๋ณ€์ˆ˜)
n, m : ํŒŒํ‹ฐ์žฅ์˜ ํฌ๊ธฐ, ์„œ๋น„์Šค๋ฅผ ์š”์ฒญํ•œ ์†๋‹˜์˜ ์ˆ˜
arr : ํŒŒํ‹ฐ์žฅ์—์„œ ๋‹ค๋ฅธ ํŒŒํ‹ฐ์žฅ๊นŒ์ง€ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„
start, end, time : ์†๋‹˜์ด ์œ„์น˜ํ•œ ํŒŒํ‹ฐ์žฅ์˜ ๋ฒˆํ˜ธ, ๋‹ค์Œ ํŒŒํ‹ฐ๊ฐ€ ์—ด๋ฆฌ๋Š” ํŒŒํ‹ฐ์žฅ์˜ ๋ฒˆํ˜ธ, ํŒŒํ‹ฐ๊ฐ€ ์—ด๋ฆฌ๋Š” ๋ฐ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„

 

ํŒŒํ‹ฐ์žฅ์—์„œ ํŒŒํ‹ฐ์žฅ์œผ๋กœ ์—ฐ๊ฒฐ๋œ ๋„๋กœ๋ฅผ ํ†ตํ•ด ์ด๋™ํ•˜๋Š” ์‹œ๊ฐ„์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. ํ”Œ๋กœ์ด๋“œ ์›Œ์…œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•ด ํŒŒํ‹ฐ์žฅ์—์„œ ๋‹ค๋ฅธ ํŒŒํ‹ฐ์žฅ์œผ๋กœ ์ด๋™ํ•  ๋•Œ ๊ฑธ๋ฆฌ๋Š” ์ตœ์†Œ ์‹œ๊ฐ„์„ ๊ตฌํ•œ๋‹ค. 

 

์†๋‹˜์ด ์œ„์น˜ํ•œ ํŒŒํ‹ฐ์žฅ์˜ ๋ฒˆํ˜ธ์—์„œ ๋‹ค์Œ ํŒŒํ‹ฐ๊ฐ€ ์—ด๋ฆฌ๋Š” ํŒŒํ‹ฐ์žฅ์˜ ๋ฒˆํ˜ธ๋กœ ์ด๋™ํ•  ๋•Œ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„์ด ๋‹ค์Œ ํŒŒํ‹ฐ๊ฐ€ ์—ด๋ฆฌ๋Š” ๋ฐ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค๋ฉด "Enjoy other party"๋ฅผ ์ถœ๋ ฅํ•˜๊ณ  ๊ทธ๋ ‡์ง€ ์•Š๋‹ค๋ฉด "Stay here"๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.



 

'๐ŸŒžAlgorithm > ๐Ÿ”ฅBaekjoon' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Baekjoon] 28432_๋๋ง์ž‡๊ธฐ  (0) 2023.12.26
[Baekjoon] 10282_ํ•ดํ‚น  (0) 2023.12.25
[Baekjoon] 5972_ํƒ๋ฐฐ ๋ฐฐ์†ก  (0) 2023.12.21
[Baekjoon] 2660_ํšŒ์žฅ๋ฝ‘๊ธฐ  (0) 2023.12.20
[Baekjoon] 1092_๋ฐฐ  (0) 2023.12.19