๋ฌธ์ (์ถ์ฒ: 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 |