-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path1386. Maze.c
executable file
·86 lines (68 loc) · 1.53 KB
/
1386. Maze.c
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
#include <stdio.h>
#include <stdint.h>
#define N_MAX 100
#define M_MAX 100
#define S_MAX 4000
#define K_MAX 4
int maze[K_MAX + 1][N_MAX + 1][M_MAX + 1];
int S[S_MAX];
int N, M, Ns;
int k, i, j, x, y, m;
int candidates[N_MAX + 1][M_MAX + 1];
int cand_copy[(N_MAX) * (M_MAX)];
int Ncand;
int Nc;
int main(int argc, char **argv) {
scanf("%d %d", &N, &M);
for (k = 1; k <= K_MAX; k++) {
for (j = 1; j <= N; j++) {
for (i = 1; i <= M; i++) {
scanf("%d %d", &x, &y);
maze[k][j][i] = (x << 8) | y;
}
}
}
scanf("%d", &Ns);
for (i = 0; i < Ns; i++) {
scanf("%d", &S[i]);
}
for (j = 1; j <= N; j++) {
for (i = 1; i <= M; i++) {
candidates[j][i] = 1;
}
}
for (m = 0; m < Ns; m++) {
int Nc = 0;
for (j = 1; j <= N; j++) {
for (i = 1; i <= M; i++) {
if (candidates[j][i]) {
cand_copy[Nc++] = (j << 8) | i;
candidates[j][i] = 0;
}
}
}
// printf("%d\n", Nc);
for (k = 0; k < Nc; k++) {
uint16_t j = (cand_copy[k] & 0xFF00) >> 8;
uint16_t i = cand_copy[k] & 0x00FF;
uint16_t x = (maze[S[m]][j][i] & 0xFF00) >> 8;
uint16_t y = maze[S[m]][j][i] & 0x00FF;
// printf("%d %d -> %d\n", x, y, maze[S[m]][j][i]);
candidates[x][y] = 1;
}
}
Ncand = 0;
for (j = 1; j <= N; j++) {
for (i = 1; i <= M; i++) {
Ncand += candidates[j][i];
}
}
printf("%d\n", Ncand);
for (j = 1; j <= N; j++) {
for (i = 1; i <= M; i++) {
if (candidates[j][i]) {
printf("%d %d\n", j, i);
}
}
}
}