Dating with Girls (2)
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2416 Accepted Submission (s): 690
Problem Description If You had solved the problem Dating with girls (1). I Think you can solve this problem too. This problem was also about dating with girls. Now you are in a maze and the girl you want to date with is also in the maze. If you can find the girl and then you can date with the girl. Else the girl would date with other boys. What a pity!
The Maze is very strange. There is many stones in the maze. The stone'll disappear at time t if it's a multiple of K (2<= K <=), on the other time, stones'll be still th Ere.
There is only '. ' or ' # ', ' Y ', ' G ' on the map of the maze. '. ' Indicates the blank which you can move on, ' # ' indicates stones. ' Y ' indicates the your location. ' G ' indicates the girl ' s location. There is only one ' Y ' and one ' G '. Every seconds you can move left, right, up or down.
Input The first line contain an integer T. Then T cases followed. Each case is begins with three integers r and C (1 <= R, c <=), and K (2 <=k <= 10).
The next R line is the map ' s description.
Output for each cases, if you can find the girl, output the least time in seconds, else output "Please give me another cha Nce! ".
Sample Input
1 6 6 2 ... Y ..... .#.... ...#.. ...#.. .. #G #.
Sample Output
7 Direct modulus Judgment
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue
> Using namespace std;
typedef long Long LL;
const int MAXN = 100 + 5;
Char FIG[MAXN][MAXN];
BOOL VIS[MAXN][MAXN][15];
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
int R, c, K;
int mintime;
struct point {int x, y, time;
Point (int x,int y, int time): x (x), Y (y), time (time) {}};
void BFS (int x,int y) {queue<point>que;
Que.push (Point (x, y, 0));
while (! Que.empty ()) {Point e = Que.front ();
Que.pop ();
if (vis[e.x][e.y][e.time% K] | | e.x < 0 | | E.y < 0 | | e.x >= r | | e.y >= c) continue;
if (fig[e.x][e.y] = = ' # ') {if (e.time% k! = 0) Continue;
} vis[e.x][e.y][e.time% K] = true;
if (fig[e.x][e.y] = = ' G ') {mintime = E.time;
Return
} for (int i = 0; i < 4; i + +) {int NX = e.x + dx[i]; int NY = e.y + Dy[i];
Que.push (Point (NX, NY, E.time + 1));
}}} void solve (int x,int y) {memset (Vis, false,sizeof (vis));
Mintime =-1;
BFS (x, y);
if (Mintime = =-1) {printf ("Please give me another chance!\n");
} else {printf ("%d\n", mintime);
}} int main () {int t,ix,iy;
scanf ("%d", &t);
while (T--) {scanf ("%d%d%d", &r, &c, &k);
for (int i = 0; i < R; i + +) {scanf ("%s", Fig[i]);
for (int j = 0; J < C; j + +) {if (fig[i][j] = = ' Y ') {IX = i;
iy = j;
}}} solve (Ix,iy); }
}