Alas, the morning has not been in the state, have not thought, basically is to look at the problem, remember to do the topic must be focused, must think more, can not easily see the problem, this question can be '/' and ' \ ' transformation, with 0 and 1,
'/' is represented as: ' \ ' as
001100
010010
001
It's three times times bigger, and the final result divided by three is OK.
Then you can use the ordinary search, or connectivity problems, note that as long as it is traversed around the edge of the 0 to show that this must not ring, WA once, or did not notice that each group of cases have a blank line;
On the code: (basically the same as others write)
#include <stdio.h> #include <stdlib.h> #include <string.h>int map[300][300];char a[100];int dx[4]={- 1,0,0,1};int dy[4]={0,-1,1,0};int w,h,flag,sum,ans;void dfs (int x,int y) {map[x][y] = 1;for (int i=0; i<4; i++) {int xx = X+dx[i];int yy = y+dy[i];if (xx>=0&&yy>=0&&xx<3*h&&yy<3*w) {if (map[xx][yy]==0) { sum++;d FS (XX,YY);}} Else{flag = 0;}}} int main () {int I,j;int num = 0;while (scanf ("%d%d", &w,&h), w+h) {Num++;getchar (); memset (map,0,sizeof (map)); for (i=0; i
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UVA 705 Slash Maze Slash Maze