Title: give you a matrix and some points, find the area of the continuous W area (eight directions) of the given point. Analysis: Search. The FloodFill algorithm can be solved by searching directly. Description: Note the format in which the data is read. |
1#include <cstdio>2#include <cstring>3 using namespacestd;4 5 Charmap[ the][ the], used[ the][ the];6 intans;7 voidDfsintXinty)8 {9 if(X <0|| Y <0|| Map[x][y] = =0)Ten return; One if(Used[x][y]! =0|| Map[x][y]! ='W') A return; - -Used[x][y] =1; theAns + +; - intI, J; - for(i =-1; I <=1; i++) - for(j =-1; J <=1; J + +) +DFS (X+i, y+j); - } + A intMain () at { - intT, I, J; - Charstr[ the]; -scanf"%d", &t); - while(t--) - { inmemset (Map,0,sizeof(map)); - intn =0; to while(gets (str)) + { - if(str[0] ==' /') the Break; * if(str[0] !='W'&& str[0] !='L') $ {Panax NotoginsengSSCANF (str,"%d%d", &i, &j); -memset (Used,0,sizeof(used)); theAns =0; +DFS (I-1, J-1); Aprintf"%d\n", ans); the } + Else{ -SSCANF (str,"%s", map[n++]); $ } $ } - if(t) -Puts""); the } - return 0;Wuyi}
UVA 469-wetlands of Florida