st[4][8]을 입력받고


if(st[x][2]^st[x+1][6]) 면 상태 저장 후 입력받은 위치의 톱니를 돌리면 된다.


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
#include <stdio.h>
#include <cstring>
#include <algorithm>
using namespace std;
 
int k, st[4][8], ro[4][4], a, b;
 
void rotate(int x, int y) {
    if (y == 1) {
        int temp = st[x][7];
        for (int i = 7; i > 0; i--) st[x][i] = st[x][i - 1];
        st[x][0= temp;
    }
    else if (y == -1) {
        int temp = st[x][0];
        for (int i = 0; i < 7; i++) st[x][i] = st[x][i + 1];
        st[x][7= temp;
    }
}
 
void solve(int x, int y) {
    rotate(x, y);
    if (x + 1 < 4 && ro[x][x + 1]) {
        ro[x][x + 1= ro[x + 1][x] = 0;
        solve(x + 1-y);
    }
    if (x > 0 && ro[x][x - 1]) {
        ro[x][x - 1= ro[x - 1][x] = 0;
        solve(x - 1-y);
    }
}
 
int main() {
    for (int i = 0; i < 4; i++for (int j = 0; j < 8; j++)
        scanf(" %1d"&st[i][j]);
    scanf("%d"&k);
    while (k--) {
        for (int i = 0; i < 3; i++) {
            if (st[i][2] ^ st[i + 1][6])
                ro[i][i + 1= ro[i + 1][i] = 1;
            else
                ro[i][i + 1= ro[i + 1][i] = 0;
        }
        scanf("%d%d"&a, &b);
        a--;
        solve(a, b);
    }
    printf("%d\n", st[0][0+ st[1][0* 2 + st[2][0* 4 + st[3][0* 8);
    return 0;
}
cs


'BOJ' 카테고리의 다른 글

1898 이전 수열은 어떤 수열일까  (0) 2017.10.30
13226 Divisors Again  (0) 2017.10.30
14890 경사로  (0) 2017.10.26
14889 스타트와 링크  (0) 2017.10.26
14888 연산자 끼워넣기  (0) 2017.10.26

+ Recent posts