山东省第7届省赛 E题 The Binding of Isaac

本题是一道程序设计竞赛题目,玩家需要帮助角色Isaac在迷宫中寻找仅与一个普通房间相邻的超级秘密房间。通过给定地图,判断可能的位置数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The Binding of Isaac

Time Limit: 2000MS Memory limit: 65536K

题目描述

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.

输入

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.

输出

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

示例输入

2
5 3
..#
.##
##.
.##
##.
1 1
#

示例输出

8
4

提示

 

来源

 “浪潮杯”山东省第七届ACM大学生程序设计竞赛

示例程序

 

  • 提交 
  • 状态
    • 如果一个房间上下左右有且只有一个'#'说明是特殊房间
    • 问这样的房间有几个
    • 直接外围加一圈'.'
    • 然后暴力就行
    • 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;
      }
      


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值