[BOJ 3085] ์ฌํ๊ฒ์
1. ๋ฌธ์ : Link
CCP
CCT
SCW
์ค์ ์ฐ์ํ๋ ๋ ๊ฐ์ ๊ตํํ์๋ ์ต๋๋ก ์ฐ์ํ ์ ์๋ ๊ฒฝ์ฐ์์์ ์ซ์๋ฅผ return
2. ํ์ด
brute-force๋ฌธ์ ์ด๋ฏ๋ก ๋ชจ๋ ๊ฒฝ์ฐ์ ์๋ฅผ ๊ตฌํ๋ค.
๋จผ์ check ํจ์๋ฅผ ๋ง๋ค์ด ์ฐ์ํ๋ ๊ฐ์ ์ต๋๊ฐ์ ๊ตฌํ๋ค.
checkํจ์์ ๋ฃ๋ ์ธ์๋ ๊ตํ ํ์ ๊ฐ์ ๋ฃ๋๋ค.
3. ์ฝ๋
package baekjoon;
import java.util.Scanner;
public class Main {
static int N;
static String[][] map;
static int answer = 0;
static int maxVal = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
map = new String[N][N];
for (int i = 0; i < N; i++) {
map[i] = sc.next().split("");
}
String temp = "";
int cnt = 0;
String cur = "";
//๊ฐ๋ก
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 1; j++) {
temp = map[i][j];
map[i][j] = map[i][j + 1];
map[i][j + 1] = temp;
for (int a = 0; a < N; a++) {
cnt = 0;
cur = map[a][0];
for (int b = 0; b < N; b++) {
if (cur.equals(map[a][b])) {
cnt++;
maxVal = Math.max(maxVal, cnt);
} else {
cur = map[a][b];
maxVal = Math.max(maxVal, cnt);
cnt = 1;
}
}
}
for (int a = 0; a < N; a++) {
cnt = 0;
cur = map[0][a];
for (int b = 0; b < N; b++) {
if (cur.equals(map[b][a])) {
cnt++;
maxVal = Math.max(maxVal, cnt);
} else {
cur = map[b][a];
maxVal = Math.max(maxVal, cnt);
cnt = 1;
}
}
}
map[i][j + 1] = map[i][j];
map[i][j] = temp;
}
}
//์ธ๋ก
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 1; j++) {
temp = map[j][i];
map[j][i] = map[j + 1][i];
map[j + 1][i] = temp;
for (int a = 0; a < N; a++) {
cnt = 0;
cur = map[a][0];
for (int b = 0; b < N; b++) {
if (cur.equals(map[a][b])) {
cnt++;
maxVal = Math.max(maxVal, cnt);
} else {
cur = map[a][b];
maxVal = Math.max(maxVal, cnt);
cnt = 1;
}
}
}
for (int a = 0; a < N; a++) {
cnt = 0;
cur = map[0][a];
for (int b = 0; b < N; b++) {
if (cur.equals(map[b][a])) {
cnt++;
maxVal = Math.max(maxVal, cnt);
} else {
cur = map[b][a];
maxVal = Math.max(maxVal, cnt);
cnt = 1;
}
}
}
map[j + 1][i] = map[j][i];
map[j][i] = temp;
}
}
System.out.println(maxVal);
}
}
'๐ป Coding Problems Solving > Brute Force' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[BOJ 1992] ์ฟผ๋ํธ๋ฆฌ (0) | 2023.06.26 |
---|---|
[BOJ 16637] ๊ดํธ์ถ๊ฐํ๊ธฐ (0) | 2023.06.22 |
[BOJ 12919] A์ B2 (0) | 2023.06.18 |
[BOJ 2309] ์ผ๊ณฑ ๋์์ด (0) | 2022.06.21 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ์นดํซ (0) | 2022.04.16 |
์ต๊ทผ๋๊ธ