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
- 문자열
- 건강
- 운동기록
- BOJ
- priorityqueue
- SQL
- math
- binary search
- 코테
- BFS
- DP
- 코딩테스트
- greedy
- 알고리즘
- dfs
- 자바
- 투포인터
- oracle
- 이분탐색
- MySQL
- Java
- COS PRO
- 러닝일지
- 시뮬레이션
- 문제풀이
- db
- 백준
- 프로그래머스
- 문제해결
- SWEA
Archives
- Today
- Total
슈콩
[BOJ] 12100 2024(Easy) 본문




[문제]
https://www.acmicpc.net/problem/12100
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
static int[] dr = {-1,1,0,0};
static int[] dc = {0,0,-1,1};
static int n;
static int[][] copy;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
n = Integer.parseInt(br.readLine());
int[][] map = new int[n][n];
for(int i=0;i<n;i++) {
st = new StringTokenizer(br.readLine());
for(int j=0;j<n;j++) {
map[i][j] = Integer.parseInt(st.nextToken());
}
}
int result = 0;
int total = (int)Math.pow(4, 5);
for(int i=0;i<total;i++) {
copy = new int[n][n];
for(int j=0;j<n;j++) copy[j] = map[j].clone();
int mode = i;
for(int k=0;k<5;k++) {
int dir = mode % 4;
mode /= 4;
rotate(dir);
merge();
}
for(int r=0;r<n;r++) {
for(int c=0;c<n;c++) {
result = Math.max(result, copy[r][c]);
}
}
}
System.out.println(result);
}
private static void rotate(int dir) {
int[][] temp = new int[n][n];
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
if(dir==0) temp[i][j] = copy[i][j];
if(dir==1) temp[i][j] = copy[n-1-j][i];
if(dir==2) temp[i][j] = copy[n-1-i][n-1-j];
if(dir==3) temp[i][j] = copy[j][n-1-i];
}
}
copy = temp;
}
private static void merge() {
int[][] temp = new int[n][n];
for(int i=0;i<n;i++) {
int pos = 0;
for(int j=0;j<n;j++) {
if(copy[i][j]!=0) {
if(temp[i][pos]==0) temp[i][pos] = copy[i][j];
else {
if(temp[i][pos]==copy[i][j]) temp[i][pos++] *= 2;
else temp[i][++pos] = copy[i][j];
}
}
}
}
copy = temp;
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 13458 시험 감독 (0) | 2025.11.30 |
|---|---|
| [BOJ] 3190 뱀 (0) | 2025.11.30 |
| [BOJ] 13460 구슬 탈출 2 (0) | 2025.11.30 |
| [BOJ] 14503 로봇 청소기 (0) | 2025.11.29 |
| [BOJ] 9205 맥주 마시면서 걸어가기 (0) | 2025.11.29 |