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 | 29 | 30 |
31 |
Tags
- 백준 17425
- Math.ceil()
- 백준 15661
- Arrays
- 프로그래머스 숫자의 표현 java
- time complexity
- 알고리즘
- 프로그래머스 도둑질 java
- 네트워크
- 프로그래머스 네트워크 java
- 프로그래머스 옹알이 java
- 코딩테스트
- 0으로 채우기
- 백준 4375
- 백준 14391
- mysql
- 백준 18290
- Algorithm
- java
- java 반올림
- 백준 11723
- 자바
- 백준 16927
- java 올림
- java 내림
- Math.floor()
- 프로그래머스 연속된 수의 합 java
- sort
- 백준 16935
- Codility
Archives
- Today
- Total
취미처럼
[백준] 3085번 사탕 게임 본문
https://www.acmicpc.net/problem/3085
3085번: 사탕 게임
예제 3의 경우 4번 행의 Y와 C를 바꾸면 사탕 네 개를 먹을 수 있다.
www.acmicpc.net
열 교환 진행 후 가로 세로 확인 > 이어진 max 값 체크 후 다시 원상복구
행 교환 진행 후 가로 세로 확인 > 이어진 max 값 체크 후 다시 원상복구
가장 마지막 열과 행은 교환이 불가하므로 입력값 N에서 1을 뺀다.
import java.util.*;
import java.io.*;
public class Main {
public static char[][] arr;
public static int N;
public static int max = 0;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
arr = new char[N][N];
String line = "";
for(int i = 0; i < N; i++) {
line = br.readLine();
for(int j = 0; j < N; j++) {
arr[i][j] = line.charAt(j);
}
}
// 행 바꾸면서 확인
for(int i = 0; i < N; i++) {
for(int j = 0; j < N - 1; j++ ) {
char temp = arr[j][i];
arr[j][i] = arr[j+1][i];
arr[j+1][i] = temp;
max = Math.max(check(), max);
temp = arr[j][i];
arr[j][i] = arr[j+1][i];
arr[j+1][i] = temp;
}
}
// 열 바꾸면서 확인
for(int i = 0; i < N; i++) {
for(int j = 0; j < N - 1; j++) {
char temp = arr[i][j];
arr[i][j] = arr[i][j+1];
arr[i][j+1] = temp;
max = Math.max(check(), max);
temp = arr[i][j];
arr[i][j] = arr[i][j+1];
arr[i][j+1] = temp;
}
}
System.out.println(max);
}
private static int check() {
// 가로 방향 확인
for(int y = 0; y < N; y++ ) {
int count = 1;
for(int x = 0; x < N - 1; x++) {
if(arr[y][x] == arr[y][x+1]) {
count++;
} else {
count = 1;
}
max = Math.max(max, count);
}
}
// 세로 방향 확인
for(int x = 0; x < N; x++) {
int count = 1;
for(int y = 0; y < N - 1; y++) {
if(arr[y][x] == arr[y+1][x]) {
count++;
} else {
count = 1;
}
max = Math.max(max, count);
}
}
return max;
}
}
'Algorithm > 백준' 카테고리의 다른 글
[백준] 1107번 리모컨 (0) | 2021.03.02 |
---|---|
[백준] 1476번 날짜 계산 (0) | 2021.02.25 |
[백준] 2309번 일곱 난쟁이 (0) | 2021.02.25 |
[백준] 6588번 골드바흐의 추측 (0) | 2021.02.25 |
[백준] 1929번 소수 구하기 (0) | 2021.02.25 |
Comments