宝石游戏

点击打开链接


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:

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;
}


  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值