#include <stdio.h>#define MAX 20charinput[MAX][MAX+1];intcnt;intdot_cnt,shop_cnt;voidcase_one(intstart_h,intstart_w,intend_h,intend_w,intd_c,ints_c);voidcase_two(intstart_h,intstart_w,intend_h,intend_w,intd_c,ints_c);voidcase_three(intstart_h,intstart_w,intend_h,intend_w,intd_c,ints_c);voidcase_four(intstart_h,intstart_w,intend_h,intend_w,intd_c,ints_c);intmain(void){intc,i,j,k;inth,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++;}elseif(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");}}return0;}voidcase_one(intstart_h,intstart_w,intend_h,intend_w,intd_c,ints_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;}voidcase_two(intstart_h,intstart_w,intend_h,intend_w,intd_c,ints_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;}voidcase_three(intstart_h,intstart_w,intend_h,intend_w,intd_c,ints_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;}voidcase_four(intstart_h,intstart_w,intend_h,intend_w,intd_c,ints_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;}
jsrimr
이건 tyjk32 님이 짜신 코드인데요,
3
3 4
....
....
....
4 3
...
...
...
...
여기까진 4로 똑같은데 이상태에서
3 4
....
....
....
하니까 8이나옵니다.
초기화가 문제라고 하는데, 어떤 초기화가 문제인지 잘 모르겠습니다.
혹시 아시는 분 있다면 답변 해주시면 정말 감사하겠습니다!
오늘 하루종일 이것만 봤습니다 ㅜㅜ
7년 전