很简单的题,就是题意不懂……!

就是判断每个'*'区域内‘X’区域块的个数

WA了好多次,就是太差了;

1.结果排序输出

2.因为是骰子所以不再1-6范围内的数字要舍弃

3.格式要求要空一行……

4.因为碰到X就清零了,所以

XXX*X
XXX*X
.....
X***X
XX***

把X清零之后,在原来的*区域内的dfs就进行不下去了,就wa了……233333333

代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <stack>
#include <cctype>
#include <string>
#include <malloc.h>
#include <queue>
#include <map>

using namespace std;
const int INF = 0xffffff;
const double Pi = 4 * atan(1);
const int Maxn = 200 + 10;
//int dir2[8][2] = {{-1,0},{0,-1},{-1,1},{1,-1},{-1,-1},{1,0},{0,1},{1,1}};
int dr[] = {0,1,0,-1};
int dc[] = {1,0,-1,0};
int h,w;
char graph[60][60];
int a[2500];
int cnt;
int num;

void dfs2(int r,int c){
    graph[r][c] = '#';
    for(int i = 0;i < 4;i++){
        int xx = r + dr[i];
        int yy = c + dc[i];
        if(xx > -1 && yy > -1 && xx < h && yy < w){
            if(graph[xx][yy] == 'X'){
                dfs2(xx,yy);
            }
        }
    }
}

void dfs(int r,int c){
    if(graph[r][c] == 'X'){
        dfs2(r,c);
        num++;
    }
    graph[r][c] = ' ';
    for(int i = 0;i < 4;i++){
        int xx = r + dr[i];
        int yy = c + dc[i];
        if(xx > -1 && yy > -1 && xx < h && yy < w){
            if(graph[xx][yy] == '*' || graph[xx][yy] == 'X' || graph[xx][yy] == '#')
                dfs(xx,yy);
        }
    }
}

int cmp(const void * a,const void * b){
    return *((int *)a) - *((int *)b);
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("inpt.txt","r",stdin);
#endif
    int cas = 0;
    while(cin >> w >> h){
        if(!w && !h)
            break;
        memset(a,0,sizeof(a));
        cnt = 0;
        for(int i = 0;i < h;i++)
            cin >> graph[i];
        for(int i = 0;i < h;i++){
            for(int j = 0;j < w;j++){
                if(graph[i][j] == '*' || graph[i][j] == 'X'){
                    num = 0;
                    dfs(i,j);
                    if(num > 0 && num < 7)
                        a[cnt++] = num;
                }
            }
        }
        qsort(a,cnt,sizeof(int),cmp);
        cout << "Throw " << ++cas << endl;
        for(int i = 0;i < cnt-1;i++)
            cout << a[i] << " ";
        cout << a[cnt-1] << endl << endl;
    }
    return 0;
}
View Code

相关文章:

  • 2021-07-16
  • 2021-11-24
  • 2022-12-23
  • 2022-12-23
  • 2021-07-31
  • 2021-08-10
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-05
  • 2022-02-18
  • 2021-12-08
  • 2022-12-23
  • 2021-10-05
  • 2021-07-26
相关资源
相似解决方案