반응형
https://www.acmicpc.net/problem/14891
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#include<iostream>
#include<algorithm>
#include <vector>
#include<math.h>
using namespace std;
int Gear[5][8];
int K;
pair<int,int> A[100];
void Rotation(int who,int dir){
int tmp;
if(dir == 1){
// right Rotation
tmp = Gear[who][7];
for(int i=7;i>0;--i) Gear[who][i] = Gear[who][i-1];
Gear[who][0] = tmp;
}else{
// left Rotation
tmp = Gear[who][0];
for(int i=0;i<7;++i) Gear[who][i] = Gear[who][i+1];
Gear[who][7] = tmp;
}
}
void Move_Gear(int who,int dir,int rl){
if(who <1||who>4) return;
if(rl == 0){ // base가 왼쪽에 있었다.
if(Gear[who][6] != Gear[who-1][2]){
//서로 극이 다른경우만 회전
Move_Gear(who+1,dir*(-1),0);
Rotation(who,dir);
}
}else{
if(Gear[who][2] != Gear[who+1][6]){
//서로 극이 다른경우만 회전
Move_Gear(who-1,dir*(-1),1);
Rotation(who,dir);
}
}
}
int Solve(){
int ans=0;
for(int i=1;i<=4;++i){
if(Gear[i][0] == 1){
ans += pow(2,i-1);
}
}
return ans;
}
int main(void){
char c;
for(int i=1;i<=4;++i){
for(int j=0;j<8;++j){
cin>>c;
Gear[i][j] = c - '0';
}
}
cin>>K;
for(int k=0;k<K;k++){
cin>>A[k].first>>A[k].second;
}
// right : 2 , reft : 6
for(int k=0;k<K;k++){
int who = A[k].first;
int dir = A[k].second;
//좌
Move_Gear(who-1,dir*(-1),1);
//우
Move_Gear(who+1,dir*(-1),0);
Rotation(who,dir);
}
cout<<Solve();
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
반응형
'ProgramSoliving' 카테고리의 다른 글
백준 : 2869 (0) | 2020.01.12 |
---|---|
백준 : 17779 (0) | 2020.01.12 |
백준 : 14890 (0) | 2020.01.12 |
백준 : 16234 * (0) | 2020.01.11 |
백준 : 9251 (0) | 2020.01.01 |