일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- append
- 백준 2589번 보물섬 G5
- 프로그래머스
- 스프링 on-profile
- Stack
- replace()
- hash
- 백준 2660번 회장뽑기 G5
- HashSet
- 백준 1967번 트리의 지름 G4 자바
- 서브모듈 yml
- 백준 2206번 벽 부수고 이동하기 G3
- dp
- 백준 1240번 노드사이의 거리
- Java
- 전위 중위 후위
- StringTokenizer
- 백준 1600번 말이 되고픈 원숭이
- StringBuilder
- 백준 11725번 트리의 부모 찾기
- HashMap
- 백준 8979번 올림픽 S5 자바
- toUpperCase
- 프로그래머스 자바
- 프로그래머스 java
- 코틀린기초
- kotlin
- 포인트 컷
- 스프링 다중프로필
- map
Archives
- Today
- Total
말하는 컴공감자의 텃밭
백준 3085번 사탕 게임 S2 - 브루트포스 본문
728x90
위치를 바꿔서 연속적인 색의 사탕을 먹는 게임이다.
모든 경우를 따져야한다 판단했고 브루트포스로 풀어봤다
가로와 세로 바꾸는 모든 경우의 수를 전부 확인해서 가장 긴 크기를 구했다.
아무것도 바꾸지 않아야 큰 경우도 존재했기에 추가했다.
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 | import java.util.*; public class Main { // 백준 11403번 경로 찾기 S1 public static int N, answer; public static char[][] candy; public static void main(String[] args) { Scanner sc = new Scanner(System.in); N = sc.nextInt(); candy = new char[N][N]; answer = 0; for (int i = 0; i < N; i++) { String s = sc.next(); for (int j = 0; j < N; j++) { candy[i][j] = s.charAt(j); } } find(); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i < N - 1 && candy[i][j] != candy[i + 1][j]) { char tmp = candy[i][j]; candy[i][j] = candy[i + 1][j]; candy[i + 1][j] = tmp; find(); candy[i + 1][j] = candy[i][j]; candy[i][j] = tmp; } if (j < N - 1 && candy[i][j] != candy[i][j + 1]) { char tmp = candy[i][j]; candy[i][j] = candy[i][j + 1]; candy[i][j + 1] = tmp; find(); candy[i][j + 1] = candy[i][j]; candy[i][j] = tmp; } } } System.out.println(answer); } public static void find() { int cnt = 1; for (int i = 0; i < N; i++) { cnt = 1; for (int j = 0; j < N - 1; j++) { if (candy[i][j] == candy[i][j + 1]) { cnt++; answer = Math.max(answer, cnt); } else { cnt = 1; } } } cnt = 1; for (int i = 0; i < N ; i++) { cnt = 1; for (int j = 0; j < N-1; j++) { if (candy[j][i] == candy[j + 1][i]) { cnt++; answer = Math.max(answer, cnt); } else { cnt = 1; } } } } } | cs |
728x90
'알고리즘 > Backjoon - Java' 카테고리의 다른 글
백준 1181번 단어정렬 S5 - Comparable 인터페이스 (1) | 2024.01.03 |
---|---|
백준 12865번 평범한 배낭 G5 - DP (0) | 2023.12.19 |
백준 2579번 계단 오르기 S3 - DP (0) | 2023.12.12 |
백준 2636번 치즈 G4 - BFS (0) | 2023.12.03 |
백준 7579번 토마토 G5 - BFS (0) | 2023.11.18 |
Comments