Jewelry
TimeLimit: 1 Second MemoryLimit: 32 Megabyte
Totalsubmit: 77 Accepted: 25
Description
The jewelry game is an interesting game. this game is run in a box of 13*6. While playing the game, it is given jewelrys with color red, blue, yellow, orange, green and purple. When any color of jewelry is 3 or more than 3 in direction of vertical, horizontal and diagonal these jewelry can be eliminated.
The game's screenshoot:
![](http://acm.hrbeu.edu.cn/oj/upload/Image/1264.jpg)
Now given a status of current, and a group of new stone, please tell that when the stones finally reach the buttom, what's the status of the game?
Input
The first line contain a integer n, indicate there will be n test case.
Each test case contain a table of character s whit 13 rows and 6 column, character B means jewelry of color blue , and R means a red one, O means a orange one, Y means a yellow one, G means a green one, P means a purple one. character W means there is no jewelry in this position.
Then followed 3 lines, each line contains a character, all this three line indicate the new coming jewelrys.
Finally is a integer m (1<=m<=6), indicate the position of new coming jewelrys.
Output
To each test case, output the state of the game when the new comming jewelrys reachd the buttom.
Sample Input
1
WWWWWW
WWWWWW
WWWWWW
WWWWWW
WWWWWW
WWWWWW
WWWWWW
WWWWWW
WWWWWW
WWWWWW
BBWWWW
BBWWWW
OOWWWW
B
B
Y
3
Sample Output
WWWWWW
WWWWWW
WWWWWW
WWWWWW
WWWWWW
WWWWWW
WWWWWW
WWWWWW
WWWWWW
WWWWWW
WWWWWW
WWWWWW
OOYWWW
1,首先把宝石掉入方框。
2,判断能否有宝石可以消去,并把能够消去的宝石的位置标记好。
3,消去标记好的宝石。
重复2,3步骤即可求出解。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define H 13
#define W 6
#define JH 3
#define JW 1
int dir[8][2]={-1,0,0,-1,1,0,0,1,-1,-1,-1,1,1,1,1,-1};
char table[H+1][W+1],newj[JH][JW];
int isW[H][W];
bool flag;
void downOp(){
int i,j,x;
for(j=0;j<W;j++){
x = H-1;
for(i=H-1;i>=0;i--){
if(isW[i][j]) continue;
table[x--][j] = table[i][j];
}
for(i=x;i>=0;i--) table[i][j] = 'W';
}
}
void search(){
flag = true;
int i,j,k,t;
memset(isW,0,sizeof(isW));
for(i=0;i<H;i++){
for(j=0;j<W;j++){
if(table[i][j] !='W'){
for(k=0;k<8;k++){
if(i+2*dir[k][0]>=0 && i+2*dir[k][0]<13){
if(table[i+dir[k][0]][j+dir[k][1]]==table[i][j] && table[i+2*dir[k][0]][j+2*dir[k][1]]==table[i][j]){
t = 0;
while(i+t*dir[k][0]>=0 && i+t*dir[k][0]<13 && table[i+t*dir[k][0]][j+t*dir[k][1]]==table[i][j]){
isW[i+t*dir[k][0]][j+t*dir[k][1]] = 1;
t++;
}
flag = false;
}
}
}
}
}
}
if(!flag) downOp();
}
int main(){
int T,i,j,k;
int l,h;
scanf("%d",&T);
while(T--){
for(i=0;i<H;i++) scanf("%s",table[i]);
for(i=0;i<JH;i++) scanf("%s",newj[i]);
scanf("%d",&l);l--;
for(i=H-1;i>=0;i--){
if(table[i][l] == 'W'){
h = i;
break;
}
}
for(i=h-JH+1;i<=h;i++) table[i][l] = newj[i-(h-JH+1)][0];
flag = false;
while(!flag) search();
for(i=0;i<H;i++){
for(j=0;j<W;j++) printf("%c",table[i][j]);
printf("\n");
}
}
return 0;
}