티스토리 뷰
구현
- 조건들을 놓치면 시간 끌리는 문제...
- 주사위가 움직이면 면이 어떻게 변하는지 파악하는게 중요!!!
소스 코드
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 | #include <iostream> #define FOR(i,a,b) for(int i = a; i < b; i++) #define endl '\n' #define sws ios::sync_with_stdio(false), cin.tie(NULL) using namespace std; int dice[4][3]; int map[21][21]; int main() { sws; int N, M, x, y, K, cmd; cin >> N >> M >> x >> y >> K; FOR(i, 0, N) FOR(j, 0, M) cin >> map[i][j]; while (K--) { cin >> cmd; if (cmd == 1) { //오른쪽 if (y + 1 == M) continue; y++; int tmp = dice[3][1]; dice[3][1] = dice[1][2]; dice[1][2] = dice[1][1]; dice[1][1] = dice[1][0]; dice[1][0] = tmp; if(map[x][y] != 0) dice[3][1] = map[x][y], map[x][y] = 0; else map[x][y] = dice[3][1]; cout << dice[1][1] << endl; } else if (cmd == 2) { //왼쪽 if (y == 0) continue; y--; int tmp = dice[3][1]; dice[3][1] = dice[1][0]; dice[1][0] = dice[1][1]; dice[1][1] = dice[1][2]; dice[1][2] = tmp; if(map[x][y] != 0) dice[3][1] = map[x][y], map[x][y] = 0; else map[x][y] = dice[3][1]; cout << dice[1][1] << endl; } else if (cmd == 3) { //위쪽 if (x == 0) continue; x--; int tmp = dice[0][1]; dice[0][1] = dice[1][1]; dice[1][1] = dice[2][1]; dice[2][1] = dice[3][1]; dice[3][1] = tmp; if(map[x][y] != 0) dice[3][1] = map[x][y], map[x][y] = 0; else map[x][y] = dice[3][1]; cout << dice[1][1] << endl; } else { if (x + 1 == N) continue; x++; int tmp = dice[3][1]; dice[3][1] = dice[2][1]; dice[2][1] = dice[1][1]; dice[1][1] = dice[0][1]; dice[0][1] = tmp; if (map[x][y] != 0) dice[3][1] = map[x][y], map[x][y] = 0; else map[x][y] = dice[3][1]; cout << dice[1][1] << endl; } } } | cs |
반응형
'백준 온라인 저지' 카테고리의 다른 글
190326 BOJ 1354번 무한 수열 2 (0) | 2019.03.26 |
---|---|
190326 BOJ 1351번 무한 수열 (0) | 2019.03.26 |
190205 BOJ 2094번 강수량 (0) | 2019.03.17 |
190316 BOJ 1992번 쿼드트리 (0) | 2019.03.16 |
190316 BOJ 1018번 체스판 다시 칠하기 (0) | 2019.03.16 |
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 운영체제
- Fast Campus
- 올인원 패키지
- 프로그래밍 온라인 강의
- 패스트캠퍼스
- 자료구조
- c언어
- 컴퓨터공학
- 개발자 취업
- #패스트캠퍼스 #프로그래밍대학생서포터즈 #올인원패키지 #컴퓨터공학 #성공하는프로그래밍공부법
- 코딩 면접
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함