Advertisement
hwanil

Untitled

Feb 2nd, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<queue>
  3. #include<memory.h>
  4. using namespace std;
  5.  
  6. int arr[5][8];
  7. int order;
  8. int d[] = { 1,-1 };
  9.  
  10. void calc(int num, int dir) {
  11.     queue<pair<int, int>> q;
  12.     bool check[5] = { 0, };
  13.     q.push({ num, dir });
  14.     check[num] = 1;
  15.    
  16.     while (!q.empty()) {
  17.         pair<int,int>  now = q.front();
  18.         q.pop();
  19.         int temparr[8];
  20.  
  21.         memcpy(temparr, arr[now.first], sizeof(arr[num]));
  22.  
  23.         int forRight = arr[now.first][2];
  24.         int forLeft = arr[now.first][6];
  25.  
  26.         for (int i = 0; i < 8; i++) {
  27.             arr[now.first][(i + now.second + 8) % 8] = temparr[i];
  28.         }
  29.  
  30.         for (int k = 0; k < 2; k++) {
  31.             int next = now.first + d[k];
  32.  
  33.             //오른쪽
  34.             if (next > 0 && next < 5 && !check[next]) {
  35.  
  36.                 //오른쪽
  37.                 if (k == 0) {
  38.                     if (forRight != arr[next][6]) {
  39.                         q.push({ next,-now.second });
  40.                         check[next] = 1;
  41.                     }
  42.                 }
  43.                 //왼쪽 톱니바퀴
  44.                 else {
  45.                     if (forLeft != arr[next][2]) {
  46.                         q.push({ next,-now.second });
  47.                         check[next] = 1;
  48.                     }
  49.                 }
  50.  
  51.             }
  52.         }
  53.     }
  54.    
  55.    
  56. }
  57. int main() {
  58.  
  59.     for (int i = 1; i <= 4; i++) {
  60.         for (int j = 0; j < 8; j++) {
  61.             scanf("%1d", &arr[i][j]);
  62.         }
  63.     }
  64.  
  65.     scanf("%d", &order);
  66.  
  67.     for (int i = 0; i < order; i++) {
  68.         int cog, dir;
  69.         scanf("%d %d", &cog, &dir);
  70.         calc(cog, dir);
  71.        
  72.     }
  73.  
  74.     int ans = 0;
  75.     if (arr[1][0])ans += 1;
  76.     if (arr[2][0])ans += 2;
  77.     if (arr[3][0])ans += 4;
  78.     if (arr[4][0])ans += 8;
  79.     printf("%d\n", ans);
  80.     return 0;
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement