water question... be careful !!!
/** Tyvj-p1030 milk grass intrusion * Mike-W * 2011-10-26 * ----------------------- * simple flood fill * Note the lower left is () * URL: http://tyvj.cpwz.cn/Problem_Show.asp? Id = 1030 */# include <stdio. h> # include <stdlib. h> # include <string. h> # define size 110 # define qsize (size * size) typedef struct _ POS {int X, Y;} Pos; char f [size] [size]; int G [size] [size]; pos q [qsize]; int qtail, qhead, qlen; int XX, YY, Sx, Sy; int d [8] [2] = {}, {}, {1,-1}, {}, {0,-1 }, {-}, {-}, {-1,-1 }}; int push (int x, int y) {q [qtail]. X = x; Q [qtail]. y = y; If (++ qtail = qsize) qtail = 0; qlen ++; return 0;} int POP (int * X, int * Y) {* x = Q [qhead]. x; * Y = Q [qhead]. y; If (++ qhead = qsize) qhead = 0; qlen --; return 0;} int flood_fill (void) {int X, Y, TX, Ty, I; push (sx, Sy); G [SX] [sy] = 0;/* The first day is not counted... */while (qlen> 0) {Pop (& X, & Y); for (I = 0; I <8; I ++) {Tx = x + d [I] [0]; ty = Y + d [I] [1]; if (TX> = 0 & TX <XX & ty> = 0 & ty <YY & F [TX] [ty] = '. '&&! G [TX] [ty]) {push (TX, Ty); G [TX] [ty] = G [x] [Y] + 1 ;}}} return 0;} int main (void) {int I, j, ans; freopen ("in", "r", stdin ); scanf ("% d", & YY, & XX, & Sy, & SX); SX = XX-SX; Sy --; for (I = 0; I <xx; I ++) scanf ("% s", F [I]); flood_fill (); for (I = 0, ans = 0; I <xx; I ++) for (j = 0; j <YY; j ++) if (ANS <G [I] [J]) ans = G [I] [J]; printf ("% d \ n", ANS); Return 0 ;}