Boardcover 문제 질문합니다 jsrimr #include <stdio.h> #define MAX 20 char input[MAX][MAX + 1]; int cnt; int dot_cnt, shop_cnt; void case_one(int start_h, int start_w, int end_h, int end_w, int d_c, int s_c); void case_two(int start_h, int start_w, int end_h, int end_w, int d_c, int s_c); void case_three(int start_h, int start_w, int end_h, int end_w, int d_c, int s_c); void case_four(int start_h, int start_w, int end_h, int end_w, int d_c, int s_c); int main(void) { int c, i, j, k; int h, w; scanf("%d", &c); for(i = 0; i < c; i++) { scanf("%d %d", &h, &w); dot_cnt = 0; shop_cnt = 0; cnt = 0; for(j = 0; j < h; j++) { scanf("%s", &input[j]); for(k = 0; k < MAX + 1; k++) { if(input[j][k] == '.') { dot_cnt++; } else if(input[j][k] == '#') { shop_cnt++; } else { break; } } } if((dot_cnt % 3) == 0) { case_one(0, 0, h, w, dot_cnt, shop_cnt); case_two(0, 0, h, w, dot_cnt, shop_cnt); case_three(0, 0, h, w, dot_cnt, shop_cnt); case_four(0, 0, h, w, dot_cnt, shop_cnt); printf("%d\n", cnt); } else { printf("0\n"); } } return 0; } void case_one(int start_h, int start_w, int end_h, int end_w, int d_c, int s_c) { if(start_w == end_w) { start_h++; start_w = 0; } if(start_h == end_h) { return; } if(input[start_h][start_w] == '#') { case_one(start_h, start_w + 1, end_h, end_w, d_c, s_c); } else { if(input[start_h + 1][start_w] == '.' && input[start_h + 1][start_w + 1] == '.') { input[start_h][start_w] = '#'; input[start_h + 1][start_w] = '#'; input[start_h + 1][start_w + 1] = '#'; if(d_c - 3 == 0) { input[start_h][start_w] = '.'; input[start_h + 1][start_w] = '.'; input[start_h + 1][start_w + 1] = '.'; cnt++; return; } case_one(start_h, start_w + 1, end_h, end_w, d_c - 3, s_c + 3); case_two(start_h, start_w + 1, end_h, end_w, d_c - 3, s_c + 3); case_three(start_h, start_w + 1, end_h, end_w, d_c - 3, s_c + 3); case_four(start_h, start_w + 1, end_h, end_w, d_c - 3, s_c + 3); input[start_h][start_w] = '.'; input[start_h + 1][start_w] = '.'; input[start_h + 1][start_w + 1] = '.'; } } return; } void case_two(int start_h, int start_w, int end_h, int end_w, int d_c, int s_c) { if(start_w == end_w) { start_h++; start_w = 0; } if(start_h == end_h) { return; } if(input[start_h][start_w] == '#') { case_two(start_h, start_w + 1, end_h, end_w, d_c, s_c); } else { if(input[start_h][start_w + 1] == '.' && input[start_h + 1][start_w] == '.') { input[start_h][start_w] = '#'; input[start_h][start_w + 1] = '#'; input[start_h + 1][start_w] = '#'; if(d_c - 3 == 0) { input[start_h][start_w] = '.'; input[start_h][start_w + 1] = '.'; input[start_h + 1][start_w] = '.'; cnt++; return; } case_one(start_h, start_w + 1, end_h, end_w, d_c - 3, s_c + 3); case_two(start_h, start_w + 1, end_h, end_w, d_c - 3, s_c + 3); case_three(start_h, start_w + 1, end_h, end_w, d_c - 3, s_c + 3); case_four(start_h, start_w + 1, end_h, end_w, d_c - 3, s_c + 3); input[start_h][start_w] = '.'; input[start_h][start_w + 1] = '.'; input[start_h + 1][start_w] = '.'; } } return; } void case_three(int start_h, int start_w, int end_h, int end_w, int d_c, int s_c) { if(start_w == end_w) { start_h++; start_w = 0; } if(start_h == end_h) { return; } if(input[start_h][start_w] == '#') { case_three(start_h, start_w + 1, end_h, end_w, d_c, s_c); } else { if(input[start_h + 1][start_w] == '.' && input[start_h + 1][start_w - 1] == '.') { input[start_h][start_w] = '#'; input[start_h + 1][start_w] = '#'; input[start_h + 1][start_w - 1] = '#'; if(d_c - 3 == 0) { input[start_h][start_w] = '.'; input[start_h + 1][start_w] = '.'; input[start_h + 1][start_w - 1] = '.'; cnt++; return; } case_one(start_h, start_w + 1, end_h, end_w, d_c - 3, s_c + 3); case_two(start_h, start_w + 1, end_h, end_w, d_c - 3, s_c + 3); case_three(start_h, start_w + 1, end_h, end_w, d_c - 3, s_c + 3); case_four(start_h, start_w + 1, end_h, end_w, d_c - 3, s_c + 3); input[start_h][start_w] = '.'; input[start_h + 1][start_w] = '.'; input[start_h + 1][start_w - 1] = '.'; } } return; } void case_four(int start_h, int start_w, int end_h, int end_w, int d_c, int s_c) { if(start_w == end_w) { start_h++; start_w = 0; } if(start_h == end_h) { return; } if(input[start_h][start_w] == '#') { case_four(start_h, start_w + 1, end_h, end_w, d_c, s_c); } else { if(input[start_h][start_w + 1] == '.' && input[start_h + 1][start_w + 1] == '.') { input[start_h][start_w] = '#'; input[start_h][start_w + 1] = '#'; input[start_h + 1][start_w + 1] = '#'; if(d_c - 3 == 0) { input[start_h][start_w] = '.'; input[start_h][start_w + 1] = '.'; input[start_h + 1][start_w + 1] = '.'; cnt++; return; } case_one(start_h, start_w + 1, end_h, end_w, d_c - 3, s_c + 3); case_two(start_h, start_w + 1, end_h, end_w, d_c - 3, s_c + 3); case_three(start_h, start_w + 1, end_h, end_w, d_c - 3, s_c + 3); case_four(start_h, start_w + 1, end_h, end_w, d_c - 3, s_c + 3); input[start_h][start_w] = '.'; input[start_h][start_w + 1] = '.'; input[start_h + 1][start_w + 1] = '.'; } } return; } 이건 tyjk32 님이 짜신 코드인데요, 3 3 4 .... .... .... 4 3 ... ... ... ... 여기까진 4로 똑같은데 이상태에서 3 4 .... .... .... 하니까 8이나옵니다. 초기화가 문제라고 하는데, 어떤 초기화가 문제인지 잘 모르겠습니다. 혹시 아시는 분 있다면 답변 해주시면 정말 감사하겠습니다! 오늘 하루종일 이것만 봤습니다 ㅜㅜ 9년 전
1개의 댓글이 있습니다. Corea input 배열을 사용하기 전에 있는 값을 다 지워주시지 않으면 문제가 생기는 것 같습니다. case_one, case_two, case_three, case_four 함수들에서 input 배열에 접근할 때 첨자의 범위 체크를 하지 않으신게 아닐까요? 9년 전 link 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.
jsrimr
이건 tyjk32 님이 짜신 코드인데요,
3
3 4
....
....
....
4 3
...
...
...
...
여기까진 4로 똑같은데 이상태에서
3 4
....
....
....
하니까 8이나옵니다.
초기화가 문제라고 하는데, 어떤 초기화가 문제인지 잘 모르겠습니다.
혹시 아시는 분 있다면 답변 해주시면 정말 감사하겠습니다!
오늘 하루종일 이것만 봤습니다 ㅜㅜ
9년 전