https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWIeV9sKkcoDFAVH
#include <iostream>
#include <vector>
using namespace std;
int map[4][8];
int k;
int num, dir;
//N:0, S:1
//1:시계 -1:반시계
void RotateMap(pair<int,int> v) {
int n = v.first;
int d = v.second;
int tmp[8];
for (int i = 0; i < 8; i++) {
tmp[i] = map[n][i];
}
if (d == 1) { //시계
map[n][0] = tmp[7];
map[n][1] = tmp[0];
map[n][2] = tmp[1];
map[n][3] = tmp[2];
map[n][4] = tmp[3];
map[n][5] = tmp[4];
map[n][6] = tmp[5];
map[n][7] = tmp[6];
}
else if (d == -1) { //반시계
map[n][0] = tmp[1];
map[n][1] = tmp[2];
map[n][2] = tmp[3];
map[n][3] = tmp[4];
map[n][4] = tmp[5];
map[n][5] = tmp[6];
map[n][6] = tmp[7];
map[n][7] = tmp[0];
}
}
int main(void) {
int testcase;
cin >> testcase;
int index = 1;
for (; testcase > 0; testcase--) {
int answer = 0;
cin >> k;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 8; j++) {
cin >> map[i][j];
}
}
for (; k > 0; k--) {
cin >> num >> dir;
num--;
vector<pair<int,int>> turn;
int prev_dir = dir;
for (int i = num-1; i >= 0; i--) {
if (map[i][2] != map[i+1][6]) {
if (prev_dir == 1) prev_dir = -1;
else prev_dir = 1;
turn.push_back({ i,prev_dir });
}
else break;
}
prev_dir = dir;
for (int i = num + 1; i < 4; i++) {
if (map[i-1][2] != map[i][6]) {
if (prev_dir == 1) prev_dir = -1;
else prev_dir = 1;
turn.push_back({ i,prev_dir });
}
else break;
}
RotateMap({ num,dir });
for (int i = 0; i < turn.size(); i++) {
RotateMap(turn[i]);
}
}
if (map[0][0] == 1) answer += 1;
if (map[1][0] == 1) answer += 2;
if (map[2][0] == 1) answer += 4;
if (map[3][0] == 1) answer += 8;
cout << "#" << index << " " << answer << "\n";
index++;
}
}
'백준 알고리즘 > 구현' 카테고리의 다른 글
보물상자 비밀번호 (0) | 2022.04.24 |
---|---|
벽돌 깨기 C++ (0) | 2022.04.24 |
활주로 건설 C++ (0) | 2022.04.23 |
줄기세포 배양 C++ (0) | 2022.04.23 |
로봇 시뮬레이션 C++ (0) | 2022.03.09 |