티스토리 뷰

출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do


#include <iostream>

#include <algorithm>
using namespace std;
 
int i, j, K, result;
int a[4][8]; int ro[40][2]; int check[4][2];
 
void rotation(int i, int wh)
{
    int tmp;
    if (wh == 1)
    {
        tmp = a[i][1]; a[i][1] = a[i][0];
        for (j = 2;j < 8;j++)
        {
            swap(a[i][j], tmp);
        }
        a[i][0] = tmp;
    }
    else if (wh == -1)
    {
        tmp = a[i][6]; a[i][6] = a[i][7];
        for (j = 5;j >= 0;j--)
        {
            swap(a[i][j], tmp);
        }
        a[i][7] = tmp;
    }
}
 
void move(int now)
{
    if (now + 1 < 4 && check[now + 1][0] != 1 && a[now][2] != a[now + 1][6])
    {
        check[now + 1][0] = 1; check[now + 1][1] = check[now][1] * -1; move(now + 1);
    }
    if (now - 1 >= 0 && check[now - 1][0] != 1 && a[now][6] != a[now - 1][2])
    {
        check[now - 1][0] = 1; check[now - 1][1] = check[now][1] * -1; move(now - 1);
    }
}
 
void cal()
{
    int count = 0;
    while (K--)
    {
        for (i = 0;i < 4;i++) for(j=0;j<2;j++) check[i][j] = 0;
         
        int now = ro[count][0] - 1;
        check[now][0] = 1; check[now][1] = ro[count][1];
 
        move(now);
 
        for (i = 0;i < 4;i++)
        {
            if (check[i][0] == 1) rotation(i, check[i][1]);
        }
 
        count++;
    }
 
    for (i = 0; i < 4; i++) if (a[i][0] == 1) result += (int)pow(2, (double)i);
}
 
int main()
{
    int T; int t = 1;
    cin >> T;
    while (T--)
    {
        cin >> K; result = 0;
        for (i = 0; i < 4; i++) for (j = 0;j < 8;j++) cin >> a[i][j];
        for (i = 0;i < K;i++) cin >> ro[i][0] >> ro[i][1];
 
        cal();
         
        cout << "#" << t << " " << result << endl;
 
        t++;
    }
 
    return 0;
}


'알고리즘 > SWEA' 카테고리의 다른 글

[SWEA 1949] 등산로 조정  (0) 2018.07.23
[SWEA 4014] 활주로 건설  (0) 2018.07.23
[SWEA 3752] 가능한 시험 점수  (0) 2018.07.23
[SWEA 1952] 수영장  (0) 2018.07.23
[SWEA 1767] 프로세서 연결하기  (0) 2018.07.23
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/12   »
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
글 보관함