-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14499.cpp
128 lines (114 loc) · 2.42 KB
/
14499.cpp
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <string>
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <climits>
#include <set>
#define p(a, b) make_pair(a, b)
#define SWAP(a, b, type) do { \
type temp; \
temp = a; \
a = b; \
b = temp; \
} while (0)
#define INF 1000000000
#define endl '\n'
#define ll long long
using namespace std;
typedef struct _dice{
int num[6];
int cur_y,cur_x;
}Dice;
int N,M,K;
int info[20][20];
Dice D;
void swap_dice(int a,int b,int c,int d){
int tmp = D.num[a];
D.num[a] = D.num[b];
D.num[b] = D.num[c];
D.num[c] = D.num[d];
D.num[d] = tmp;
}
void move_E(){
if(D.cur_y+1==M) return;
D.cur_y+=1;
swap_dice(0,3,5,2);
if(info[D.cur_x][D.cur_y]==0) info[D.cur_x][D.cur_y]=D.num[5];
else {
D.num[5] = info[D.cur_x][D.cur_y];
info[D.cur_x][D.cur_y]=0;
}
cout<<D.num[0]<<'\n';
}
void move_W(){
if(D.cur_y-1<0) return;
D.cur_y-=1;
swap_dice(0,2,5,3);
if(info[D.cur_x][D.cur_y]==0) info[D.cur_x][D.cur_y]=D.num[5];
else {
D.num[5] = info[D.cur_x][D.cur_y];
info[D.cur_x][D.cur_y]=0;
}
cout<<D.num[0]<<'\n';
}
void move_N(){
if(D.cur_x-1<0) return;
D.cur_x-=1;
swap_dice(0,4,5,1);
if(info[D.cur_x][D.cur_y]==0) info[D.cur_x][D.cur_y]=D.num[5];
else {
D.num[5] = info[D.cur_x][D.cur_y];
info[D.cur_x][D.cur_y]=0;
}
cout<<D.num[0]<<'\n';
}
void move_S(){
if(D.cur_x+1==N) return;
D.cur_x+=1;
swap_dice(0,1,5,4);
if(info[D.cur_x][D.cur_y]==0) info[D.cur_x][D.cur_y]=D.num[5];
else{
D.num[5] = info[D.cur_x][D.cur_y];
info[D.cur_x][D.cur_y]=0;
}
cout<<D.num[0]<<'\n';
}
void input() {
cin>>N>>M>>D.cur_x>>D.cur_y>>K;
for(int i=0;i<N;i++)
for(int j=0;j<M;j++)
cin>>info[i][j];
}
void solution() {
for(int i=0;i<6;i++) D.num[i]=0;
int query;
for(int i=0;i<K;i++){
cin>>query;
switch(query){
case 1:
move_E();
break;
case 2:
move_W();
break;
case 3:
move_N();
break;
case 4:
move_S();
break;
}
}
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
input();
solution();
return 0;
}