Bubble shooter
time limit (normal/java): 1000ms/3000ms Run memory limit: 65536KByte
Description
Bubble shooter is a popular game. You can find a IoT of versions from the Internet.
The goal of this game was to the bubbles off the field. Every time just point the cannon to where you want the next bubble to go, and if three or more about bubbles with the SAM E color came together (including the newly shot bubble), they would detonate. After the first explode, if some bubbles is disconnected from the bubble (s) in the topmost row, they would explode too.
In this problem, you'll be given a arranged situation of bubbles in the field and the newly shot bubble. Your program should output, the total number of bubbles, that would explode.
input
There is multiple test cases. Each test case begins with four integers h (the height of the field, 2 <= H <=), W (the width of the field, 2 &L t;= W <=, in the picture above, W are), H (the vertical position of the newly shot bubble, count from top to Bott OM, and the topmost is counted as 1) and W (the horizontal position of the newly shot bubble, count from d The leftmost is counted as 1). Then H lines follow, the odd lines would contain W characters while the even lines would contain W-1 characters (refer to th e picture above). Each character would be either a lowercase from ' a ' to ' Z ' indicating the color of the bubble in that position, or a capita L Letter ' E ' indicating an empty position. Assure the arranged situation is always valid (all the bubbles be directly or indirectly connected with at least One bubble in the topmost row, and the position of newly shot bubble are never empty).
Output
For each test case, the output an integer indicating how many bubbles would explode.
Sample Input
2 2 2 1
aa
a
3 3 3 3
AAA
BA
BBA
3 3 3 1
AAA
BA
BBA
3 3 3 3
AAA
Ea
AaB
Sample Output
3
8
3
0
A word Pit
First judgment can not be removed (3 or more)
If you can find it with the first line, that's not going to fall. The total minus will not fall is the explosion is the subscript from 1 we OJ looks like starting from 0.
#include <stdio.h> #include <queue> #include <string.h> using namespace std;
const int MAX = 410;
struct node {int x;
int y;
}s;
int n,m;
int w,h;
int dir[6][2] = {1,-1,1,1,-1,1,-1,-1,0,-2,0,2};
Char A[max][max]; BOOL Check (int x,int y) {if (x%2 = = 1 && y >= 1 && y <= m*2+1 && y%2 = 1 && x >
= 1 && x <= N) return true; if (x%2 = = 0 && y >= 2 && y <= m*2 && y%2 = 0 && x >= 1 && x <= N) r
Eturn true;
return false;
} queue <node> Q;
int BFS (int flag,char c) {int cnt,i;
CNT = Q.size ();
while (!q.empty ()) {node P = q.front ();
Q.pop ();
for (i = 0; i < 6; i++) {node T;
T.x = p.x + dir[i][0];
T.y = p.y + dir[i][1];
printf ("%c", c);
if (check (T.X,T.Y) = = false) continue;
if (!a[t.x][t.y]) continue;
if (flag) if (A[T.X][T.Y]! = c) Continue;
Puts ("22");
A[T.X][T.Y] = 0;
Q.push (t); cnt++;
}} return CNT;
} int main () {char Str[max];
int i,j,k,sum,s1,s2;
while (scanf ("%d%d%d", &n,&m,&h,&w)!=eof) {sum = 0;
memset (A,0,sizeof (a));
while (!q.empty ()) Q.pop ();
for (i = 1;i <= n; i++) {scanf ("%s", str);
if (i% 2) k = 1;
else k = 2;
for (j = 0; str[j]; J++,k + = 2) {A[i][k] = str[j];
if (str[j]! = ' E ') sum++;
else a[i][k] = 0;
}} s.x = h;
if (h% 2) S.y = w*2-1;
else S.y = w*2;
Q.push (s);
char C = a[s.x][s.y];
A[S.X][S.Y] = 0;
/*for (i = 1;i <= n; i++) {for (j = 1;j <= 2*m-1; j + +) printf ("%c", A[i][j]);
Puts ("");
}*/S1 = BFS (1,c);
printf ("%c\n", A[s.x][s.y]);
printf ("%d\n", S1);
if (S1 < 3) {puts ("0");
Continue
} while (!q.empty ()) Q.pop ();
for (i = 1;i <= m*2-1; i + = 2) {if (A[1][i]) {s.x = 1;
S.y = i;
printf ("%d%d\n", s.x,s.y);
Q.push (s);
A[S.X][S.Y] = 0;
} } s2 = BFS (0, ' a ');
printf ("%d\n", SUM-S2);
} return 0;
}