-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathq8.cpp
More file actions
170 lines (159 loc) · 2.88 KB
/
q8.cpp
File metadata and controls
170 lines (159 loc) · 2.88 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <iostream>
#include <queue>
#include <algorithm>
using std::endl;
using std::cin;
using std::cout;
using std::queue;
using std::max;
// 8:潘多拉星球的悬浮公寓
// x为当前行数,y为当前列数
// 面标号展开图(每面都是左上角为(0,0),向下和向右为正方向)
//4
//0 1 2 3
//5
bool visit[20][20][6];
// 立方体大小
int k = 0;
// 房子数
int sum = 0;
// 最大房子面积
int maxSpace = 0;
// 0->上 1->下 2->左 3->右
int dir[4][2] = { {-1,0},{1,0},{0,-1},{0,1} };
// 面的上下左右 以 面的坐标轴向下和向右为正方向时为准
int next[6][4] = { {4,5,3,1},{4,5,0,2},{4,5,1,3},{4,5,2,0},{2,0,3,1},{2,0,3,1} };
// i溢出当前面的方向
// 有点绕,需要空间想象能力
void nextPos(int &x, int &y, int s, int i) {
switch (s) {
case 0:
if (i == 0) {
x = k - 1;
} else if (i == 1) {
x = k - 1;
} else if (i == 2) {
y = k - 1;
} else if (i == 3) {
y = 0;
}
break;
case 1:
if (i == 0) {
x = k - 1 - y;
y = k - 1;
} else if (i == 1) {
x = k - 1 - y;
y = k - 1;
} else if (i == 2) {
y = k - 1;
} else if (i == 3) {
y = 0;
}
break;
case 2:
if (i == 0) {
x = 0;
y = k - 1 - y;
} else if (i == 1) {
x = 0;
y = k - 1 - y;
} else if (i == 2) {
y = k - 1;
} else if (i == 3) {
y = 0;
}
break;
case 3:
if (i == 0) {
x = y;
y = 0;
} else if (i == 1) {
x = y;
y = 0;
} else if (i == 2) {
y = k - 1;
} else if (i == 3) {
y = 0;
}
break;
case 4:
if (i == 0) {
x = 0;
y = k - 1 - y;
} else if (i == 1) {
x = 0;
} else if (i == 2) {
y = x;
x = 0;
} else if (i == 3) {
y = k - 1 - x;
x = 0;
}
break;
case 5:
if (i == 0) {
x = k - 1;
y = k - 1 - y;
} else if (i == 1) {
x = k - 1;
} else if (i == 2) {
y = x;
x = k - 1;
} else if (i == 3) {
y = k - 1 - x;
x = k - 1;
}
break;
default:
break;
}
}
int dfs(int x, int y, int s) {
visit[x][y][s] = true;
int area = 1;
for (int i = 0; i < 4; i++) {
int nextX = x + dir[i][0];
int nextY = y + dir[i][1];
int nextS = s;
if (nextX == -1 || nextY == -1 || nextX == k || nextY == k) {
nextPos(nextX, nextY, nextS, i);
nextS = next[nextS][i];
}
if (!visit[nextX][nextY][nextS]) {
area += dfs(nextX, nextY, nextS);
}
}
return area;
}
int main(int argc, char *argv[]) {
int t = 0;
cin >> t;
while (t--) {
sum = 0;
maxSpace = 0;
cin >> k;
// 接收表面情况
for (int s = 0; s < 6; s++) {
for (int i = 0; i < k; i++) {
for (int j = 0; j < k; j++) {
int space = 0;
cin >> space;
visit[i][j][s] = space == 1;
}
}
}
for (int s = 0; s < 6; s++) {
for (int i = 0; i < k; i++) {
for (int j = 0; j < k; j++) {
if (!visit[i][j][s]) {
maxSpace = max(maxSpace, dfs(i, j, s));
sum++;
}
}
}
}
cout << sum << ' ' << maxSpace << endl;
}
return 0;
}