Despite this, I am very disappointed !!!
Come on !!! Come on !!!
"《《《《《《《《《《《《《
"
A very simple question, step by step. Going out of the matrix indicates that there is no ring. If you go to a place that has already passed, it indicates that there is a ring. You can output the result in the format !!!
# Include <stdio. h>
# Include <string. h>
Int n, m, temp;
Int ans [1010] [1010];
Char map [1010] [1010];
Void DFS (INT Sx, int SY)
{
While (SX> = 0 & SX <n & Sy> = 0 & Sy <M & map [SX] [sy]! = 'O ')
{
If (Map [SX] [sy] ='s ')
{
// Temp ++;
Map [SX] [sy] = 'O ';
Ans [SX] [sy] = ++ temp;
SX ++;
}
Else if (Map [SX] [sy] = 'n ')
{
// Temp ++;
Map [SX] [sy] = 'O ';
Ans [SX] [sy] = ++ temp;
SX --;
}
Else if (Map [SX] [sy] = 'E ')
{
// Temp ++;
Map [SX] [sy] = 'O ';
Ans [SX] [sy] = ++ temp;
Sy ++;
}
Else if (Map [SX] [sy] = 'W ')
{
// Temp ++;
Map [SX] [sy] = 'O ';
Ans [SX] [sy] = ++ temp;
Sy --;
}
}
If (Map [SX] [sy] = 'O ')
Printf ("% d step (s) before a loop of % d step (s) \ n", ANS [SX] [sy]-1, temp-ans [SX] [sy] + 1 );
Else
Printf ("% d step (s) to exit \ n", temp );
}
Int main ()
{
Int K, I;
While (scanf ("% d", & N, & M, & K), N + M + k)
{
Memset (ANS, 0, sizeof (ANS ));
For (I = 0; I <n; I ++)
Scanf ("% s", map [I]);
Temp = 0;
DFS (0, k-1 );
}
Return 0;
}
Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1035