csu 1186 BMW文字识别


1186: BMW图形文字识别

Time Limit: 1 Sec Memory Limit: 128 MB
SUBMIT: 160 Solved: 33
[SUBMIT] [STATUS]

Description

有一些由“_"和"#"组成的图形,图形中由"#"拼成了"B"、"M"、"W"三种字母,。用程序识别这些字母,统计三个字母的个数。

Input

多组数据,每组数据第一行两个字母n、m,表示图形的行数和列数,20<=n<=100,20<=m<=100。

接下来n行为图形内容,字母字体是和题目描述这三个字母相同的标准字体,且不歪斜,每个字母占据独立的矩形区域,自身是连通的,不和其他字母交叉或相连。

Output

每组数据对应一行输出图形中B、M、W三个字母的个数,空格隔开。

Sample Input

20 50
___###############________________________________
___###################____________________________
___#####################__________________________
___#####_____________#####________________________
___#####_______________###________________________
___#####_______________###________________________
___#####_______________###________________________
___#####_____________#####________________________
___#####___________#####__________________________
___###################____________________________
___###################____________________________
___#####___________#######________________________
___#####_______________###________________________
___#####_______________#####______________________
___#####_______________#####______________________
___#####_______________#####______________________
___#####_______________#####______________________
___#####_____________#####________________________
___#######################________________________
___###################____________________________
30 30
______________________________
___###_________###____________
___###_________###____________
___###_______#####____________
___#####_____#####____________
___#####_____#####____________
___#####_____#####____________
___#___#_____#####____________
___#___#___###___#____________
___#___#####_____#____________
___#_____###_____#____________
___#_____###_____#____________
___#_____###_____#____________
___#_____###_____#____________
___#_____#_______#____________
______________________________
_###_____###_____#____________
_###_____###_____#____________
_###_____###_____#____________
___#_____###_____#____________
___#___#####_____#____________
___#___#___#___###____________
___#___#___###_###____________
___#####_____#####____________
___#####_____###______________
___#####_____###______________
___#####_____###______________
_____###_____###______________
_____#_______###______________
______________________________

Sample Output

1 0 0
0 1 1
 
  
 
  
 
  
 
  
 
  
 
  
 
  
#include<stdio.h>
#define N 101

char mat[N][N];
int m,n,r,b;
/*
尼玛这题太水了,比赛的时候竟然rp差的作死的没有做出来,
直接模拟,右上角和右下角即可区别B、M、W
*/
int move[][2]={0,1,1,0,0,-1,-1,0};

void dfs(int i,int j)
{
    int x,y,k;
    if(i>b)
        b=i;
    if(j>r)
        r=j;
    mat[i][j]='*';
    for(k=0;k<4;++k)
    {
        x=i+move[k][0];
        y=j+move[k][1];
        if(x>=0&&x<m&&y>=0&&y<n&&mat[x][y]=='#')
            dfs(x,y);
    }
}

void solve()
{
    int bmw[3]={0};
    int i,j,k;
    for(i=0;i<m;++i)
        for(j=0;j<n;++j)
            if(mat[i][j]=='#')
            {
                r=0;
                b=0;
                dfs(i,j);
                if(mat[i][r]!='*')
                    k=0;
                else if(mat[b][r]=='*')
                    k=1;
                else
                    k=2;
                bmw[k]++;
            }
    for(i=0;i<2;++i)
        printf("%d ",bmw[i]);
    printf("%d\n",bmw[i]);
}

int main()
{
    while(scanf("%d%d",&m,&n)==2)
    {
        for(int i=0;i<m;++i)
            scanf("%s",mat[i]);
        solve();
    }
    return 0;
}


 
  
 
  
 
 

你可能感兴趣的:(input,图形,IM,output)