求助
查看原帖
求助
1144759
rq_hyj楼主2024/12/9 20:33

在第四个点后全WA,求条

#include<cstdio>
#include<iostream>
#include<queue>
using namespace std;
int n,k;
string arr[105];
int fla;
int t[105][15];
struct s{
    int x,y;
    int cnt;
};
queue <s> q;
int tx[10]={0,1,0,-1,0},ty[10]={0,0,1,0,-1};
void ddxyz(){
    for(int i=0;i<=100;i++){
        for(int j=0;j<=10;j++){
            t[i][j]=0;
        }
    }
}
void bfs(int o,int p){
    while(!q.empty()){
        q.pop();
    }
    q.push({o,p,1});
    t[o][p]=1;
    while(!q.empty()){
        int fx=q.front().x;
        int fy=q.front().y;
        int wcx=q.front().cnt;
        q.pop();
        if(wcx>=k){
            fla=1;
            t[fx][fy]=2;
            break;
        }                                                                                                                                                                                                                                                                                                                                                                                
        for(int i=1;i<=4;i++){
            if(fx+tx[i]<n&&fx+tx[i]>=0&&fy+ty[i]<10&&fy+ty[i]>=0&&arr[o][p]==arr[fx+tx[i]][fy+ty[i]]&&t[fx+tx[i]][fy+ty[i]]==0){
                q.push({fx+tx[i],fy+ty[i],wcx+1});
                t[fx+tx[i]][fy+ty[i]]=1;
            }
        }
    }
    for(int i=0;i<n;i++){
	    for(int j=0;j<10;j++){
	        if(t[i][j]!=2){
	        	t[i][j]=0;
			}
	    }
	}
}
void del(int o,int p){
    while(!q.empty()){
        q.pop();
    }
    q.push({o,p,0});
    t[o][p]=1;
    while(!q.empty()){
    	int fx=q.front().x;
        int fy=q.front().y;
        q.pop();
        for(int i=1;i<=4;i++){
            if(fx+tx[i]<n&&fx+tx[i]>=0&&fy+ty[i]<10&&fy+ty[i]>=0&&arr[fx][fy]==arr[fx+tx[i]][fy+ty[i]]&&t[fx+tx[i]][fy+ty[i]]==0){
                q.push({fx+tx[i],fy+ty[i],0});
                t[fx+tx[i]][fy+ty[i]]=1;                                                                                                                                                   
            }
        }
       arr[fx][fy]='0';
    }
}
void dow(){
    for(int i=n-2;i>=0;i--){
        for(int j=0;j<10;j++){
            int xxx=i;
            while(arr[xxx+1][j]=='0'&&xxx+1<n){
                arr[xxx+1][j]=arr[xxx][j];
                arr[xxx][j]='0';
                xxx++;
            }
        }
    }
}
void check(){
    fla=0;
    ddxyz();
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            if(t[i][j]==0&&arr[i][j]!='0'){
                bfs(i,j); 
            }
        }
    }
    if(fla==0){
        return ;
    }
    else{
		for(int i=0;i<n;i++){
	        for(int j=0;j<10;j++){
	            if(t[i][j]==2){
	                del(i,j);
	            }
	        }
	    }
    }
    dow();
} 
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    while(1){
        check();
        if(fla==0){
            break;
        }
    } 
//    printf("----------------------------------------------\n");
    for(int i=0;i<n;i++){
        cout<<arr[i]<<endl;
    }
    return 0;
}

代码巨长,码风奇丑,各位大佬见谅

2024/12/9 20:33
加载中...