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
- 운동기록
- SWEA
- 건강
- 문제해결
- MySQL
- math
- BOJ
- 러닝일지
- oracle
- COS PRO
- 코테
- 이분탐색
- greedy
- binary search
- DP
- Java
- 알고리즘
- db
- 투포인터
- dfs
- 문자열
- 자바
- 시뮬레이션
- SQL
- BFS
- 백준
- 프로그래머스
- 코딩테스트
- 문제풀이
- priorityqueue
Archives
- Today
- Total
슈콩
[BOJ] 백준 5373 큐빙 본문
[문제]
https://www.acmicpc.net/problem/5373
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
static Map<Character,Integer> faceIdxMap = new HashMap<>();
static Map<Integer,Character> faceColorMap = new HashMap<>();
static Face[] cube;
static int[][][] edgeInfo = {
{{2,0,2},{2,0,1},{2,0,0},{4,2,2},{4,1,2},{4,0,2},{3,2,0},{3,2,1},{3,2,2},{5,0,0},{5,1,0},{5,2,0}},
{{3,0,2},{3,0,1},{3,0,0},{4,0,0},{4,1,0},{4,2,0},{2,2,0},{2,2,1},{2,2,2},{5,2,2},{5,1,2},{5,0,2}},
{{1,0,2},{1,0,1},{1,0,0},{4,2,0},{4,2,1},{4,2,2},{0,2,0},{0,2,1},{0,2,2},{5,2,0},{5,2,1},{5,2,2}},
{{0,0,2},{0,0,1},{0,0,0},{4,0,2},{4,0,1},{4,0,0},{1,2,0},{1,2,1},{1,2,2},{5,0,2},{5,0,1},{5,0,0}},
{{2,0,0},{2,1,0},{2,2,0},{1,0,0},{1,1,0},{1,2,0},{3,0,0},{3,1,0},{3,2,0},{0,0,0},{0,1,0},{0,2,0}},
{{2,2,2},{2,1,2},{2,0,2},{0,2,2},{0,1,2},{0,0,2},{3,2,2},{3,1,2},{3,0,2},{1,2,2},{1,1,2},{1,0,2}}
};
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
mapping();
int T = Integer.parseInt(br.readLine());
for(int tc=0;tc<T;tc++) {
makeCube();
int n = Integer.parseInt(br.readLine());
st = new StringTokenizer(br.readLine());
for(int i=0;i<n;i++) {
String order = st.nextToken();
if(order.charAt(1)=='+')
cube[faceIdxMap.get(order.charAt(0))].clockWise();
else
cube[faceIdxMap.get(order.charAt(0))].counterClockWise();
}
for(int i=0;i<3;i++) {
for(int j=0;j<3;j++) {
System.out.print(cube[0].color[i][j]);
}
System.out.println();
}
}
}
static class Face{
char[][] color;
int face;
Face(char c,int face){
color = new char[3][3];
for(int i=0;i<3;i++) {
for(int j=0;j<3;j++) {
color[i][j] = c;
}
}
this.face = face;
}
void clockWise(){
char[][] copy = new char[3][3];
for(int i=0;i<3;i++) {
for(int j=0;j<3;j++) {
copy[i][j] = color[2-j][i];
}
}
color = copy;
char[] temp = new char[3];
for(int i=0;i<3;i++) {
temp[i] = cube[edgeInfo[face][i+9][0]].color[edgeInfo[face][i+9][1]][edgeInfo[face][i+9][2]];
}
for(int i=8;i>=0;i--) {
cube[edgeInfo[face][i+3][0]].change(edgeInfo[face][i+3][1],edgeInfo[face][i+3][2],
cube[edgeInfo[face][i][0]].color[edgeInfo[face][i][1]][edgeInfo[face][i][2]]);
}
for(int i=0;i<3;i++) {
cube[edgeInfo[face][i][0]].change(edgeInfo[face][i][1], edgeInfo[face][i][2], temp[i]);
}
}
void counterClockWise() {
char[][] copy = new char[3][3];
for(int i=0;i<3;i++) {
for(int j=0;j<3;j++) {
copy[i][j] = color[j][2-i];
}
}
color = copy;
char[] temp = new char[3];
for(int i=0;i<3;i++) {
temp[i] = cube[edgeInfo[face][i][0]].color[edgeInfo[face][i][1]][edgeInfo[face][i][2]];
}
for(int i=0;i<9;i++) {
cube[edgeInfo[face][i][0]].change(edgeInfo[face][i][1], edgeInfo[face][i][2],
cube[edgeInfo[face][i+3][0]].color[edgeInfo[face][i+3][1]][edgeInfo[face][i+3][2]]);
}
for(int i=0;i<3;i++) {
cube[edgeInfo[face][i+9][0]].change(edgeInfo[face][i+9][1], edgeInfo[face][i+9][2], temp[i]);
}
}
void change(int row,int col,char c) {
color[row][col] = c;
}
}
private static void mapping() {
faceIdxMap.put('U',0);
faceIdxMap.put('D',1);
faceIdxMap.put('F',2);
faceIdxMap.put('B',3);
faceIdxMap.put('L',4);
faceIdxMap.put('R',5);
faceColorMap.put(0,'w');
faceColorMap.put(1,'y');
faceColorMap.put(2,'r');
faceColorMap.put(3,'o');
faceColorMap.put(4,'g');
faceColorMap.put(5,'b');
}
private static void makeCube() {
cube = new Face[6];
for(int i=0;i<6;i++) {
cube[i] = new Face(faceColorMap.get(i),i);
}
}
}
'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 백준 2751 수 정렬하기 2 (2) | 2025.08.19 |
|---|---|
| [BOJ] 백준 11782 배열 합치기 (0) | 2025.08.19 |
| [BOJ] 백준 4991 로봇청소기 (2) | 2025.08.17 |
| [BOJ] 백준 3190 뱀 (2) | 2025.08.17 |
| [BOJ] 백준 2478 자물쇠 (2) | 2025.08.17 |