[๋ฐฑ์ค] ๐ฅ 1913 ๋ฌํฝ์ด
๐ ๋์ด๋
๐ฅ Silver 3
๐ ๋ฌธ์
https://www.acmicpc.net/problem/1913
๐ ํ์ด
์ด ๋ฌํฝ์ด ๋ฌธ์ ๋ ๋ด๊ฐ ๋ฐฑ์ค์ ์ฒ์ํ๋ ํ๋ ๋ฌธ์ ์๋ค.
๋์ ํ ๊ตฌํ์ ํ๋ ๋ฐฉ๋ฒ์ ๋ชจ๋ฅด๊ฒ ์ด์ ๋ฏธ๋ค๋๊ณ , ๋์ค์ ํ๊ธฐ๋ก ํ ๋ฌธ์ ์๋ค.
์ฒ์์ ๊ตฌ์ํ ๋ฐฉ๋ฒ์ ์ค์๋ถํฐ ์์ํ ํ, ํผ์ ธ๋๊ฐ๋ ๋ฐฉ์์ด์๋ค.
๊ทธ ์ด๋ ํ ๋ฒ์น๋ ์ฐพ์๋ด์ง ๋ชปํ๊ณ ๋จ์ํ ์๋ก๊ฐ๋ค๊ฐ ์๋๋ก๊ฐ๋ค๊ฐ ํ๋ ๋ฐฉ์์ผ๋ก ๊ตฌํํ๋ ค๊ณ ํ๋๋ฐ, ๊ตฌํ์ด ๋ถ๊ฐ๋ฅํ๋ค.
์ดํ ๋ค์ ์ด ๋ฌธ์ ๋ฅผ ๋ดค์๋, ๊ทธ๋ฆผ์ ๊ทธ๋ ค๋ณด๋ ํ๊ฐ์ง ํน์ง์ ๋ฐ๊ฒฌํ ์ ์์๋ค.
๋ฐ๋ก ๋ค์ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ด 4/2์์ผ๋ก ๋ฐ๊นฅ์ ๋๋ฅด๋ ๊ฒ์ด์๋ค.
๊ทธ๋์ ๋ค์๊ณผ ๊ฐ์ด ์ฝ๋๋ฅผ ์์ฑํ์๋ค.
๐ Code
package Implements;
import java.io.*;
import java.util.StringJoiner;
public class N1913 {
static int N;
static int total;
static int target;
static int[][] snail;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
total = N * N;
target = Integer.parseInt(br.readLine());
snail = new int[N][N];
TotalMake();
FindSnail();
}
static void FindSnail() {
int x = 0;
int y = 0;
StringJoiner sj;
for (int i = 0; i < N; i++) {
sj = new StringJoiner(" ");
for (int j = 0; j < N; j++) {
sj.add(Integer.toString(snail[i][j]));
if (snail[i][j] == target) {
x = i + 1;
y = j + 1;
}
}
System.out.println(sj);
}
System.out.println(x + " " + y);
}
static void TotalMake() {
for (int i = 0; i < N / 2; i++) {
MakeSnail(i, N - i - 1);
}
snail[N / 2][N / 2] = total;
}
static void MakeSnail(int min, int max) {
for (int i = min; i <= max - 1; i++) {
snail[i][min] = total--;
}
for (int i = min; i <= max - 1; i++) {
snail[max][i] = total--;
}
for (int i = max; i >= min + 1; i--) {
snail[i][max] = total--;
}
for (int i = max; i >= min + 1; i--) {
snail[min][i] = total--;
}
}
}
package (์ด๋ฆ); ๋ฅผ ๋๊ณ , class ์ด๋ฆ์ Main
์ผ๋ก ๋ณ๊ฒฝํ๋ฉด ๋๋ค.
๊ฐ์ธ ๊ณต๋ถ ๊ธฐ๋ก์ฉ ๋ธ๋ก๊ทธ์
๋๋ค.
ํ๋ฆฌ๊ฑฐ๋ ์ค๋ฅ๊ฐ ์์ ๊ฒฝ์ฐ ์ ๋ณดํด์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค.๐