Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<queue>
- #include<memory.h>
- using namespace std;
- int arr[5][8];
- int order;
- int d[] = { 1,-1 };
- void calc(int num, int dir) {
- queue<pair<int, int>> q;
- bool check[5] = { 0, };
- q.push({ num, dir });
- check[num] = 1;
- while (!q.empty()) {
- pair<int,int> now = q.front();
- q.pop();
- int temparr[8];
- memcpy(temparr, arr[now.first], sizeof(arr[num]));
- int forRight = arr[now.first][2];
- int forLeft = arr[now.first][6];
- for (int i = 0; i < 8; i++) {
- arr[now.first][(i + now.second + 8) % 8] = temparr[i];
- }
- for (int k = 0; k < 2; k++) {
- int next = now.first + d[k];
- //오른쪽
- if (next > 0 && next < 5 && !check[next]) {
- //오른쪽
- if (k == 0) {
- if (forRight != arr[next][6]) {
- q.push({ next,-now.second });
- check[next] = 1;
- }
- }
- //왼쪽 톱니바퀴
- else {
- if (forLeft != arr[next][2]) {
- q.push({ next,-now.second });
- check[next] = 1;
- }
- }
- }
- }
- }
- }
- int main() {
- for (int i = 1; i <= 4; i++) {
- for (int j = 0; j < 8; j++) {
- scanf("%1d", &arr[i][j]);
- }
- }
- scanf("%d", &order);
- for (int i = 0; i < order; i++) {
- int cog, dir;
- scanf("%d %d", &cog, &dir);
- calc(cog, dir);
- }
- int ans = 0;
- if (arr[1][0])ans += 1;
- if (arr[2][0])ans += 2;
- if (arr[3][0])ans += 4;
- if (arr[4][0])ans += 8;
- printf("%d\n", ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement