第七届山东省ACM省赛 E The Binding of Isaac

Problem Description

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.

Example Input
2
5 3
..#
.##
##.
.##
##.
1 1
#
Example Output
8
4
Hint
 

一道简单的枚举。  求一个.点,只有一个#点相连的个数。  在原地图的基础上,向周边扩展一圈,枚举即可



#include<iostream>

#include<stdio.h>
#include<string.h>
using namespace std;
int a,b;
char mp[110][110];
char str[110];
int dx[]={1,-1,0,0};
int li,lj;
int dy[]={0,0,-1,1};
bool hanshu(int hi,int hj)
{
    int nu=0;
    if(mp[hi][hj]=='.')
    {
        for(int hg=0;hg<4;hg++)
        {
            int rx=hi+dx[hg];
            int ry=hj+dy[hg];
            if(rx>=0&&rx<li&&ry>=0&&ry<lj&&mp[rx][ry]=='#')
            {
                nu++;
            }
        }
    }
    if(nu==1)
        return true;
    else
        return false;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>a>>b;
        for(int i=0;i<=b+1;i++)
            mp[0][i]='.';
        for(int i=1;i<=a;i++)
        {
            int jj=0;
            cin>>str;
            mp[i][jj++]='.';
            int j;


            for(j=0;j<strlen(str);j++)
            {
                if(str[j]=='.')
                {
                    mp[i][jj++]='.';
                }
                else
                {
                    mp[i][jj++]='#';
                }
            }
            mp[i][jj]='.';
        }
        for(int i=0;i<b+2;i++)
            mp[a+1][i]='.';
      
        li=a+2;
         lj=b+2;
        int ans=0;
        for(int i=0;i<li;i++)
            for(int j=0;j<lj;j++)
        {


                if(hanshu(i,j))
                {


                    ans++;
                }


        }
        cout<<ans<<endl;
    }
}




/***************************************************
User name: 谭泽纯
Result: Accepted
Take time: 436ms
Take Memory: 236KB
Submit time: 2017-04-28 15:32:09
****************************************************/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值