样例过了,但全WA 求调 QAQ
查看原帖
样例过了,但全WA 求调 QAQ
791331
tjr0513楼主2023/6/7 21:00
#include<bits/stdc++.h>
using namespace std;
void read(int& x) {
    x = 0;
    bool y = false;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        y = ch == '-';
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 1) + (x << 3) + (ch ^ 48);
        ch = getchar();
    }
    if (y)x = -x;
}
const int N=210,dx[]={0,1,-1,0,0},dy[]={0,0,0,1,-1};
int n,k,sum;
char mp[N][15];
bool flag=true,vis[N][15];
void dfs(int x,int y){
	sum++;
	for(int i=1;i<=4;i++){
		int xx=x+dx[i],yy=y+dy[i];
		if(xx>n||xx<1||yy>10||yy<1) continue;
		if(vis[xx][yy]) continue;
		if(mp[xx][yy]!=mp[x][y]) continue;
		vis[xx][yy]=true;
		dfs(xx,yy);
	}
}
void down(){
	for(int i=n;i>=1;i--){
		for(int j=1;j<=10;j++){
			if(mp[i][j]=='0'&&mp[i-1][j]!='0'){
				swap(mp[i][j],mp[i-1][j]);
			}
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	read(n),read(k);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=10;j++){
			cin>>mp[i][j];
		}
	}
	while(flag){
		flag=false;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=10;j++){
				if(mp[i][j]!='0'){
					memset(vis,0,sizeof(vis));
					vis[i][j]=true;
					sum=0;
					dfs(i,j);
					if(sum>=k){
						flag=true;
						for(int ii=1;ii<=n;ii++){
							for(int jj=1;jj<=10;jj++){
								if(vis[ii][jj]){
									mp[ii][jj]='0';
								}
							}
						}
						down();
					}
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=10;j++){
			putchar(mp[i][j]);
		}
		putchar('\n');
	}
	return 0;
}
2023/6/7 21:00
加载中...