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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | #include <stdio.h> #include <string.h> #include <math.h> #include <queue> #include <utility> using namespace std; int topni[5][10]; void change(int top, int mov) { if (mov == -1) { int first = topni[top][1]; for (int i = 1; i <= 7; i++) { topni[top][i] = topni[top][i + 1]; } topni[top][8] = first; } else { int end = topni[top][8]; for (int i = 7; i >= 1; i--) { topni[top][i+1] = topni[top][i]; } topni[top][1] = end; } } int dx[2] = { -1,1 }; void bfs(int a, int b, int* match) { int chk[5] = { 0 }; chk[a] = 1; change(a, b); queue<pair<int, int>> q; q.push(make_pair(a, b)); while (!q.empty()) { int top = q.front().first; int move = q.front().second; chk[top] = 1; q.pop(); for (int i = 0; i < 2; i++) { int topX = top + dx[i]; if (topX <= 0 || topX > 4) continue; if (chk[topX] == 1) continue; int idx = (topX < top ? topX : top); if (match[idx] == 1) { q.push(make_pair(topX, -move)); change(topX, -move); } } } } int score() { int rst = 0; for (int i = 1; i <= 4; i++) { rst += (topni[i][1] * pow(2, i - 1)); } return rst; } void rolling(int a, int b) { int right[5] = { 0 }, left[5] = {0}; for (int i = 1; i <= 4; i++) { right[i] = topni[i][3]; left[i] = topni[i][7]; } int match[4] = { 0 }; int rst = 0; for (int i = 1; i <= 3; i++) { if (right[i] != left[i + 1]) { match[i] = 1; } } bfs(a, b, match); } int main() { int t; scanf("%d", &t); for (int l = 1; l <= t; l++) { int k; scanf("%d", &k); memset(topni, -1, sizeof(topni)); for (int i = 1; i <= 4; i++) { for (int j = 1; j <= 8; j++) { scanf("%d", &topni[i][j]); } } int sum = 0; for (int i = 0; i < k; i++) { int a, b; scanf("%d %d", &a, &b); rolling(a, b); } ; printf("#%d %d\n", l, score()); } } | cs |
삼성 모의 역량테스트를 쳤다
가장 쉬운 문제가 이정도 수준인게 좀 ㅎㄷㄷ하다
생각하는 과정은 그리 어렵지 않았지만, 중간에 디버깅 하는 데에서 시간을 많이 잡아먹었다.
중간에 BFS 를 섞어서 사용했던 것이 좀 어려웠다.
'삼성 코팅테스트 준비 > 모의 역량 테스트 문제' 카테고리의 다른 글
5658 보물상자 비밀번호 (0) | 2020.03.02 |
---|---|
5656 벽돌깨기 (0) | 2020.03.02 |
5644 무선충전 (0) | 2020.03.02 |
4008 숫자만들기 (0) | 2020.01.16 |
1952 수영장 (0) | 2020.01.16 |