Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- java
- algorithm
- 코드스쿼드 마스터즈
- 2021.01.14
- 자바
- 쉽게 배우는 운영체제
- Til
- SWEA
- 2021.01.11
- 2021.01.12
- 백준
- 마스터즈 2주차 회고
- 코드스쿼드
- 잃어버린 괄호
- 2021.01.19
- 2021.01.18
- 2021.01.17
- 2021.01.13
- spring-boot
- 백준 1149
- 박재성
- baekjoon1541
- 백준 9093
- 2021.01.06
- 괄호
- 알고리즘데이
- 2021.01.22
- 2020.01.08
- 알고리즘
- 2021.01.21
Archives
- Today
- Total
Cooper's devlog
사탕 게임:3085번 - JAVA 본문
1. 문제 링크
https://www.acmicpc.net/problem/3085
2. 문제 설명
3. 문제 접근
1. 배열 값을 좌우/상하 변경
2. check(가능한 캔디 길이를 확인)
3. 데이터 원상 복귀
check method 설명
1. 행 탐색 : 좌우 값이 일치 시 -> count++
2. 열 탐색 : 상하 값이 일치 시 -> count++
3. count < ans라면, ans = count
4. 문제 풀이
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
package brute_force;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class candy_game {
static char[][] data;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
data = new char[n][n];
for (int i = 0; i < n; i++)
data[i] = br.readLine().toCharArray();
int ans = 0;
for (int row = 0; row < n; row++) {
for (int col = 0; col < n; col++) {
if(col + 1 < n) {
char char_tmp = data[row][col];
data[row][col] = data[row][col+1];
data[row][col + 1] = char_tmp;
int ans_tmp = check(data);
if(ans < ans_tmp)
ans = ans_tmp;
char_tmp = data[row][col];
data[row][col] = data[row][col + 1];
data[row][col + 1] = char_tmp;
}
if(row + 1 < n) {
char char_tmp = data[row][col];
data[row][col] = data[row+1][col];
data[row + 1][col] = char_tmp;
int ans_tmp = check(data);
if(ans < ans_tmp)
ans = ans_tmp;
char_tmp = data[row][col];
data[row][col] = data[row + 1][col];
data[row + 1][col] = char_tmp;
}
}
}
System.out.println(ans);
}
static int check(char[][] data) {
int n = data.length;
int ans = 1;
int count = 1;
for (int row = 0; row < n; row++) {
count = 1;
for (int col = 1; col < n; col++) {
if(data[row][col] == data[row][col-1]) {
count+= 1;
}else {
count = 1;
}
if(ans < count)
ans = count;
}
}
count = 1;
for (int col = 0; col< n; col++) {
count = 1;
for (int row = 1; row < n; row++) {
if(data[row][col] == data[row - 1][col]) {
count+= 1;
}else {
count = 1;
}
if(ans < count)
ans = count;
}
}
return ans;
}
}
|
<정답 확인>
'Algorithm > Baekjoon' 카테고리의 다른 글
좋은 친구 : 3078번 - JAVA (0) | 2020.10.05 |
---|---|
합이 0인 네 정수:7453 - JAVA (0) | 2020.10.03 |
일곱 난쟁이:2309번 - JAVA (0) | 2020.07.21 |
가장 큰 증가 부분 수열:11055번 - JAVA (0) | 2020.07.21 |
동물원: 1309번 - JAVA (0) | 2020.07.17 |
Comments