v4t3564(暴力水题)

The Binding of Isaac
Ok, now I will introduce this game to you…

Isaac is trapped in a maze which has many common rooms…

Like this…There are 9 common rooms on the map.
And there is only one super-secret room. We can’t see it on the map. The super-secret room always has many special items in it. Isaac wants to find it but he doesn’t know where it is.Bob

tells him that the super-secret room is located in an empty place which is adjacent to only one common rooms.

Two rooms are called adjacent only if they share an edge. But there will be many possible places.
Now Isaac wants you to help him to find how many places may be the super-secret room.

Input

Multiple test cases. The first line contains an integer T (T<=3000), indicating the number of test case.

Each test case begins with a line containing two integers N and M (N<=100, M<=100) indicating the number

of rows and columns. N lines follow, “#” represent a common room. “.” represent an empty place.Common rooms

maybe not connect. Don’t worry, Isaac can teleport.

Output

One line per case. The number of places which may be the super-secret room.

Sample

Input
Copy2
5 3
…#
.##
##.
.##
##.
1 1

Output

Copy8
4

遍历每个小方格;边上的单独遍历,只要是#就加一;里面的要判定上下左右有多少个#。

#include <bits/stdc++.h>
using namespace std;
int t,n,m,i,j,a[120][120];
int fun(int i,int j)
{
   
    int k=0;
    if(a[i-1][j]==1)
        k++;
    if(a[i][j-1]==1)
        k++;
    if(a[i+1][j]==1)
        k++;
    if(a[i][j+1]==1)
        k++;
    if(k==1)
        return 1;
    else
        return 0;
}
int main()
{
   
    char c;
    scanf("%d",&t);
    while(t--)
    {
   
        memset(a,0,sizeof(a));
        scanf("%d%d",&n,&m);
        getchar();
        for(i=1; i<=n; i++)
        {
   
            for(j=1; j<=m; j++)
            {
   
                scanf("%c",&c);
                if(c=='.')
                    a[i][j]=0;
                else if(c=='#')
                    a[i][j]=1;
            }
            getchar();
        }
        int cnt=0;
        for(i=1; i<=n; i++)
        {
   
            if(a[i][1])
                cnt++;
            if(a[i][m])
                cnt++;
        }
        for(j=1; j<=m; j++)
        {
   
            if(a[1][j])
                cnt++;
            if(a[n][j])
                cnt++;
        }
        for(i=1; i<=n; i++)
        {
   
            for(j=1; j<=m; j++)
            {
   
                if(a[i][j]==0)
                {
   
                    if(fun(i,j))
                        cnt++;
                }
            }
        }
        cout<<cnt<<'\n';
    }
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 春招至今,你的战绩如何? #
5015次浏览 47人参与
# 你的实习产出是真实的还是包装的? #
1103次浏览 27人参与
# MiniMax求职进展汇总 #
22878次浏览 293人参与
# 军工所铁饭碗 vs 互联网高薪资,你会选谁 #
6898次浏览 36人参与
# 简历第一个项目做什么 #
31245次浏览 312人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
186343次浏览 1114人参与
# 巨人网络春招 #
11164次浏览 223人参与
# 面试紧张时你会有什么表现? #
30328次浏览 188人参与
# 简历中的项目经历要怎么写? #
309361次浏览 4150人参与
# 网易游戏笔试 #
6304次浏览 83人参与
# 职能管理面试记录 #
10682次浏览 59人参与
# 把自己当AI,现在最消耗你token的问题是什么? #
6850次浏览 154人参与
# 从哪些方向判断这个offer值不值得去? #
56695次浏览 357人参与
# 腾讯音乐求职进展汇总 #
160391次浏览 1105人参与
# 小红书求职进展汇总 #
226845次浏览 1356人参与
# AI时代,哪些岗位最容易被淘汰 #
62375次浏览 727人参与
# 你怎么看待AI面试 #
179254次浏览 1163人参与
# 正在春招的你,也参与了去年秋招吗? #
362517次浏览 2631人参与
# 你的房租占工资的比例是多少? #
92123次浏览 896人参与
# 机械求职避坑tips #
94396次浏览 567人参与
# 校招笔试 #
466168次浏览 2950人参与
# 面试官最爱问的 AI 问题是...... #
27111次浏览 834人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务