Shandong Province 7th session E question the Binding of ISAAC

Source: Internet
Author: User
The Binding of ISAAC Time limit:2000ms Memory limit:65536k Title Description

Ok, now I'll introduce this game ...

Isaac are trapped in a maze which have many common rooms ...

Like this ... There is 9 common rooms on the map.

And there are only one super-secret. We can ' t see it on the map. The super-secret is always have 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 was located in a empty place which was adjacent to only one common rooms.
The rooms is called adjacent only if they share an edge. But there'll be many possible places.

Now ISAAC wants-to-help him-find how many places could be the super-secret. input

Multiple test cases. The first line contains a integer T (t<=3000), indicating the number of the test case.
Each test case begins with a line containing the integers N and M (n<=100, m<=100) indicating the number
of rows and columns. N lines follow, "#" represent a common. "." 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.

Sample Input

2
5 3
.. #
.##
##.
. ##
##.
1 1
#
Sample Output
8
4
Tips Source"Wave Cup" Shandong Province Seventh annual ACM College Student Program Design contest Sample Program

Commit status If there is a room up and down and only one ' # ' description is a special room ask such a room with a few direct perimeter plus a lap '. ' And then the violence will do Accode:

#include <bits/stdc++.h>
using namespace std;
Char dp[120][120];
int n,m,loop;
int main () {
    scanf ("%d", &loop);
    while (loop--) {
        scanf ("%d%d", &n,&m);
        memset (DP, '. ', sizeof (DP));
        for (int i=1;i<=n;++i) for
            (int j=1;j<=m;++j)
                    cin>>dp[i][j];
        int ans=0;
        for (int i=0;i<=n+1;++i) for
        (int j=0;j<=m+1;++j) {
            if (dp[i][j]== ' # ') continue;
            int tmp=0;
            if (dp[i+1][j]== ' # ') tmp++;
            if (dp[i][j+1]== ' # ') tmp++;
            if (dp[i][j-1]== ' # ') tmp++;
            if (dp[i-1][j]== ' # ') tmp++;
            if (tmp==1) ans++;
        }
        cout<<ans<< ' \12 ';
    }
    return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.