做了前两场虽然有点恶心,但也没今天那么想吐嘈.... 反正是一题未A..不得不承认依旧很菜..

 

A题,死了命的提示结果错误....  显然已模拟题.封装 remove 与 maintain 然后print.. 各种情况都考虑,将其后台数据都输出比较.还是未找到错误点在哪里..

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;

const int N = 50;
char mp[N][N];
int n, m;
bool vis[N][N];

bool legal(int x,int y){
    if(x>=1&&x<=n&&y>=1&&y<=m)
        return true;
    return false;
}
void maintain(){

    for(int c = 1; c <= m; c++){

        for(int r = n; r > 1; r--){
            if( mp[r][c] == '0' ){
                int p = -1;        
                for(int t = r-1; t >= 1; t-- ){
                    if( mp[t][c] != '0' ){
                        p = t; break;    
                    }
                }
                if( p == -1 ) break;
                else swap( mp[r][c], mp[p][c] );
            }    
        }        
    }
}

bool find(int x,int y){
    bool flag = false;    
    // left 
    if( y >= 3 ){
        char ch = mp[x][y];
        if( (mp[x][y-1]==ch) && (mp[x][y-2]==ch) ){
            flag = true;    
            for(int i = y; i >= 1; i--)    
                if( mp[x][i] == ch ) vis[x][i] = true;
                else break;
        }
    }    
    // right
    if( y+2 <= m ){
        char ch = mp[x][y];
        if( (mp[x][y+1]==ch) && (mp[x][y+2]==ch) ){
            flag = true;
            for(int i = y; i <= m; i++)
                if( mp[x][i] == ch ) vis[x][i] = true;
                else break;
        }
    }    
    // up
    if( x >= 3 ){
        char ch = mp[x][y];
        if( (mp[x-1][y]==ch) && (mp[x-2][y]==ch) ){
            flag = true;
            for(int i = x; i >= 1; i--)
                if( mp[i][y] == ch ) vis[i][y] = true;
                else break;
        }
    }    
    // down
    if( x+2 <= n ){
        char ch = mp[x][y];
        if( (mp[x+1][y]==ch) && (mp[x+2][y]==ch) ){
            flag = true;
            for(int i = x; x <= n; i++)
                if( mp[i][y] == ch ) vis[i][y] = true;
                else    break;
        }
    }
    return flag;
}
bool remove(){
    memset(vis,0,sizeof(vis));
    bool flag = false;    
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++){
            if( (!vis[i][j]) && (mp[i][j]!='0') ){
                if( find(i,j) )
                    flag = true;
            }    
        }
    if( flag ){    
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++)
                if( vis[i][j] ) mp[i][j] = '0';
    }    
    return flag;
}
void print(){
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++)
            printf("%c", mp[i][j]);
        puts("");
    }
}

int main(){
    freopen("1.in","r",stdin);
    int T;
    scanf("%d", &T);
    while(T--){
        scanf("%d%d",&n,&m); 
        for(int i = 1; i <= n; i++)
            scanf("%s", mp[i]+1 );    
        
        maintain();
        while( remove() ){
        //    print();    
            maintain();
            print();    
        }            
    }
    return 0;
}
View Code

相关文章:

  • 2021-12-19
  • 2021-10-27
  • 2022-12-23
  • 2021-07-25
  • 2022-01-03
  • 2022-01-12
  • 2022-12-23
猜你喜欢
  • 2021-09-08
  • 2022-12-23
  • 2022-01-31
  • 2021-09-16
  • 2022-12-23
  • 2022-02-19
  • 2021-06-23
相关资源
相似解决方案