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 | 
                            Tags
                            
                        
                          
                          - 1563
- softeer
- Unreal Engine5
- UE5
- algorithm
- 프로그래머스
- RVO
- 티스토리챌린지
- directx
- const
- IFileDialog
- Frustum
- 백준
- C++
- UnrealEngine4
- baekjoon
- UnrealEngine5
- winapi
- DirectX11
- TObjectPtr
- 언리얼엔진5
- C
- 2294
- 팰린드롬 만들기
- Programmers
- RootMotion
- NRVO
- 오블완
- GeeksForGeeks
- 줄 세우기
                            Archives
                            
                        
                          
                          - Today
- Total
Game Develop
[Algorithm] Baekjoon 14499번 : 주사위 굴리기 본문
https://www.acmicpc.net/problem/14499
14499번: 주사위 굴리기
첫째 줄에 지도의 세로 크기 N, 가로 크기 M (1 ≤ N, M ≤ 20), 주사위를 놓은 곳의 좌표 x, y(0 ≤ x ≤ N-1, 0 ≤ y ≤ M-1), 그리고 명령의 개수 K (1 ≤ K ≤ 1,000)가 주어진다. 둘째 줄부터 N개의 줄에 지
www.acmicpc.net
| 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 | int row, col, curY, curX, opCount; int arr[20][20] = { 0 }; int dice[6] = { 0 }; // 위아래 상하좌우 int dirs[5][2] = { {0,0}, {0,1}, {0,-1}, {-1,0}, {1,0} }; int diceDirs[5][6] = // 동서북남 {      {0,0,0,0,0,0},      {5,4,2,3,0,1}, // 동     {4,5,2,3,1,0}, // 서     {2,3,1,0,4,5}, // 북     {3,2,0,1,4,5}  // 남 }; bool checkInRange(int dir) {     int nextY = curY + dirs[dir][0];     int nextX = curX + dirs[dir][1];     if (nextY < 0 || nextY == row || nextX < 0 || nextX == col) return false;     else     {         curY = nextY;         curX = nextX;         return true;     } } void roll(int op) {     int temp[6] = { dice[0], dice[1], dice[2], dice[3], dice[4], dice[5] };     for (int i = 0; i < 6; ++i)     {         int next = diceDirs[op][i];         dice[next] = temp[i];     }     if (arr[curY][curX] == 0)     {         arr[curY][curX] = dice[1];     }     else     {         dice[1] = arr[curY][curX];         arr[curY][curX] = 0;     } } int main(void) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> row >> col >> curY >> curX >> opCount;     for (int i = 0; i < row; ++i)     {         for (int j = 0; j < col; ++j)         {             cin >> arr[i][j];         }     }     int dir;     vector<int> answers;     for (int i = 0; i < opCount; ++i)     {         cin >> dir;         if (!checkInRange(dir)) continue;         roll(dir);         answers.push_back(dice[0]);     }     for (auto& answer : answers)     {         printf("%d\n", answer);     } } | cs | 
어렵지않게 풀만한 시뮬레이션 문제이다.
주사위를 굴릴때 각 면의 값들이 어떤값들로 바뀌는지만 잘 생각하면 나머지는 아주 쉽다.
'Algorithm > Baekjoon' 카테고리의 다른 글
| [Algorithm] Baekjoon 16398번 : 행성 연결 (1) | 2023.09.27 | 
|---|---|
| [Algorithm] Baekjoon 1722번 : 순열의 순서 (0) | 2023.09.26 | 
| [Algorithm] Baekjoon 15684번 : 사다리 조작 (0) | 2023.09.26 | 
| [Algorithm] Baekjoon 13397번 : 구간 나누기 2 (0) | 2023.09.23 | 
| [Algorithm] Baekjoon 1025번 : 제곱수 찾기 (0) | 2023.09.23 | 
