음... CCTV 방향의 모든 경우의 수에 대해 사각지대를 찾는 부분.
각각의 경우의 수에 대해 배열에 CCTV 감시 영역을 표시한 후, 사각지대를 count해준다!!
이것도 테케 다 맞는다고 대충 냈다가..엄청 틀렸네ㅜ,ㅠ
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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | #include <stdio.h> #include <string.h> #define MAX 987654321 typedef struct { int y, x, d, m; }cctv; cctv C[8]; cctv CC[8]; int visit[8]; int N, M, MIN, cctv_count, cctv5_count; int map[11][11]; void Draw_0(int y, int x, int arr[11][11])//상 { int i = 0; while (1) { if (map[y - i][x] == -1 || map[y-i][x] == 6) break; arr[y - i][x] = 7; i++; } } void Draw_1(int y, int x, int arr[11][11])//우 { int i = 0; while (1) { if (map[y][x + i] == -1 || map[y][x + i] == 6) break; arr[y][x + i] = 7; i++; } } void Draw_2(int y, int x, int arr[11][11])//하 { int i = 0; while (1) { if (map[y + i][x] == -1 || map[y + i][x] == 6) break; arr[y + i][x] = 7; i++; } } void Draw_3(int y, int x, int arr[11][11])//좌 { int i = 0; while (1) { if (map[y][x - i] == -1 || map[y][x - i] == 6) break; arr[y][x - i] = 7; i++; } } void DFS(int cur, int num) { if (MIN == 0) return; if (num == cctv_count) { int count = 0; int arr[11][11] = { 0, }; for (int i = 0; i < 11; i++) { for (int j = 0; j < 11; j++) { arr[i][j] = map[i][j]; } } for (int i = 0; i < cctv_count; i++) { switch (visit[i]) { case 0: if (C[i].m == 1) { Draw_0(C[i].y, C[i].x, arr); } else if (C[i].m == 2) { Draw_0(C[i].y, C[i].x, arr); Draw_2(C[i].y, C[i].x, arr); } else if (C[i].m == 3) { Draw_0(C[i].y, C[i].x, arr); Draw_1(C[i].y, C[i].x, arr); } else if (C[i].m == 4) { Draw_0(C[i].y, C[i].x, arr); Draw_1(C[i].y, C[i].x, arr); Draw_3(C[i].y, C[i].x, arr); } break; case 1: if (C[i].m == 1) { Draw_1(C[i].y, C[i].x, arr); } else if (C[i].m == 2) { Draw_1(C[i].y, C[i].x, arr); Draw_3(C[i].y, C[i].x, arr); } else if (C[i].m == 3) { Draw_1(C[i].y, C[i].x, arr); Draw_2(C[i].y, C[i].x, arr); } else if (C[i].m == 4) { Draw_0(C[i].y, C[i].x, arr); Draw_1(C[i].y, C[i].x, arr); Draw_2(C[i].y, C[i].x, arr); } break; case 2: if (C[i].m == 1) { Draw_2(C[i].y, C[i].x, arr); } else if (C[i].m == 2) { Draw_2(C[i].y, C[i].x, arr); Draw_0(C[i].y, C[i].x, arr); } else if (C[i].m == 3) { Draw_3(C[i].y, C[i].x, arr); Draw_2(C[i].y, C[i].x, arr); } else if (C[i].m == 4) { Draw_1(C[i].y, C[i].x, arr); Draw_2(C[i].y, C[i].x, arr); Draw_3(C[i].y, C[i].x, arr); } break; case 3: if (C[i].m == 1) { Draw_3(C[i].y, C[i].x, arr); } else if (C[i].m == 2) { Draw_3(C[i].y, C[i].x, arr); Draw_1(C[i].y, C[i].x, arr); } else if (C[i].m == 3) { Draw_0(C[i].y, C[i].x, arr); Draw_3(C[i].y, C[i].x, arr); } else if (C[i].m == 4) { Draw_0(C[i].y, C[i].x, arr); Draw_2(C[i].y, C[i].x, arr); Draw_3(C[i].y, C[i].x, arr); } break; } } for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) { //printf("%d ",arr[i][j]); if (arr[i][j] == 0) count++; } //printf("\n"); } //printf("\n"); if (count < MIN) MIN = count; return; } for (int i = cur + 1; i < cctv_count; i++) { for (int j = 0; j < 4; j++) { visit[i] = j; DFS(i, num + 1); visit[i] = 0; } } return; } int main() { MIN = MAX; memset(map, -1, sizeof(map)); scanf("%d %d", &N, &M); for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) { scanf("%d", &map[i][j]); if (map[i][j] > 0 && map[i][j] < 5) { C[cctv_count].y = i; C[cctv_count].x = j; C[cctv_count++].m = map[i][j]; } else if (map[i][j] == 5) { CC[cctv5_count].y = i; CC[cctv5_count].x = j; CC[cctv5_count++].m = map[i][j]; } } } for (int i = 0; i < cctv5_count; i++) { Draw_0(CC[i].y, CC[i].x, map); Draw_1(CC[i].y, CC[i].x, map); Draw_2(CC[i].y, CC[i].x, map); Draw_3(CC[i].y, CC[i].x, map); } int count = 0; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) { if (map[i][j] == 0) count++; } } if (count < MIN) MIN = count; for (int i = 0; i < cctv_count; i++) { for (int j = 0; j < 4; j++)//방향 { visit[i] = j; DFS(i, 1); visit[i] = 0; } } printf("%d\n",MIN); return 0; } | cs |
'SW 업무 관련 > 백준' 카테고리의 다른 글
[C언어] 9207. 페그 솔리테어 (0) | 2018.10.03 |
---|---|
[C언어]14620 꽃길 (0) | 2018.10.01 |
[C언어] 3108. 로고 (0) | 2018.09.26 |
[C언어] 10164. 격자상의 경로 (0) | 2018.09.25 |
[C언어] 14888. 연산자 끼워넣기 (0) | 2018.09.25 |