数据点下下来自己测都没错,一提交上去只有40??!
查看原帖
数据点下下来自己测都没错,一提交上去只有40??!
305925
Liu45318楼主2020/8/14 10:51
#include<iostream>
#include<cstdio>
using namespace std;

const short X[8]={-1,0,1,1,1,0,-1,-1};
const short Y[8]={1,1,1,0,-1,-1,-1,0};
short n,m;
long int ans=0;
bool map[110][110]={false};
void dfs(int,int);

int main()
{
    char c;
    cin>>n>>m;
    getchar();
    getchar(); //换行符
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
        {
            c=getchar();
            if (!(c=='.')) map[i][j]=true;
            else if (c=='.') map[i][j]=false;
        }
        getchar();
        getchar();   
    }//输入

    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            if (map[i][j])
            {
                ans++;
                dfs(i,j);//开始搜索
            }
    cout<<ans<<endl;//输出答案

    return 0;
}

void dfs(int x,int y)
{
    if (x<=0||x>n||y<=0||y>m||!map[x][y]) return ;

    map[x][y]=false; 
    for (int i=0;i<8;i++)
        dfs(x+X[i],y+Y[i]);//继续搜

    return ;
}

我要黑化啊啊啊啊啊啊啊啊啊啊啊啊啊啊

2020/8/14 10:51
加载中...